Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Nov 18, 2024
1 parent 42e6730 commit 55a508a
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 14 deletions.
4 changes: 2 additions & 2 deletions docs/verify-xml.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Task XmlIgnoreMember() =>
VerifyXml(xml)
.IgnoreMember("node");
```
<sup><a href='/src/Verify.Tests/XmlTests.cs#L64-L71' title='Snippet source file'>snippet source</a> | <a href='#snippet-XmlIgnoreMember' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/XmlTests.cs#L95-L102' title='Snippet source file'>snippet source</a> | <a href='#snippet-XmlIgnoreMember' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Will produce
Expand All @@ -92,7 +92,7 @@ public Task XmlScrubMember() =>
VerifyXml(xml)
.ScrubMember("node");
```
<sup><a href='/src/Verify.Tests/XmlTests.cs#L73-L80' title='Snippet source file'>snippet source</a> | <a href='#snippet-XmlScrubMember' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Verify.Tests/XmlTests.cs#L104-L111' title='Snippet source file'>snippet source</a> | <a href='#snippet-XmlScrubMember' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Will produce
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CA1822;CS1591;CS0649;xUnit1026;xUnit1013;CS1573;VerifyTestsProjectDir;VerifySetParameters;PolyFillTargetsForNuget</NoWarn>
<Version>28.3.1</Version>
<Version>28.3.2</Version>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>preview</LangVersion>
<AssemblyVersion>1.0.0</AssemblyVersion>
Expand Down
3 changes: 3 additions & 0 deletions src/Verify.Tests/XmlTests.Comment.verified.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<person>
<!-- name is John Doe -->
</person>
2 changes: 2 additions & 0 deletions src/Verify.Tests/XmlTests.Comment_Mix.verified.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<person>
<!-- name is John Doe -->value</person>
2 changes: 2 additions & 0 deletions src/Verify.Tests/XmlTests.Comment_Mix_WithScrub.verified.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<person>
<!-- replaced -->replaced</person>
3 changes: 3 additions & 0 deletions src/Verify.Tests/XmlTests.Comment_WithScrub.verified.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<person>
<!-- value -->
</person>
37 changes: 34 additions & 3 deletions src/Verify.Tests/XmlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,37 @@ public Task NoDeclaration() =>
</body>
""");

[Fact]
public Task Comment() =>
VerifyXml(
"""
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<person><!-- name is John Doe --></person>
""");

[Fact]
public Task Comment_WithScrub() =>
VerifyXml(
"""
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<person><!-- value --></person>
""");
[Fact]
public Task Comment_Mix() =>
VerifyXml(
"""
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<person><!-- name is John Doe -->value</person>
""");
[Fact]
public Task Comment_Mix_WithScrub() =>
VerifyXml(
"""
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<person><!-- value -->value</person>
""")
.AddScrubber(_ => _.Replace("value", "replaced"));

[Fact]
public Task CData() =>
VerifyXml(
Expand All @@ -40,7 +71,7 @@ public Task CData_WithScrub() =>
VerifyXml(
"""
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<person><![CDATA[value]]></person>
<person><![CDATA[value]]></person>
""")
.AddScrubber(_ => _.Replace("value", "replaced"));

Expand All @@ -49,15 +80,15 @@ public Task CDataMix() =>
VerifyXml(
"""
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<person><![CDATA[name is John Doe]]>value</person>
<person><![CDATA[name is John Doe]]>value</person>
""");

[Fact]
public Task CDataMix_WithScrub() =>
VerifyXml(
"""
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<person><![CDATA[value]]>value</person>
<person><![CDATA[value]]>value</person>
""")
.AddScrubber(_ => _.Replace("value", "replaced"));

Expand Down
16 changes: 8 additions & 8 deletions src/Verify/Verifier/InnerVerifier_Xml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Task<VerifyResult> VerifyXml(XContainer? target)
var elements = target
.Descendants()
.ToList();

foreach (var element in elements)
{
if (serialization.TryGetScrubOrIgnoreByName(element.Name.LocalName, out var scrubOrIgnore))
Expand All @@ -87,15 +88,14 @@ Task<VerifyResult> VerifyXml(XContainer? target)

foreach (var node in target.DescendantNodes())
{
if (node is XText text)
switch (node)
{
text.Value = ConvertValue(serialization, text.Value);
continue;
}
if (node is XCData cdata)
{
cdata.Value = ConvertValue(serialization, cdata.Value);
continue;
case XText text:
text.Value = ConvertValue(serialization, text.Value);
continue;
case XComment comment:
comment.Value = ConvertValue(serialization, comment.Value);
continue;
}
}

Expand Down

0 comments on commit 55a508a

Please sign in to comment.