File: 15_oo_cmp_ident.t

package info (click to toggle)
libxml-dumper-perl 0.81-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, jessie, jessie-kfreebsd, lenny, squeeze, wheezy
  • size: 196 kB
  • ctags: 32
  • sloc: perl: 535; makefile: 48; xml: 12
file content (87 lines) | stat: -rw-r--r-- 1,570 bytes parent folder | download | duplicates (6)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use strict;
use warnings;

use Test;
use XML::Dumper;

BEGIN { plan tests => 5 }

sub check( $$ );

check "a simple scalar", <<XML;
<perldata>
 <scalar>foo</scalar>
</perldata>
XML

check "a scalar reference", <<XML;
<perldata>
 <scalarref>Hi Mom</scalarref>
</perldata>
XML

check "a hash reference", <<XML;
<perldata>
 <hashref>
  <item key="key1">value1</item>
  <item key="key2">value2</item>
 </hashref>
</perldata>
XML

check "an array reference", <<XML;
<perldata>
 <arrayref>
  <item key="0">foo</item>
  <item key="1">bar</item>
 </arrayref>
</perldata>
XML

check "a combination of datatypes", <<XML;
<perldata>
 <arrayref>
  <item key="0">Scalar</item>
  <item key="1">
   <scalarref>ScalarRef</scalarref>
  </item>
  <item key="2">
   <arrayref>
    <item key="0">foo</item>
    <item key="1">bar</item>
   </arrayref>
  </item>
  <item key="3">
   <hashref>
    <item key="key1">value1</item>
    <item key="key2">value2</item>
   </hashref>
  </item>
 </arrayref>
</perldata>
XML

# ============================================================
sub check( $$ ) {
# ============================================================
	my $test = shift;
	my $xml = shift;

	my $dump = new XML::Dumper();

	my $perl = $dump->xml2pl( $xml );
	my $roundtrip_xml = $dump->pl2xml( $perl );

	if( $dump->xml_compare( $xml, $roundtrip_xml ) && $dump->xml_identity( $xml, $xml )) {
		ok( 1 );
		return;
	}

	print STDERR
		"\nTest for $test failed: data doesn't match!\n\n" . 
		"Got:\n----\n'$xml'\n----\n".
		"Came up with:\n----\n'$roundtrip_xml'\n----\n";

	ok( 0 );
}