File: test_drop_comments.t

package info (click to toggle)
libxml-twig-perl 1%3A3.52-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 4,952 kB
  • sloc: perl: 21,221; xml: 423; makefile: 9
file content (42 lines) | stat: -rwxr-xr-x 993 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/perl -w
use strict;

use File::Spec;
use lib File::Spec->catdir(File::Spec->curdir,"t");
use tools;

use XML::Twig;

print "1..3\n";

my $xml = <<XML_TEST;
<xml_root>
  <!-- some comment -->
  <key>value</key>
</xml_root>
XML_TEST

{
    my $twig1 = XML::Twig->new(comments => 'keep', keep_spaces => 1);
    $twig1->parse($xml);
    ok ($twig1->sprint() =~ /<!--.*-->/s, 'keep comments');
    #print $twig1->sprint, "\n", '-'x80, "\n"; # keeps comments ok
    $twig1->dispose;
}

{
    my $twig2 = XML::Twig->new(comments => 'drop', keep_spaces => 1);
    $twig2->parse($xml);
    ok ($twig2->sprint() !~ /<!--.*-->/s, 'drop comments');
    #print $twig2->sprint, "\n", '-'x80, "\n"; # drops comments ok
    $twig2->dispose;
}

{
    my $twig3 = XML::Twig->new(comments => 'keep', keep_spaces => 1);
    $twig3->parse($xml);
    ok ($twig3->sprint() =~ /<!--.*-->/s, 'keep comments');
    #print $twig3->sprint, "\n", '-'x80, "\n"; # drops comments!!
    $twig3->dispose;
}
exit 0;