~ubuntu-branches/ubuntu/raring/libxml-bare-perl/raring

« back to all changes in this revision

Viewing changes to t/Basic.t

  • Committer: Bazaar Package Importer
  • Author(s): Antonio Radici
  • Date: 2009-01-31 17:28:53 UTC
  • Revision ID: james.westby@ubuntu.com-20090131172853-hptyu448d89nsje4
Tags: upstream-0.40+dfsg.1
ImportĀ upstreamĀ versionĀ 0.40+dfsg.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
 
 
3
use strict;
 
4
 
 
5
use Test::More qw(no_plan);
 
6
 
 
7
use_ok( 'XML::Bare' );
 
8
 
 
9
my $xml;
 
10
my $root;
 
11
 
 
12
$xml = new XML::Bare( text => "<xml><node>val</node></xml>" );
 
13
$root = $xml->parse();
 
14
is( $root->{xml}->{node}->{value}, 'val' );
 
15
 
 
16
$xml = new XML::Bare( text => "<xml><node/></xml>" );
 
17
$root = $xml->parse();
 
18
is( ref( $root->{xml}->{node} ), 'HASH' );
 
19
 
 
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' );
 
23
 
 
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' );
 
27
 
 
28
$xml = new XML::Bare( text => "<xml><node><![CDATA[<cval>]]></node></xml>" );
 
29
$root = $xml->parse();
 
30
is( $root->{xml}->{node}->{value}, '<cval>' );
 
31
 
 
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' );
 
35
 
 
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' );
 
39
 
 
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' );
 
44
 
 
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' );
 
49
 
 
50
# test loading a comment
 
51
$xml = new XML::Bare( text => "<xml><!--test--></xml>" );
 
52
$root = $xml->parse();
 
53
is( $root->{xml}->{comment}, 'test' );
 
54
 
 
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 );
 
62
is( $a, $b );
 
63
 
 
64
# test bad closing tags
 
65
# we need to a way to ensure that something dies... ?