Closed SebastianStehle closed 1 year ago
Does this still break if you just do?
var comment = "<!-- [endif] -->";
var diffs =
DiffBuilder
.Compare(comment)
.WithTest(comment)
.Build();
Assert.Equal(0, diffs.Count());
Does this happy to other types of comments? E.g.:
<!-- comment -->
<!-- -->
No, this works. It also happens with other comments. Both empty and with a text.
No, this works. It also happens with other comments. Both empty and with a text.
Sorry, which of my questions are you referring to?
Your code works,
With my code both comments do not work.
Ok, I wonder which of the strategies being added are causing this. Is it only this exact configuration that causes this? If not, do you mind reducing the example down as much as possible.
This is the smallest config I could come up with:
var diffs =
DiffBuilder
.Compare(comment)
.WithTest(comment)
.WithOptions(options => options
.AddSearchingNodeMatcher()
)
.Build();
OK, interesting, thanks.
Does all these cases fail?
[Theory]
[InlineData("<!--comment-->", "<!--comment-->")]
[InlineData("<!-- [endif] -->", "<!-- [endif] -->")]
[InlineData("<!-- -->", "<!-- -->")]
[InlineData("<!---->", "<!---->")]
public void Test001(string controlHtml, string testHtml)
{
var diffs =
DiffBuilder
.Compare(controlHtml)
.WithTest(testHtml)
.WithOptions(options => options
.AddSearchingNodeMatcher()
)
.Build();
Assert.Equal(0, diffs.Count());
}
The first, "<!--comment-->"
, is from the test of ForwardSearchingNodeMatcher
, which is the matcher used when calling AddSearchingNodeMatcher
, so I would think it would work.
Yes, all these fail in my case. I also added the test to my fork and it fails there as well.
Ok, thanks. That will take some additional investigation.
@SebastianStehle, sorry for the very long response time on this. Here is what happens:
When you use the WithOptions
call, you are responsible for adding in all the compares, matches, filters, etc., since the defaults options are not used.
The default options/configuration is, by the way, this:
options
.IgnoreDiffAttributes()
.IgnoreComments()
.AddSearchingNodeMatcher()
.AddCssSelectorMatcher()
.AddAttributeNameMatcher()
.AddElementComparer()
.AddIgnoreElementSupport()
.AddStyleSheetComparer()
.AddTextComparer(WhitespaceOption.Normalize, ignoreCase: false)
.AddAttributeComparer()
.AddClassAttributeComparer()
.AddBooleanAttributeComparer(BooleanAttributeComparision.Strict)
.AddStyleAttributeComparer()
.AddIgnoreChildrenElementSupport()
.AddIgnoreAttributesElementSupport();
So to make your code work, you just have to call .AddCommentComparer()
in the builder options, otherwise the differ does not know how to compare comments. By default, comments are ignored if you do use WithOptions
.
using AngleSharp.Diffing;
using AngleSharp.Diffing.Strategies.AttributeStrategies;
using AngleSharp.Diffing.Strategies.TextNodeStrategies;
var comment = "<!-- [endif] -->";
var diffs =
DiffBuilder
.Compare(comment)
.WithTest(comment)
.WithOptions(options => options
.AddAttributeComparer()
.AddAttributeNameMatcher()
.AddBooleanAttributeComparer(BooleanAttributeComparision.Strict)
.AddClassAttributeComparer()
.AddCssSelectorMatcher()
.AddElementComparer()
.AddIgnoreElementSupport()
.AddSearchingNodeMatcher()
.AddStyleAttributeComparer()
.AddStyleSheetComparer()
.AddTextComparer(WhitespaceOption.Normalize, ignoreCase: false)
+ .AddCommentComparer()
.IgnoreDiffAttributes()
)
.Build();
Console.WriteLine(diffs.Count());
Bug Report
Prerequisites
AngleSharp.Css
for CSS support)For more information, see the
CONTRIBUTING
guide.Description
When I compare two comments a diff is created.
Steps to Reproduce
Shows one diff.