[tests] Apply formatting rules

This commit is contained in:
Laura Hausmann 2024-06-29 01:09:17 +02:00
parent 50d3068a57
commit 94b7eb7c66
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 27 additions and 26 deletions

View file

@ -18,9 +18,9 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0"/> <PackageReference Include="FluentAssertions" Version="6.12.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0"/>
<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" /> <PackageReference Include="MSTest.TestAdapter" Version="3.4.3"/>
<PackageReference Include="MSTest.TestFramework" Version="3.4.3" /> <PackageReference Include="MSTest.TestFramework" Version="3.4.3"/>
<PackageReference Include="coverlet.collector" Version="6.0.2"> <PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View file

@ -66,7 +66,8 @@ public class MfmTests
[TestMethod] [TestMethod]
public void TestMention() public void TestMention()
{ {
const string input = "test @test test @test@instance.tld @test_ @_test @test_@ins-tance.tld @_test@xn--mastodn-f1a.de @_test@-xn--mastodn-f1a.de"; const string input =
"test @test test @test@instance.tld @test_ @_test @test_@ins-tance.tld @_test@xn--mastodn-f1a.de @_test@-xn--mastodn-f1a.de";
List<MfmNode> expected = List<MfmNode> expected =
[ [
new MfmTextNode("test "), new MfmTextNode("test "),
@ -81,7 +82,7 @@ public class MfmTests
new MfmMentionNode("test_@ins-tance.tld", "test_", "ins-tance.tld"), new MfmMentionNode("test_@ins-tance.tld", "test_", "ins-tance.tld"),
new MfmTextNode(" "), new MfmTextNode(" "),
new MfmMentionNode("_test@xn--mastodn-f1a.de", "_test", "xn--mastodn-f1a.de"), new MfmMentionNode("_test@xn--mastodn-f1a.de", "_test", "xn--mastodn-f1a.de"),
new MfmTextNode(" @_test@-xn--mastodn-f1a.de"), new MfmTextNode(" @_test@-xn--mastodn-f1a.de")
]; ];
var res = Mfm.parse(input); var res = Mfm.parse(input);
@ -180,7 +181,7 @@ public class MfmTests
new MfmHashtagNode("test"), new MfmHashtagNode("test"),
new MfmTextNode("'s "), new MfmTextNode("'s "),
new MfmHashtagNode("t-e_s-t"), new MfmHashtagNode("t-e_s-t"),
new MfmTextNode(". test"), new MfmTextNode(". test")
]; ];
var res = Mfm.parse(input); var res = Mfm.parse(input);
@ -226,30 +227,13 @@ public class MfmTests
} }
} }
private class MfmNodeEquality : IEqualityComparer<MfmNode>
{
public bool Equals(MfmNode? x, MfmNode? y)
{
if (x == null && y == null) return true;
if (x == null && y != null) return false;
if (x != null && y == null) return false;
return MfmNodeEqual(x!, y!);
}
public int GetHashCode(MfmNode obj)
{
return obj.GetHashCode();
}
}
private static bool MfmNodeEqual(MfmNode a, MfmNode b) private static bool MfmNodeEqual(MfmNode a, MfmNode b)
{ {
if (a.GetType() != b.GetType()) return false; if (a.GetType() != b.GetType()) return false;
if (!a.Children.IsEmpty || !b.Children.IsEmpty) if (!a.Children.IsEmpty || !b.Children.IsEmpty)
{ {
if (!a.Children.IsEmpty && b.Children.IsEmpty || a.Children.IsEmpty && !b.Children.IsEmpty) if ((!a.Children.IsEmpty && b.Children.IsEmpty) || (a.Children.IsEmpty && !b.Children.IsEmpty))
return false; return false;
if (!a.Children.SequenceEqual(b.Children, new MfmNodeEquality())) if (!a.Children.SequenceEqual(b.Children, new MfmNodeEquality()))
return false; return false;
@ -338,4 +322,21 @@ public class MfmTests
return true; return true;
} }
private class MfmNodeEquality : IEqualityComparer<MfmNode>
{
public bool Equals(MfmNode? x, MfmNode? y)
{
if (x == null && y == null) return true;
if (x == null && y != null) return false;
if (x != null && y == null) return false;
return MfmNodeEqual(x!, y!);
}
public int GetHashCode(MfmNode obj)
{
return obj.GetHashCode();
}
}
} }