PageRenderTime 31ms CodeModel.GetById 18ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/XML-TreePP/t/52_require_xml_decl.t

http://xml-treepp.googlecode.com/
Unknown | 54 lines | 47 code | 7 blank | 0 comment | 0 complexity | ea0425b342ece8a4a6ea7e3b6d39bb7c MD5 | raw file
 1# ----------------------------------------------------------------
 2    use strict;
 3    use Test::More;
 4# ----------------------------------------------------------------
 5    my $xml1 = <<"EOT";
 6<root>
 7    <elem>value</elem>
 8</root>
 9EOT
10    my $xml2 = <<"EOT";
11<?xml version="1.0" encoding="UTF-8"?>
12<root>
13    <elem>value</elem>
14</root>
15EOT
16# ----------------------------------------------------------------
17{
18    plan tests => 5;
19    use_ok('XML::TreePP');
20
21    my $tpp1 = XML::TreePP->new();
22    my $tpp2 = XML::TreePP->new( require_xml_decl => 1 );
23    
24    my $res;
25    my $die;
26
27    ($res, $die) = &test($tpp1, $xml1);
28    is($res->{root}->{elem}, 'value', 'no decl and default');
29
30    ($res, $die) = &test($tpp1, $xml2);
31    is($res->{root}->{elem}, 'value', 'has decl and default');
32
33    ($res, $die) = &test($tpp2, $xml1);
34    like($die, qr/^XML DECLARATION NOT FOUND/i, 'require_xml_decl works');
35
36    ($res, $die) = &test($tpp2, $xml2);
37    is($res->{root}->{elem}, 'value', 'has decl and require_xml_decl');
38}
39# ----------------------------------------------------------------
40sub test {
41    my $tpp = shift;
42    my $xml = shift;
43    my $exp = shift;
44
45    local $@;
46    my $tree;
47    eval {
48        $tree = $tpp->parse($xml);
49    };
50    return ($tree, $@);
51}
52# ----------------------------------------------------------------
53;1;
54# ----------------------------------------------------------------