PageRenderTime 37ms CodeModel.GetById 15ms app.highlight 18ms RepoModel.GetById 2ms app.codeStats 0ms

/XML-TreePP/t/07_attr_prefix.t

http://xml-treepp.googlecode.com/
Unknown | 33 lines | 27 code | 6 blank | 0 comment | 0 complexity | eafcf201497ba90553810204fd21ea93 MD5 | raw file
 1# ----------------------------------------------------------------
 2    use strict;
 3    use Test::More tests => 15;
 4    BEGIN { use_ok('XML::TreePP') };
 5# ----------------------------------------------------------------
 6    my $source = '<root><foo bar="hoge" /></root>';
 7
 8    my $tpp = XML::TreePP->new();
 9
10    my $tree1 = $tpp->parse( $source );
11    is( $tree1->{root}->{foo}->{'-bar'}, 'hoge', "parse: default" );
12
13    my $test = $source;
14    $test =~ s/\s+//sg;
15
16    foreach my $prefix ( '-', '@', '__', '?}{][)(', '$*@^%+&', '0' ) {
17        my $vprefix = defined $prefix ? ( length($prefix) ? $prefix : '""' ) : 'undef';
18        $tpp->set( attr_prefix => $prefix );
19        my $tree = $tpp->parse( $source );
20        is( $tree->{root}->{foo}->{$prefix.'bar'}, 'hoge', "parse: $vprefix" );
21
22        my $back = $tpp->write( $tree );
23        $back =~ s/\s+//sg;
24        $back =~ s/<\?.*?\?>//s;
25        is( $test, $back, "write: $vprefix" );
26    }
27
28    $tpp->set( "attr_prefix" );               # remove attr_prefix
29    my $tree2 = $tpp->parse( $source );
30    is( $tree2->{root}->{foo}->{'-bar'}, 'hoge', "parse: default (again)" );
31# ----------------------------------------------------------------
32;1;
33# ----------------------------------------------------------------