File: 52_require_xml_decl.t

package info (click to toggle)
libxml-treepp-perl 0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 680 kB
  • sloc: perl: 810; xml: 58; sh: 41; makefile: 2
file content (54 lines) | stat: -rwxr-xr-x 1,408 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
# ----------------------------------------------------------------
    use strict;
    use Test::More;
# ----------------------------------------------------------------
    my $xml1 = <<"EOT";
<root>
    <elem>value</elem>
</root>
EOT
    my $xml2 = <<"EOT";
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <elem>value</elem>
</root>
EOT
# ----------------------------------------------------------------
{
    plan tests => 5;
    use_ok('XML::TreePP');

    my $tpp1 = XML::TreePP->new();
    my $tpp2 = XML::TreePP->new( require_xml_decl => 1 );
    
    my $res;
    my $die;

    ($res, $die) = &test($tpp1, $xml1);
    is($res->{root}->{elem}, 'value', 'no decl and default');

    ($res, $die) = &test($tpp1, $xml2);
    is($res->{root}->{elem}, 'value', 'has decl and default');

    ($res, $die) = &test($tpp2, $xml1);
    like($die, qr/^XML DECLARATION NOT FOUND/i, 'require_xml_decl works');

    ($res, $die) = &test($tpp2, $xml2);
    is($res->{root}->{elem}, 'value', 'has decl and require_xml_decl');
}
# ----------------------------------------------------------------
sub test {
    my $tpp = shift;
    my $xml = shift;
    my $exp = shift;

    local $@;
    my $tree;
    eval {
        $tree = $tpp->parse($xml);
    };
    return ($tree, $@);
}
# ----------------------------------------------------------------
;1;
# ----------------------------------------------------------------