File: test_comment_handler.t

package info (click to toggle)
libxml-twig-perl 1%3A3.39-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 2,128 kB
  • sloc: perl: 19,329; xml: 202; makefile: 7
file content (64 lines) | stat: -rwxr-xr-x 1,762 bytes parent folder | download | duplicates (2)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/perl -w
use strict;
use Carp;

# test for the various conditions in navigation methods

use XML::Twig;

my $nb_tests=4;
print "1..$nb_tests\n";

my $result;
my $t= XML::Twig->new( comments => 'process',
                       twig_handlers => { '#COMMENT' => sub { $result .=$_->text; } },
                     );
$t->parse( q{<doc id="doc"><!-- comment in doc --></doc>});
my $expected= ' comment in doc ';
if( $result eq $expected)
  { print "ok 1\n"; }
else
  { print "not ok 1\n";
    warn "expected: $expected\nfound   : $result\n";
  }

$result='';
$t= XML::Twig->new( comments => 'process',
                       twig_handlers => { '#COMMENT' => sub { $result .=$_->text; } },
                     );
$t->parse( q{<!-- comment in doc --><doc id="doc"></doc>});
$expected= ' comment in doc ';
if( $result eq $expected)
  { print "ok 2\n"; }
else
  { print "not ok 2\n";
    warn "expected: $expected\nfound   : $result\n";
  }

$result='';
$t= XML::Twig->new( twig_handlers => { 'doc' => sub { $result= $_->{extra_data}; } },);
$t->parse( q{<!-- comment in doc --><doc id="doc"></doc>});
$expected= '<!-- comment in doc -->';
if( $result eq $expected)
  { print "ok 3\n"; }
else
  { print "not ok 3\n";
    warn "expected: $expected\nfound   : $result\n";
  }


$result='';
$t= XML::Twig->new( comments => 'process',
                    twig_roots => { '/#COMMENT' => sub { $result= $_->{extra_data}; },
                                    elt         => sub { },
                                  });
$t->parse( q{<!-- comment in doc --><doc id="doc"><elt/></doc>});
$expected= '';  # This is a bug!
if( $result eq $expected)
  { print "ok 4\n"; }
else
  { print "not ok 4\n";
    warn "expected: $expected\nfound   : $result\n";
  }
exit 0;