-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Expand file tree
/
Copy pathAssert.cs
More file actions
48 lines (38 loc) · 1.29 KB
/
Assert.cs
File metadata and controls
48 lines (38 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace DotnetFuzzing;
internal static class Assert
{
// Feel free to add any other helpers as needed.
public static void Equal<T>(T expected, T actual)
{
if (!EqualityComparer<T>.Default.Equals(expected, actual))
{
Throw(expected, actual);
}
static void Throw(T expected, T actual) =>
throw new Exception($"Expected={expected} Actual={actual}");
}
public static void NotNull<T>(T value)
{
if (value == null)
{
ThrowNull();
}
static void ThrowNull() =>
throw new Exception("Value is null");
}
public static void SequenceEqual<T>(ReadOnlySpan<T> expected, ReadOnlySpan<T> actual)
{
if (!expected.SequenceEqual(actual))
{
Throw(expected, actual);
}
static void Throw(ReadOnlySpan<T> expected, ReadOnlySpan<T> actual)
{
Equal(expected.Length, actual.Length);
int diffIndex = expected.CommonPrefixLength(actual);
throw new Exception($"Expected={expected[diffIndex]} Actual={actual[diffIndex]} at index {diffIndex}");
}
}
}