5
5
use Test::More qw(no_plan);
7
use_ok( 'XML::Bare', qw/xmlin/ );
12
$xml = new XML::Bare( text => "<xml><node>val</node></xml>" );
13
$root = $xml->parse();
14
is( $root->{xml}->{node}->{value}, 'val' );
16
$xml = new XML::Bare( text => "<xml><node/></xml>" );
17
$root = $xml->parse();
18
is( ref( $root->{xml}->{node} ), 'HASH' );
20
$xml = new XML::Bare( text => "<xml><node att=12>val</node></xml>" );
21
$root = $xml->parse();
22
is( $root->{xml}->{node}->{att}->{value}, '12' );
24
$xml = new XML::Bare( text => "<xml><node att=\"12\">val</node></xml>" );
25
$root = $xml->parse();
26
is( $root->{xml}->{node}->{att}->{value}, '12' );
28
$xml = new XML::Bare( text => "<xml><node><![CDATA[<cval>]]></node></xml>" );
29
$root = $xml->parse();
30
is( $root->{xml}->{node}->{value}, '<cval>' );
32
$xml = new XML::Bare( text => "<xml><node>a</node><node>b</node></xml>" );
33
$root = $xml->parse();
34
is( $root->{xml}->{node}->[1]->{value}, 'b' );
36
$xml = new XML::Bare( text => "<xml><multi_node/><node>a</node></xml>" );
37
$root = $xml->parse();
38
is( $root->{xml}->{node}->[0]->{value}, 'a' );
40
# test basic mixed - value before
41
$xml = new XML::Bare( text => "<xml><node>val<a/></node></xml>" );
42
$root = $xml->parse();
43
is( $root->{xml}->{node}->{value}, 'val' );
45
# test basic mixed - value after
46
$xml = new XML::Bare( text => "<xml><node><a/>val</node></xml>" );
47
$root = $xml->parse();
48
is( $root->{xml}->{node}->{value}, 'val' );
50
# test loading a comment
51
$xml = new XML::Bare( text => "<xml><!--test--></xml>" );
52
$root = $xml->parse();
53
is( $root->{xml}->{comment}, 'test' );
55
# test cyclic equality
56
$xml = new XML::Bare( text => "<xml><b><!--test--></b><c/><c/></xml>" );
57
$root = $xml->parse();
58
my $a = $xml->xml( $root );
59
$xml = new XML::Bare( text => $a );
60
$root = $xml->parse();
61
my $b = $xml->xml( $root );
13
( $xml, $root, $simple ) = reparse( "<xml><node>val</node></xml>" );
14
is( $root->{xml}->{node}->{value}, 'val', 'normal node value reading' );
15
is( $simple->{node}, 'val', 'simple - normal node value reading' );
17
( $xml, $root, $simple ) = reparse( "<xml><node/></xml>" );
18
is( ref( $root->{xml}->{node} ), 'HASH', 'existence of blank node' );
19
is( $simple->{node}, 1, 'simple - existence of blank node' );
21
( $xml, $root, $simple ) = reparse( "<xml><node att=12>val</node></xml>" );
22
is( $root->{xml}->{node}->{att}->{value}, '12', 'reading of attribute value' );
23
is( $simple->{node}{att}, '12', 'simple - reading of attribute value' );
25
( $xml, $root, $simple ) = reparse( "<xml><node att=\"12\">val</node></xml>" );
26
is( $root->{xml}->{node}->{att}->{value}, '12', 'reading of " surrounded attribute value' );
27
is( $simple->{node}{att}, '12', 'simple - reading of " surrounded attribute value' );
29
( $xml, $root, $simple ) = reparse( "<xml><node><![CDATA[<cval>]]></node></xml>" );
30
is( $root->{xml}->{node}->{value}, '<cval>', 'reading of cdata' );
31
is( $simple->{node}, '<cval>', 'simple - reading of cdata' );
33
( $xml, $root, $simple ) = reparse( "<xml><node>a</node><node>b</node></xml>" );
34
is( $root->{xml}->{node}->[1]->{value}, 'b', 'multiple node array creation' );
35
is( $simple->{node}[1], 'b', 'simple - multiple node array creation' );
37
( $xml, $root, $simple ) = reparse( "<xml><multi_node/><node>a</node></xml>" );
38
is( $root->{xml}->{node}->[0]->{value}, 'a', 'use of multi_' );
39
is( $simple->{node}[0], 'a', 'simple - use of multi_' );
41
# note output of this does not work
42
( $xml, $root ) = new XML::Bare( text => "<xml><node>val<a/></node></xml>" );
43
is( $root->{xml}->{node}->{value}, 'val', 'basic mixed - value before' );
44
#is( $simple->{xml}{node}[0], 'val', 'simple - basic mixed - value before' );
46
# note output of this does not work
47
( $xml, $root ) = new XML::Bare( text => "<xml><node><a/>val</node></xml>" );
48
is( $root->{xml}->{node}->{value}, 'val', 'basic mixed - value after' );
50
( $xml, $root, $simple ) = reparse( "<xml><!--test--></xml>",1 );
51
is( $root->{xml}->{comment}, 'test', 'loading a comment' );
54
( $xml, $root ) = new XML::Bare( text => "<xml></xml>" );
55
$xml->add_node( $root, 'item', name => 'bob' );
56
is( ref( $root->{'item'}[0]{'name'} ), 'HASH', 'node addition' );
57
is( $root->{'item'}[0]{'name'}{'value'}, 'bob', 'node addition' );
59
# test cyclic equalities
60
cyclic( "<xml><b><!--test--></b><c/><c/></xml>", 'comment' );
61
cyclic( "<xml><a><![CDATA[cdata]]></a></xml>", 'cdata' ); # with cdata
63
my $text = '<xml><node>checkval</node></xml>';
64
( $xml, $root ) = new XML::Bare( text => $text );
65
my $i = $root->{'xml'}{'node'}{'_i'}-1;
66
my $z = $root->{'xml'}{'node'}{'_z'}-$i+1;
67
is( substr( $text, $i, $z ), '<node>checkval</node>', '_i and _z vals' );
72
my ( $xml, $root ) = new XML::Bare( text => $text );
73
my $a = $xml->xml( $root );
74
( $xml, $root ) = new XML::Bare( text => $a );
75
my $simple = $nosimp ? 0 : xmlin( $text );
76
return ( $xml, $root, $simple );
80
my ( $text, $name ) = @_;
81
( $xml, $root ) = new XML::Bare( text => $text );
82
my $a = $xml->xml( $root );
83
( $xml, $root ) = new XML::Bare( text => $a );
84
my $b = $xml->xml( $root );
85
is( $a, $b, "cyclic - $name" );
64
88
# test bad closing tags
65
89
# we need to a way to ensure that something dies... ?