xmltwig
xmltwig copied to clipboard
test_bugs_3_22 is inconsistent with documentation. What is the expected behaviour?
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.
- The default is
drop
. Sincetest_bugs_3_22
doesn't pass any options to thenparse
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 likeset_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?
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.