Skip to content

Commit 55a508a

Browse files
committed
.
1 parent 42e6730 commit 55a508a

File tree

8 files changed

+55
-14
lines changed

8 files changed

+55
-14
lines changed

docs/verify-xml.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public Task XmlIgnoreMember() =>
6666
VerifyXml(xml)
6767
.IgnoreMember("node");
6868
```
69-
<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>
69+
<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>
7070
<!-- endSnippet -->
7171

7272
Will produce
@@ -92,7 +92,7 @@ public Task XmlScrubMember() =>
9292
VerifyXml(xml)
9393
.ScrubMember("node");
9494
```
95-
<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>
95+
<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>
9696
<!-- endSnippet -->
9797

9898
Will produce

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33
<PropertyGroup>
44
<NoWarn>CA1822;CS1591;CS0649;xUnit1026;xUnit1013;CS1573;VerifyTestsProjectDir;VerifySetParameters;PolyFillTargetsForNuget</NoWarn>
5-
<Version>28.3.1</Version>
5+
<Version>28.3.2</Version>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<LangVersion>preview</LangVersion>
88
<AssemblyVersion>1.0.0</AssemblyVersion>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<person>
2+
<!-- name is John Doe -->
3+
</person>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<person>
2+
<!-- name is John Doe -->value</person>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<person>
2+
<!-- replaced -->replaced</person>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<person>
2+
<!-- value -->
3+
</person>

src/Verify.Tests/XmlTests.cs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,37 @@ public Task NoDeclaration() =>
2727
</body>
2828
""");
2929

30+
[Fact]
31+
public Task Comment() =>
32+
VerifyXml(
33+
"""
34+
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
35+
<person><!-- name is John Doe --></person>
36+
""");
37+
38+
[Fact]
39+
public Task Comment_WithScrub() =>
40+
VerifyXml(
41+
"""
42+
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
43+
<person><!-- value --></person>
44+
""");
45+
[Fact]
46+
public Task Comment_Mix() =>
47+
VerifyXml(
48+
"""
49+
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
50+
<person><!-- name is John Doe -->value</person>
51+
""");
52+
[Fact]
53+
public Task Comment_Mix_WithScrub() =>
54+
VerifyXml(
55+
"""
56+
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
57+
<person><!-- value -->value</person>
58+
""")
59+
.AddScrubber(_ => _.Replace("value", "replaced"));
60+
3061
[Fact]
3162
public Task CData() =>
3263
VerifyXml(
@@ -40,7 +71,7 @@ public Task CData_WithScrub() =>
4071
VerifyXml(
4172
"""
4273
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
43-
<person><![CDATA[value]]></person>
74+
<person><![CDATA[value]]></person>
4475
""")
4576
.AddScrubber(_ => _.Replace("value", "replaced"));
4677

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

5586
[Fact]
5687
public Task CDataMix_WithScrub() =>
5788
VerifyXml(
5889
"""
5990
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
60-
<person><![CDATA[value]]>value</person>
91+
<person><![CDATA[value]]>value</person>
6192
""")
6293
.AddScrubber(_ => _.Replace("value", "replaced"));
6394

src/Verify/Verifier/InnerVerifier_Xml.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Task<VerifyResult> VerifyXml(XContainer? target)
6666
var elements = target
6767
.Descendants()
6868
.ToList();
69+
6970
foreach (var element in elements)
7071
{
7172
if (serialization.TryGetScrubOrIgnoreByName(element.Name.LocalName, out var scrubOrIgnore))
@@ -87,15 +88,14 @@ Task<VerifyResult> VerifyXml(XContainer? target)
8788

8889
foreach (var node in target.DescendantNodes())
8990
{
90-
if (node is XText text)
91+
switch (node)
9192
{
92-
text.Value = ConvertValue(serialization, text.Value);
93-
continue;
94-
}
95-
if (node is XCData cdata)
96-
{
97-
cdata.Value = ConvertValue(serialization, cdata.Value);
98-
continue;
93+
case XText text:
94+
text.Value = ConvertValue(serialization, text.Value);
95+
continue;
96+
case XComment comment:
97+
comment.Value = ConvertValue(serialization, comment.Value);
98+
continue;
9999
}
100100
}
101101

0 commit comments

Comments
 (0)