Skip to content

Inputs created from XmlDocument with "PreserveWhitespace = true" generate unexpected differences. #38

@jlocans

Description

@jlocans

Hello!

First of all, thanks for the great library!

Maybe this is intentional, but I just spent way too much time figuring out why any 3 of the whitespace ignore rules were not working and were in fact returning twice the differences than w/o any additional rules.

Turns out, if you create XmlDocument with PreserveWhitespace set to true and use that as input source, then the whitespace rules don't work.

I've modified one of the test cases:

[Test]
public void TestDiff_withIgnoreWhitespaces_shouldSucceed() {
    // prepare testData
    string controlXml = "<a><b>Test Value</b></a>";
    string testXml = "<a>\n <b>\n  Test Value\n </b>\n</a>";
    var controlDoc = new XmlDocument
    {
        PreserveWhitespace = true
    };
    controlDoc.LoadXml(controlXml);
    var testDoc = new XmlDocument
    {
        PreserveWhitespace = true
    };
    testDoc.LoadXml(testXml);

    // run test
    var myDiff = DiffBuilder.Compare(Input.FromDocument(controlDoc).Build())
        .WithTest(Input.FromDocument(testDoc).Build())
        .IgnoreWhitespace()
        .Build();

    // validate result
    Assert.IsFalse(myDiff.HasDifferences(), "XML similar " + myDiff.ToString());
}

I guess I would have expected that any of the whitespace ignore rules would take precedence over PreserveWhitespace setting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions