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