File: test_pi_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 (66 lines) | stat: -rwxr-xr-x 1,719 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
65
66
#!/usr/bin/perl -w
use strict;
use Carp;

# test for the various conditions in navigation methods

$|=1;

use XML::Twig;

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

my $result;
my $t= XML::Twig->new( pi => 'process',
                       twig_handlers => { '?pi' => sub { $result .=$_->text; } },
                     );
$t->parse( q{<doc id="doc"><?pi pi in doc ?></doc>});
my $expected= '<?pi pi 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( pi => 'process',
                       twig_handlers => { '?pi' => sub { $result .=$_->text; } },
                     );
$t->parse( q{<?pi pi in doc ?><doc id="doc"></doc>});
$expected= '<?pi pi 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{<?pi pi in doc ?><doc id="doc"></doc>});
$expected= '<?pi pi 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( pi => 'process',
                    twig_roots => { '?pi' => sub { $result= $_->target . "/" . $_->data; },
                                    elt         => sub { },
                                  });
$t->parse( q{<?pi pi in doc ?><doc id="doc"><elt/></doc>});
$expected= 'pi/pi in doc ';  
if( $result eq $expected)
  { print "ok 4\n"; }
else
  { print "not ok 4\n";
    warn "expected: /$expected/\nfound   : /$result/\n";
  }

exit 0;