Skip to content

Commit

Permalink
Add test cases for has multiple attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
nowsprinting committed Oct 27, 2024
1 parent 2e9b6cf commit 653fdb1
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions Tests/Runtime/Comparers/XmlComparerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace TestHelper.Comparers
[TestFixture]
public class XmlComparerTest
{
private const string BaseXml = @"<root><child>value1</child><child attribute=""attr"">value2</child></root>";
private const string BaseXml =
@"<root><child>value1</child><child attribute=""attr"" attribute2=""attr2"">value2</child></root>";

private static IEnumerable<TestCaseData> s_TestCaseSource()
{
Expand All @@ -21,40 +22,52 @@ private static IEnumerable<TestCaseData> s_TestCaseSource()
yield return new TestCaseData(null, null, 0);

// Missing attribute in the left: Different
yield return new TestCaseData(BaseXml,
@"<root><child>value1</child><child attribute2=""attr2"">value2</child></root>", -1);

// Missing attributes in the left: Different
yield return new TestCaseData(BaseXml,
@"<root><child>value1</child><child>value2</child></root>", -1);

// Different attribute value: Different
yield return new TestCaseData(BaseXml,
@"<root><child>value1</child><child attribute=""bad attr"">value2</child></root>", -1);
@"<root><child>value1</child><child attribute=""bad attr"" attribute2=""attr2"">value2</child></root>",
-1);

// Different value: Different
yield return new TestCaseData(BaseXml,
@"<root><child>bad value</child><child attribute=""attr"">value2</child></root>", -1);
@"<root><child>bad value</child><child attribute=""attr"" attribute2=""attr2"">value2</child></root>",
-1);
}

private static IEnumerable<TestCaseData> s_TestCaseSourceReversible()
{
// Different order: Same
// Different element order: Same
yield return new TestCaseData(BaseXml,
@"<root><child attribute=""attr"" attribute2=""attr2"">value2</child><child>value1</child></root>", 0);

// Different attribute order: Same
yield return new TestCaseData(BaseXml,
@"<root><child attribute=""attr"">value2</child><child>value1</child></root>", 0);
@"<root><child>value1</child><child attribute2=""attr2"" attribute=""attr"">value2</child></root>", 0);

// Different comments: Same
yield return new TestCaseData(BaseXml,
@"<root><!-- comment --><child>value1</child><child attribute=""attr"">value2</child></root>", 0);
@"<root><!-- comment --><child>value1</child><child attribute=""attr"" attribute2=""attr2"">value2</child></root>",
0);

// Different XML declaration: Same
yield return new TestCaseData(BaseXml,
@"<?xml version=""1.0"" encoding=""utf-8""?>
<root><child>value1</child><child attribute=""attr"">value2</child></root>", 0);
<root><child>value1</child><child attribute=""attr"" attribute2=""attr2"">value2</child></root>", 0);

// Different white space: Same
yield return new TestCaseData(BaseXml, @"<root>
<child>
value1
</child>
<child
attribute=""attr"">
attribute=""attr""
attribute2=""attr2"">
value2
</child></root>", 0);

Expand Down Expand Up @@ -88,6 +101,7 @@ public void UsingWithEqualTo_CompareAsXml()
<root>
<!-- comment -->
<child
attribute2=""attr2""
attribute=""attr"">
value2
</child>
Expand Down

0 comments on commit 653fdb1

Please sign in to comment.