File: 25_text_node_key.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 (42 lines) | stat: -rwxr-xr-x 1,201 bytes parent folder | download | duplicates (4)
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
#   25_text_noe_key.t

use strict;
use Test::More tests => 13;
BEGIN { use_ok('XML::TreePP') };

my $tpp = XML::TreePP->new();
$tpp->set( cdata_scalar_ref => 1 );

my $hello = 'Hello, World!';
my $tnode_keys = [ '#text', '_content', '0' ];

foreach my $tkey ( @$tnode_keys ) {
    my $rand = int(rand() * 9000 + 1000);
    my $text = "$hello $rand $tkey";

    my $tree = {
        root    =>  {
            text    =>  {
                -attr   =>  $text,
                $tkey   =>  $text,
            },
            cdata   =>  {
                -attr   =>  $text,
                $tkey   =>  \$text,
            },
        }
    };
    $tpp->set( text_node_key => $tkey );
    my $write = $tpp->write( $tree );
#   print STDERR $write;

    my $back = $tpp->parse( $write );
    is( $back->{root}->{text}->{-attr}, $text, "attribute1 for $tkey" );
    is( $back->{root}->{text}->{$tkey}, $text, "text node for $tkey" );
    is( $back->{root}->{cdata}->{-attr}, $text, "attribute2 for $tkey" );
    my $ref = $back->{root}->{cdata}->{$tkey};
    is( $$ref, $text, "cdata node for $tkey (content)" ) if ref $ref;
    is( $text, 'SCALAR(0x...)', "cdata node for $tkey (ref)" ) unless ref $ref;
}

1;