File: test_comment_handler.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 (75 lines) | stat: -rwxr-xr-x 1,914 bytes parent folder | download | duplicates (6)
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
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/perl -w
use strict;
use Carp;

# test for the various conditions in navigation methods

use XML::Twig;

if( $] < 5.008)
  { warn "skipped, not tested under perl < 5.8\n"; print "1..1\nok 1\n"; exit 0; }

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";
  }
}

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

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

{
my $result='';
my $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>});
my $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;