PageRenderTime 20ms CodeModel.GetById 1ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 1ms

/XML-TreePP/t/38_cdata_cdsect.t

http://xml-treepp.googlecode.com/
Unknown | 62 lines | 54 code | 8 blank | 0 comment | 0 complexity | 3dd7d9501a7db885657e2e2c51ff2330 MD5 | raw file
 1# ----------------------------------------------------------------
 2    use strict;
 3    use Test::More tests => 161;
 4    BEGIN { use_ok('XML::TreePP') };
 5# ----------------------------------------------------------------
 6{
 7    my $test = {
 8        '<cdata><![CDATA[]]></cdata>'       =>  '',
 9        '<cdata><![CDATA[]]]></cdata>'      =>  ']',
10        '<cdata><![CDATA[>]]></cdata>'      =>  '>',
11
12        '<cdata><![CDATA[]]]]></cdata>'                 =>  ']]',
13        '<cdata><![CDATA[]]]><![CDATA[]]]></cdata>'     =>  ']]',
14
15        '<cdata><![CDATA[]>]]></cdata>'                 =>  ']>',
16        '<cdata><![CDATA[]]]><![CDATA[>]]></cdata>'     =>  ']>',
17
18        '<cdata>]<![CDATA[]]]>&gt;</cdata>'             =>  ']]>',
19        '<cdata>]<![CDATA[]>]]></cdata>'                =>  ']]>',
20        '<cdata><![CDATA[]]]]>&gt;</cdata>'             =>  ']]>',
21        '<cdata><![CDATA[]]]]><![CDATA[>]]></cdata>'    =>  ']]>',
22        '<cdata><![CDATA[]]]><![CDATA[]>]]></cdata>'    =>  ']]>',
23        '<cdata>]<![CDATA[]]]><![CDATA[>]]></cdata>'    =>  ']]>',
24        '<cdata><![CDATA[]]]><![CDATA[]]]>&gt;</cdata>' =>  ']]>',
25        '<cdata><![CDATA[]]]>]<![CDATA[>]]></cdata>'    =>  ']]>',
26        '<cdata><![CDATA[]]]><![CDATA[]]]><![CDATA[>]]></cdata>'    =>  ']]>',
27
28        '<cdata><![CDATA[]]]><![CDATA[]>]]]]><![CDATA[>]]></cdata>' =>  ']]>]]>',
29        '<cdata><![CDATA[]]]><![CDATA[]>]]]><![CDATA[]>]]></cdata>' =>  ']]>]]>',
30
31        '<cdata><![CDATA[]]]><![CDATA[]>]]><![CDATA[]]]]><![CDATA[>]]></cdata>' =>  ']]>]]>',
32        '<cdata><![CDATA[]]]]><![CDATA[>]]><![CDATA[]]]><![CDATA[]>]]></cdata>' =>  ']]>]]>',
33    };
34    &cdata_cdsect( $test );
35    &cdata_cdsect( $test, { cdata_scalar_ref=>1 } );
36}
37# ----------------------------------------------------------------
38sub cdata_cdsect {
39    my $list = shift;
40    my $opt  = shift;
41    my $tpp  = XML::TreePP->new( %$opt );
42
43    foreach my $src ( keys %$list ) {
44        my $val = $list->{$src};
45        my $tree = $tpp->parse( $src );
46        ok( exists $tree->{cdata}, 'exists' );
47
48        my $cdata = $tree->{cdata};
49        $cdata = $$cdata if ( ref $cdata eq 'SCALAR' );
50        ok( ! ref $cdata, 'invalid ref' );
51        is( $cdata, $val, $val );
52
53        my $xml = $tpp->write( $tree );
54        my $again = $tpp->parse( $xml );
55        my $cdat2 = $again->{cdata};
56        $cdat2 = $$cdat2 if ( ref $cdat2 eq 'SCALAR' );
57        is( $cdat2, $cdata, 'round trip' );
58    }
59}
60# ----------------------------------------------------------------
61;1;
62# ----------------------------------------------------------------