xmltwig icon indicating copy to clipboard operation
xmltwig copied to clipboard

test_bugs_3_22 is inconsistent with documentation. What is the expected behaviour?

Open cxw42 opened this issue 6 years ago • 1 comments

Test environment: Perl 5.26.1, Cygwin x86_64 via perlbrew, XML::Twig 3.52 (latest), XML::Parser 2.44 (latest)

The first test in t/test_bugs_3.22.t parses

<doc>foo <!-- comment -->bar baz</doc>

and then calls

root->set_content("foo bar");

The test expects that the comment will be preserved, i.e.,

<doc>foo <!-- comment -->bar</doc>

However, the docs for the comments option say two things that don't match up with that test.

  1. The default is drop. Since test_bugs_3_22 doesn't pass any options to the nparse call, comments shouldn't be kept.

2 . Even if comments were kept, the docs also say that:

Any use of set_pcdata on the #PCDATA element (directly or through other methods like set_content) will delete the comment(s).

Since the test is calling set_content, the comments shouldn't be preserved.

In my own tests, the comment is not preserved. Therefore, the test fails even though (as far as I can tell) it shouldn't.

What is the expected behaviour? Should the test be changed?

cxw42 avatar Apr 03 '18 17:04 cxw42

In this case the test describes the behavior better than the docs: the code tries its best to preserve the comment in the XML. So if the text before or after the comment is not changed, it keeps the comment in the new element.

The default for comments is 'keep' by the way, so that's one more thing to fix in the docs.

mirod avatar Apr 03 '18 19:04 mirod