line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2008-2012 by [Mark Overmeer]. |
2
|
|
|
|
|
|
|
# For other contributors see ChangeLog. |
3
|
|
|
|
|
|
|
# See the manual pages for details on the licensing terms. |
4
|
|
|
|
|
|
|
# Pod stripped from pm file by OODoc 2.00. |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
795
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
7
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package XML::Compile::Tester; |
10
|
1
|
|
|
1
|
|
15
|
use vars '$VERSION'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
11
|
|
|
|
|
|
|
$VERSION = '0.90'; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
5
|
use base 'Exporter'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
134
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @EXPORT = qw/ |
16
|
|
|
|
|
|
|
set_compile_defaults |
17
|
|
|
|
|
|
|
set_default_namespace |
18
|
|
|
|
|
|
|
reader_create create_reader |
19
|
|
|
|
|
|
|
writer_create create_writer |
20
|
|
|
|
|
|
|
writer_test |
21
|
|
|
|
|
|
|
reader_error |
22
|
|
|
|
|
|
|
writer_error |
23
|
|
|
|
|
|
|
templ_xml |
24
|
|
|
|
|
|
|
templ_perl |
25
|
|
|
|
|
|
|
templ_tree |
26
|
|
|
|
|
|
|
compare_xml |
27
|
|
|
|
|
|
|
/; |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
1
|
|
4
|
use Test::More; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
30
|
1
|
|
|
1
|
|
1570
|
use Data::Dumper; |
|
1
|
|
|
|
|
7812
|
|
|
1
|
|
|
|
|
99
|
|
31
|
1
|
|
|
1
|
|
1178
|
use Log::Report qw/try/; |
|
1
|
|
|
|
|
131702
|
|
|
1
|
|
|
|
|
9
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $default_namespace; |
34
|
|
|
|
|
|
|
my @compile_defaults; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# not using pack_type, which avoids a recursive dependency to XML::Compile |
38
|
|
|
|
|
|
|
sub _reltype_to_abs($) |
39
|
0
|
0
|
0
|
0
|
|
|
{ defined $default_namespace && substr($_[0], 0,1) eq '{' |
40
|
|
|
|
|
|
|
? "{$default_namespace}$_[0]" : $_[0] } |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub reader_create($$$@) |
43
|
0
|
|
|
0
|
1
|
|
{ my ($schema, $test, $reltype) = splice @_, 0, 3; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $type = _reltype_to_abs $reltype; |
46
|
0
|
|
|
|
|
|
my $read_t = $schema->compile |
47
|
|
|
|
|
|
|
( READER => $type |
48
|
|
|
|
|
|
|
, check_values => 1 |
49
|
|
|
|
|
|
|
, include_namespaces => 0 |
50
|
|
|
|
|
|
|
, @compile_defaults |
51
|
|
|
|
|
|
|
, @_ |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
isa_ok($read_t, 'CODE', "reader element $test"); |
55
|
0
|
|
|
|
|
|
$read_t; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
*create_reader = \&reader_create; # name change in 0.03 |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub reader_error($$$) |
61
|
0
|
|
|
0
|
1
|
|
{ my ($schema, $reltype, $xml) = @_; |
62
|
0
|
|
|
|
|
|
my $r = reader_create $schema, "check read error $reltype", $reltype; |
63
|
0
|
0
|
|
|
|
|
defined $r or return; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
0
|
|
|
my $tree = try { $r->($xml) }; |
|
0
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $error = ref $@ && $@->exceptions |
67
|
0
|
0
|
0
|
|
|
|
? join("\n", map {$_->message} $@->exceptions) |
68
|
|
|
|
|
|
|
: ''; |
69
|
0
|
0
|
|
|
|
|
undef $tree |
70
|
|
|
|
|
|
|
if $error; # there is output if only warnings are produced |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
ok(!defined $tree, "no return for $reltype"); |
73
|
0
|
0
|
|
|
|
|
warn "RETURNED TREE=",Dumper $tree if defined $tree; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
ok(length $error, "ER=$error"); |
76
|
0
|
|
|
|
|
|
$error; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub writer_create($$$@) |
81
|
0
|
|
|
0
|
1
|
|
{ my ($schema, $test, $reltype) = splice @_, 0, 3; |
82
|
0
|
|
|
|
|
|
my $type = _reltype_to_abs $reltype; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my $write_t = $schema->compile |
85
|
|
|
|
|
|
|
( WRITER => $type |
86
|
|
|
|
|
|
|
, check_values => 1 |
87
|
|
|
|
|
|
|
, include_namespaces => 0 |
88
|
|
|
|
|
|
|
, use_default_namespace => 1 |
89
|
|
|
|
|
|
|
, @compile_defaults |
90
|
|
|
|
|
|
|
, @_ |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
isa_ok($write_t, 'CODE', "writer element $test"); |
94
|
0
|
|
|
|
|
|
$write_t; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
*create_writer = \&writer_create; # name change in 0.03 |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub writer_test($$;$) |
100
|
0
|
|
|
0
|
1
|
|
{ my ($writer, $data, $doc) = @_; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
0
|
|
|
|
$doc ||= XML::LibXML->createDocument('1.0', 'UTF-8'); |
103
|
0
|
|
|
|
|
|
isa_ok($doc, 'XML::LibXML::Document'); |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $tree = $writer->($doc, $data); |
106
|
0
|
|
|
|
|
|
ok(defined $tree); |
107
|
0
|
0
|
|
|
|
|
defined $tree or return; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
isa_ok($tree, 'XML::LibXML::Node'); |
110
|
0
|
|
|
|
|
|
$tree; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub writer_error($$$) |
115
|
0
|
|
|
0
|
1
|
|
{ my ($schema, $reltype, $data) = @_; |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
my $write = writer_create $schema, "writer for $reltype", $reltype; |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
my $node; |
120
|
0
|
|
|
0
|
|
|
try { my $doc = XML::LibXML->createDocument('1.0', 'UTF-8'); |
121
|
0
|
|
|
|
|
|
isa_ok($doc, 'XML::LibXML::Document'); |
122
|
0
|
|
|
|
|
|
$node = $write->($doc, $data); |
123
|
0
|
|
|
|
|
|
}; |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
my $error |
126
|
|
|
|
|
|
|
= ref $@ && $@->exceptions |
127
|
0
|
0
|
0
|
|
|
|
? join("\n", map {$_->message} $@->exceptions) |
128
|
|
|
|
|
|
|
: ''; |
129
|
0
|
0
|
|
|
|
|
undef $node if $error; # there is output if only warnings are produced |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# my $error = $@ ? $@->wasFatal->message : ''; |
132
|
0
|
|
|
|
|
|
ok(!defined $node, "no return for $reltype expected"); |
133
|
0
|
0
|
|
|
|
|
warn "RETURNED =", $node->toString if ref $node; |
134
|
0
|
|
|
|
|
|
ok(length $error, "EW=$error"); |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
$error; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub templ_xml($$@) |
141
|
0
|
|
|
0
|
1
|
|
{ my ($schema, $test, @opts) = @_; |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
my $abs = _reltype_to_abs $test; |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
$schema->template |
146
|
|
|
|
|
|
|
( XML => $abs |
147
|
|
|
|
|
|
|
, include_namespaces => 1 |
148
|
|
|
|
|
|
|
, @opts |
149
|
|
|
|
|
|
|
) . "\n"; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub templ_perl($$@) |
154
|
0
|
|
|
0
|
1
|
|
{ my ($schema, $test, @opts) = @_; |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
my $abs = _reltype_to_abs $test; |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
$schema->template |
159
|
|
|
|
|
|
|
( PERL => $abs |
160
|
|
|
|
|
|
|
, include_namespaces => 0 |
161
|
|
|
|
|
|
|
, @opts |
162
|
|
|
|
|
|
|
); |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub templ_tree($$@) |
167
|
0
|
|
|
0
|
0
|
|
{ my ($schema, $test, @opts) = @_; |
168
|
0
|
|
|
|
|
|
my $abs = _reltype_to_abs($test); |
169
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
|
$schema->template |
171
|
|
|
|
|
|
|
( TREE => $abs |
172
|
|
|
|
|
|
|
, @opts |
173
|
|
|
|
|
|
|
); |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
178
|
0
|
|
|
0
|
1
|
|
sub set_compile_defaults(@) { @compile_defaults = @_ } |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
|
181
|
0
|
|
|
0
|
1
|
|
sub set_default_namespace($) { $default_namespace = shift } |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub compare_xml($$;$) |
185
|
0
|
|
|
0
|
1
|
|
{ my ($tree, $expect, $comment) = @_; |
186
|
0
|
0
|
|
|
|
|
my $dump = ref $tree ? $tree->toString : $tree; |
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
for($dump, $expect) |
189
|
0
|
0
|
|
|
|
|
{ defined $_ or next; |
190
|
0
|
|
|
|
|
|
s/\>\s+/>/gs; |
191
|
0
|
|
|
|
|
|
s/\s+\
|
192
|
0
|
|
|
|
|
|
s/\>\s+\
|
193
|
0
|
|
|
|
|
|
s/\s*\n\s*/ /gs; |
194
|
0
|
|
|
|
|
|
s/\s{2,}/ /gs; |
195
|
0
|
|
|
|
|
|
s/\s+\z//gs; |
196
|
|
|
|
|
|
|
} |
197
|
0
|
|
|
|
|
|
is($dump, $expect, $comment); |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
1; |