Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using FluentAssertions #202

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 32 additions & 40 deletions MaxMind.Db.Test/DecoderTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#region

using FluentAssertions;
using System;
using System.Collections.Generic;
using System.Numerics;
Expand All @@ -17,7 +16,7 @@ public static class DecoderTest
[MemberData(nameof(TestUInt16))]
[MemberData(nameof(TestUInt32))]
[MemberData(nameof(TestInt32s))]
[MemberData(nameof(TestInt64s))]
[MemberData(nameof(TestUInt64s))]
[MemberData(nameof(TestBigIntegers))]
[MemberData(nameof(TestDoubles))]
[MemberData(nameof(TestFloats))]
Expand All @@ -27,7 +26,7 @@ public static class DecoderTest
[MemberData(nameof(TestBytes))]
[MemberData(nameof(TestMaps))]
[MemberData(nameof(TestArrays))]
public static void TestTypeDecoding<T>(Dictionary<T, byte[]> tests, bool useShouldBe = false) where T : class
public static void TestTypeDecoding<T>(Dictionary<T, byte[]> tests) where T : class
{
foreach (var entry in tests)
{
Expand All @@ -37,14 +36,7 @@ public static void TestTypeDecoding<T>(Dictionary<T, byte[]> tests, bool useShou
using var database = new ArrayBuffer(input);
var decoder = new Decoder(database, 0, false);
var val = decoder.Decode<T>(0, out _);
if (useShouldBe)
{
val.Should().Be(expect);
}
else
{
val.Should().BeEquivalentTo(expect, options => options.RespectingRuntimeTypes());
}
Assert.Equal(expect, val);
}
}

Expand All @@ -56,7 +48,7 @@ public static IEnumerable<object[]> TestUInt16()
{(1 << 8) - 1, [0xa1, 0xff] },
{500, [0xa2, 0x1, 0xf4] },
{10872, [0xa2, 0x2a, 0x78] },
{ushort.MaxValue, [0xa2, 0xff, 0xff] }
{(int) ushort.MaxValue, [0xa2, 0xff, 0xff] }
};

yield return [uint16s];
Expand All @@ -66,13 +58,13 @@ public static IEnumerable<object[]> TestUInt32()
{
var uint32s = new Dictionary<object, byte[]>
{
{0, [0xc0] },
{(1 << 8) - 1, [0xc1, 0xff] },
{500, [0xc2, 0x1, 0xf4] },
{10872, [0xc2, 0x2a, 0x78] },
{(1 << 16) - 1, [0xc2, 0xff, 0xff] },
{(1 << 24) - 1, [0xc3, 0xff, 0xff, 0xff] },
{uint.MaxValue, [0xc4, 0xff, 0xff, 0xff, 0xff] }
{0L, [0xc0] },
{(1L << 8) - 1, [0xc1, 0xff] },
{500L, [0xc2, 0x1, 0xf4] },
{10872L, [0xc2, 0x2a, 0x78] },
{(1L << 16) - 1, [0xc2, 0xff, 0xff] },
{(1L << 24) - 1, [0xc3, 0xff, 0xff, 0xff] },
{(long) uint.MaxValue, [0xc4, 0xff, 0xff, 0xff, 0xff] }
};

yield return [uint32s];
Expand All @@ -99,18 +91,18 @@ public static IEnumerable<object[]> TestInt32s()
yield return [int32s];
}

public static IEnumerable<object[]> TestInt64s()
public static IEnumerable<object[]> TestUInt64s()
{
var int64s = new Dictionary<object, byte[]>
var uint64s = new Dictionary<object, byte[]>
{
{0L, [0x0, 0x2] },
{500L, [0x2, 0x2, 0x1, 0xf4] },
{10872, [0x2, 0x2, 0x2a, 0x78] }
{0UL, [0x0, 0x2] },
{500UL, [0x2, 0x2, 0x1, 0xf4] },
{10872UL, [0x2, 0x2, 0x2a, 0x78] }
};

for (var power = 1; power < 8; power++)
{
var key = Int64Pow(2, 8 * power) - 1;
var key = UInt64Pow(2, 8 * power) - 1;
var value = new byte[2 + power];

value[0] = (byte)power;
Expand All @@ -120,15 +112,15 @@ public static IEnumerable<object[]> TestInt64s()
value[i] = 0xff;
}

int64s.Add(key, value);
uint64s.Add(key, value);
}

