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

« back to all changes in this revision

Viewing changes to t/Basic.t

  • Committer: Bazaar Package Importer
  • Author(s): Antonio Radici, Antonio Radici, gregor herrmann
  • Date: 2009-03-22 10:49:56 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090322104956-a5hx63ijvvmy4ao6
Tags: 0.43-1
[ Antonio Radici ]
* New upstream release
* debian/copyright:
  + added copyright for src/bench/xmlio_testread.cpp
  + removed repack.sh references because there are no licensing issues
  + set the proper license for the upstream source (it is dual licensed)
* debian/control:
  + upgrade to Standards-Version 3.8.1, no changes required
* removed debian/repack.sh
* debian/watch:
  + removed versionmangle and the reference to repack

[ gregor herrmann ]
* debian/control: add missing full stop to long description, thanks to
  Rhonda for spotting.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
use Test::More qw(no_plan);
6
6
 
7
 
use_ok( 'XML::Bare' );
 
7
use_ok( 'XML::Bare', qw/xmlin/ );
8
8
 
9
9
my $xml;
10
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 );
 
11
my $simple;
 
12
 
 
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' );
 
16
 
 
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' );
 
20
 
 
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' );
 
24
 
 
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' );
 
28
 
 
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' );
 
32
 
 
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' );
 
36
 
 
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_' );
 
40
 
 
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' );
 
45
 
 
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' );
 
49
 
 
50
( $xml, $root, $simple ) = reparse( "<xml><!--test--></xml>",1  );
 
51
is( $root->{xml}->{comment}, 'test', 'loading a comment' );
 
52
 
 
53
# test node addition
 
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' );
 
58
 
 
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
 
62
 
 
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' );
 
68
 
 
69
sub reparse {
 
70
  my $text = shift;
 
71
  my $nosimp = shift;
 
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 );
 
77
}
 
78
 
 
79
sub cyclic {
 
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" );
 
86
}
63
87
 
64
88
# test bad closing tags
65
89
# we need to a way to ensure that something dies... ?