File: twig.t

package info (click to toggle)
libtest-xml-perl 0.08-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 160 kB
  • sloc: perl: 351; makefile: 2
file content (79 lines) | stat: -rw-r--r-- 1,785 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
76
77
78
79
# @(#) $Id$

use strict;
use warnings;

use Test::More;

BEGIN {
    foreach ( qw( XML::Twig ) ) {
        eval "use $_";
        plan skip_all => "$_ not present" if $@;
    }
}

use Test::XML::Twig;

plan tests => 10;

#---------------------------------------------------------------------

sub handler {
    my ( $t, $el ) = @_;
    $el->set_gi( 'bar' );
}

#---------------------------------------------------------------------

my $t = get_twig( '>' );
is( $t, undef, 'get_twig() bad input' );

$t = get_twig( '<foo/>' );
isa_ok( $t, 'XML::Twig' );

#---------------------------------------------------------------------

eval { test_twig_handler() };
like( $@, qr/^usage: /, 'test_twig_handler() no args failure' );

eval { test_twig_handler( \&handler ) };
like( $@, qr/^usage: /, 'test_twig_handler() 1 args failure' );

eval { test_twig_handler( \&handler, '<foo/>' ) };
like( $@, qr/^usage: /, 'test_twig_handler() 2 args failure' );

eval { test_twig_handler( \&handler, '<foo/>', '<bar/>' ) };
like( $@, qr/^usage: /, 'test_twig_handler() 3 args failure' );

eval { test_twig_handler( 'handler', '<foo/>', '<bar/>', 'testname' ) };
like( $@, qr/^usage: /, 'test_twig_handler() arg 1 type failure' );

test_twig_handler(
    \&handler,
    '<foo />',
    '<bar></bar>',
    'test_twig_handler() with handler()',
);

test_twig_handler(
    \&handler,
    '<foo />',
    qr/\bbar\b/,
    'test_twig_handler() with qr//',
);

#---------------------------------------------------------------------

test_twig_handlers(
    { start_tag_handlers => { 'foo' => \&handler } },
    '<foo />',
    '<bar></bar>',
    'test_twig_handlers() with handler()',
);

# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# indent-tabs-mode: nil
# End:
# vim: set ai et sw=4 syntax=perl :