yield return [int64s];
yield return [uint64s];
}

public static long Int64Pow(long x, int pow)
public static ulong UInt64Pow(ulong x, int pow)
{
long ret = 1;
ulong ret = 1;
while (pow != 0)
{
if ((pow & 1) == 1)
Expand Down Expand Up @@ -163,7 +155,7 @@ public static IEnumerable<object[]> TestBigIntegers()
bigInts.Add(key, value);
}

yield return [bigInts, /*useShouldBe*/ true];
yield return [bigInts];
}

public static IEnumerable<object[]> TestDoubles()
Expand Down Expand Up @@ -205,16 +197,16 @@ public static IEnumerable<object[]> TestPointers()
{
var pointers = new Dictionary<object, byte[]>
{
{0, [0x20, 0x0] },
{5, [0x20, 0x5] },
{10, [0x20, 0xa] },
{(1 << 10) - 1, [0x23, 0xff] },
{3017, [0x28, 0x3, 0xc9] },
{(1 << 19) - 5, [0x2f, 0xf7, 0xfb] },
{(1 << 19) + (1 << 11) - 1, [0x2f, 0xff, 0xff] },
{(1 << 27) - 2, [0x37, 0xf7, 0xf7, 0xfe] },
{((long) 1 << 27) + (1 << 19) + (1 << 11) - 1, [0x37, 0xff, 0xff, 0xff] },
{((long) 1 << 31) - 1, [0x38, 0x7f, 0xff, 0xff, 0xff] }
{0L, [0x20, 0x0] },
{5L, [0x20, 0x5] },
{10L, [0x20, 0xa] },
{(1L << 10) - 1, [0x23, 0xff] },
{3017L, [0x28, 0x3, 0xc9] },
{(1L << 19) - 5, [0x2f, 0xf7, 0xfb] },
{(1L << 19) + (1 << 11) - 1, [0x2f, 0xff, 0xff] },
{(1L << 27) - 2, [0x37, 0xf7, 0xf7, 0xfe] },
{(1L << 27) + (1 << 19) + (1 << 11) - 1, [0x37, 0xff, 0xff, 0xff] },
{(1L << 31) - 1, [0x38, 0x7f, 0xff, 0xff, 0xff] }
};

yield return [pointers];
Expand Down
1 change: 0 additions & 1 deletion MaxMind.Db.Test/MaxMind.Db.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="FluentAssertions" Version="7.0.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
13 changes: 6 additions & 7 deletions MaxMind.Db.Test/PointerTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#region

using FluentAssertions;
using MaxMind.Db.Test.Helper;
using System.Collections.Generic;
using System.IO;
Expand All @@ -21,22 +20,22 @@ public void TestWithPointers()
var decoder = new Decoder(database, 0);

var node = decoder.Decode<Dictionary<string, object>>(0, out _);
node["long_key"].Should().Be("long_value1");
Assert.Equal("long_value1", node["long_key"]);

node = decoder.Decode<Dictionary<string, object>>(22, out _);
node["long_key"].Should().Be("long_value2");
Assert.Equal("long_value2", node["long_key"]);

node = decoder.Decode<Dictionary<string, object>>(37, out _);
node["long_key2"].Should().Be("long_value1");
Assert.Equal("long_value1", node["long_key2"]);

node = decoder.Decode<Dictionary<string, object>>(50, out _);
node["long_key2"].Should().Be("long_value2");
Assert.Equal("long_value2", node["long_key2"]);

node = decoder.Decode<Dictionary<string, object>>(55, out _);
node["long_key"].Should().Be("long_value1");
Assert.Equal("long_value1", node["long_key"]);

node = decoder.Decode<Dictionary<string, object>>(57, out _);
node["long_key2"].Should().Be("long_value2");
Assert.Equal("long_value2", node["long_key2"]);
}
}
}
Loading
Loading