diff --git a/docs/verify-xml.md b/docs/verify-xml.md index e589ce93a..5db99b20c 100644 --- a/docs/verify-xml.md +++ b/docs/verify-xml.md @@ -66,7 +66,7 @@ public Task XmlIgnoreMember() => VerifyXml(xml) .IgnoreMember("node"); ``` -snippet source | anchor +snippet source | anchor Will produce @@ -92,7 +92,7 @@ public Task XmlScrubMember() => VerifyXml(xml) .ScrubMember("node"); ``` -snippet source | anchor +snippet source | anchor Will produce diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 1530e71ba..93b59dd83 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -2,7 +2,7 @@ CA1822;CS1591;CS0649;xUnit1026;xUnit1013;CS1573;VerifyTestsProjectDir;VerifySetParameters;PolyFillTargetsForNuget - 28.3.1 + 28.3.2 enable preview 1.0.0 diff --git a/src/Verify.Tests/XmlTests.Comment.verified.xml b/src/Verify.Tests/XmlTests.Comment.verified.xml new file mode 100644 index 000000000..888654dcb --- /dev/null +++ b/src/Verify.Tests/XmlTests.Comment.verified.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/Verify.Tests/XmlTests.Comment_Mix.verified.xml b/src/Verify.Tests/XmlTests.Comment_Mix.verified.xml new file mode 100644 index 000000000..7cbdab728 --- /dev/null +++ b/src/Verify.Tests/XmlTests.Comment_Mix.verified.xml @@ -0,0 +1,2 @@ + + value \ No newline at end of file diff --git a/src/Verify.Tests/XmlTests.Comment_Mix_WithScrub.verified.xml b/src/Verify.Tests/XmlTests.Comment_Mix_WithScrub.verified.xml new file mode 100644 index 000000000..be9844faf --- /dev/null +++ b/src/Verify.Tests/XmlTests.Comment_Mix_WithScrub.verified.xml @@ -0,0 +1,2 @@ + + replaced \ No newline at end of file diff --git a/src/Verify.Tests/XmlTests.Comment_WithScrub.verified.xml b/src/Verify.Tests/XmlTests.Comment_WithScrub.verified.xml new file mode 100644 index 000000000..616bee4fe --- /dev/null +++ b/src/Verify.Tests/XmlTests.Comment_WithScrub.verified.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/Verify.Tests/XmlTests.cs b/src/Verify.Tests/XmlTests.cs index 2d8da210e..7fc977d04 100644 --- a/src/Verify.Tests/XmlTests.cs +++ b/src/Verify.Tests/XmlTests.cs @@ -27,6 +27,37 @@ public Task NoDeclaration() => """); + [Fact] + public Task Comment() => + VerifyXml( + """ + + + """); + + [Fact] + public Task Comment_WithScrub() => + VerifyXml( + """ + + + """); + [Fact] + public Task Comment_Mix() => + VerifyXml( + """ + + value + """); + [Fact] + public Task Comment_Mix_WithScrub() => + VerifyXml( + """ + + value + """) + .AddScrubber(_ => _.Replace("value", "replaced")); + [Fact] public Task CData() => VerifyXml( @@ -40,7 +71,7 @@ public Task CData_WithScrub() => VerifyXml( """ - + """) .AddScrubber(_ => _.Replace("value", "replaced")); @@ -49,7 +80,7 @@ public Task CDataMix() => VerifyXml( """ - value + value """); [Fact] @@ -57,7 +88,7 @@ public Task CDataMix_WithScrub() => VerifyXml( """ - value + value """) .AddScrubber(_ => _.Replace("value", "replaced")); diff --git a/src/Verify/Verifier/InnerVerifier_Xml.cs b/src/Verify/Verifier/InnerVerifier_Xml.cs index c0f7ec8d6..dd300f183 100644 --- a/src/Verify/Verifier/InnerVerifier_Xml.cs +++ b/src/Verify/Verifier/InnerVerifier_Xml.cs @@ -66,6 +66,7 @@ Task VerifyXml(XContainer? target) var elements = target .Descendants() .ToList(); + foreach (var element in elements) { if (serialization.TryGetScrubOrIgnoreByName(element.Name.LocalName, out var scrubOrIgnore)) @@ -87,15 +88,14 @@ Task 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; } }