| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package XML::Parsepp::Testgen; |
|
2
|
|
|
|
|
|
|
$XML::Parsepp::Testgen::VERSION = '0.03'; |
|
3
|
1
|
|
|
1
|
|
1768
|
use 5.014; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
47
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
7
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
42
|
|
|
6
|
1
|
|
|
1
|
|
23
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
47
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
339
|
use XML::Parser; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
|
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
12
|
|
|
|
|
|
|
our @EXPORT = qw(); |
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw(xml_2_test test_2_xml); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $template; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub xml_2_test { |
|
18
|
|
|
|
|
|
|
my ($input, $opts) = @_; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $xml = parm_2_text($input); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my ($xml_def1, $xml_def2) = $xml =~ m{\A (\N*) \n (\N*) \n}xms |
|
23
|
|
|
|
|
|
|
or die "Error-0010: Can't extract xml_defs from '". |
|
24
|
|
|
|
|
|
|
(substr($xml, 0, 50) =~ s{\n}'\\n'xmsgr)."...'"; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
unless ($xml_def1 eq '#! Testdata for XML::Parsepp') { |
|
27
|
|
|
|
|
|
|
die "Error-0020: Expected xml_def1 to be '#! Testdata for XML::Parsepp', but found '$xml_def1'"; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
unless ($xml_def2 eq '#! Ver 0.01') { |
|
31
|
|
|
|
|
|
|
die "Error-0030: Expected xml_def2 to be '#! Ver 0.01', but found '$xml_def2'"; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# $check_positions = 1 ==> check error-positions of the following form: |
|
35
|
|
|
|
|
|
|
# if ($err =~ m{at \s+ line \s+ (\d+), \s+ column \s+ (\d+), \s+ byte \s+ (\d+) \s+ at \s+}xms) |
|
36
|
|
|
|
|
|
|
my $check_positions = defined($opts) ? $opts->{'chkpos'} : 0; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my @HList = ( |
|
39
|
|
|
|
|
|
|
[ 'Init', 'INIT', '(Expat)' ], |
|
40
|
|
|
|
|
|
|
[ 'Final', 'FINL', '(Expat)' ], |
|
41
|
|
|
|
|
|
|
[ 'Start', 'STRT', '(Expat, Element, @Attr)' ], |
|
42
|
|
|
|
|
|
|
[ 'End', 'ENDL', '(Expat, Element)' ], |
|
43
|
|
|
|
|
|
|
[ 'Char', 'CHAR', '(Expat, String)' ], |
|
44
|
|
|
|
|
|
|
[ 'Proc', 'PROC', '(Expat, Target, Data)' ], |
|
45
|
|
|
|
|
|
|
[ 'Comment', 'COMT', '(Expat, Data)' ], |
|
46
|
|
|
|
|
|
|
[ 'CdataStart', 'CDST', '(Expat)' ], |
|
47
|
|
|
|
|
|
|
[ 'CdataEnd', 'CDEN', '(Expat)' ], |
|
48
|
|
|
|
|
|
|
[ 'Default', 'DEFT', '(Expat, String)' ], |
|
49
|
|
|
|
|
|
|
[ 'Unparsed', 'UNPS', '(Expat, Entity, Base, Sysid, Pubid, Notation)' ], |
|
50
|
|
|
|
|
|
|
[ 'Notation', 'NOTA', '(Expat, Notation, Base, Sysid, Pubid)' ], |
|
51
|
|
|
|
|
|
|
# [ 'ExternEnt', 'EXEN', '(Expat, Base, Sysid, Pubid)' ], |
|
52
|
|
|
|
|
|
|
# [ 'ExternEntFin', 'EXEF', '(Expat)' ], |
|
53
|
|
|
|
|
|
|
[ 'Entity', 'ENTT', '(Expat, Name, Val, Sysid, Pubid, Ndata, IsParam)' ], |
|
54
|
|
|
|
|
|
|
[ 'Element', 'ELEM', '(Expat, Name, Model)' ], |
|
55
|
|
|
|
|
|
|
[ 'Attlist', 'ATTL', '(Expat, Elname, Attname, Type, Default, Fixed)' ], |
|
56
|
|
|
|
|
|
|
[ 'Doctype', 'DOCT', '(Expat, Name, Sysid, Pubid, Internal)' ], |
|
57
|
|
|
|
|
|
|
[ 'DoctypeFin', 'DOCF', '(Expat)' ], |
|
58
|
|
|
|
|
|
|
[ 'XMLDecl', 'DECL', '(Expat, Version, Encoding, Standalone)' ], |
|
59
|
|
|
|
|
|
|
); |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my %HSub; |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $replm = q!s{([\x00-\x1f\[\]])}{sprintf('&<%02x>', ord($1))}xmsge!; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $i = 0; |
|
66
|
|
|
|
|
|
|
for my $hl (@HList) { $i++; |
|
67
|
|
|
|
|
|
|
my $func_body = ''; |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my @vlist = split m{,}xms, $hl->[2] =~ s{[\s\(\)]}''xmsgr; |
|
70
|
|
|
|
|
|
|
for my $vl (@vlist) { |
|
71
|
|
|
|
|
|
|
$vl = '$'.$vl unless $vl =~ m{\A \@}xms; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$func_body .= "{ # ".sprintf('%2d', $i).". ".sprintf('%-15s', $hl->[0])." ".$hl->[2]."\n"; |
|
75
|
|
|
|
|
|
|
$func_body .= " my (".join(', ', @vlist).") = \@_;\n\n"; |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $has_array = 0; |
|
78
|
|
|
|
|
|
|
my $j = 0; |
|
79
|
|
|
|
|
|
|
for my $vl (@vlist) { $j++; |
|
80
|
|
|
|
|
|
|
next if $j == 1; |
|
81
|
|
|
|
|
|
|
if ($vl =~ m{\A \@}xms) { |
|
82
|
|
|
|
|
|
|
$has_array = 1; |
|
83
|
|
|
|
|
|
|
$func_body .= " for my \$a ($vl) {\n"; |
|
84
|
|
|
|
|
|
|
$func_body .= " \$a //= '*undef*'; \$a =~ $replm;\n"; |
|
85
|
|
|
|
|
|
|
$func_body .= " }\n"; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
else { |
|
88
|
|
|
|
|
|
|
$func_body .= " ".sprintf('%-12s', $vl)." //= '*undef*'; ".sprintf('%-12s', $vl).' =~ '.$replm.";\n"; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
$func_body .= "\n"; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
$func_body .= qq! local \$" = "], [";\n! if $has_array; |
|
95
|
|
|
|
|
|
|
$func_body .= qq! push \@result, "!.$hl->[1]; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
$j = 0; |
|
98
|
|
|
|
|
|
|
for my $vl (@vlist) { $j++; |
|
99
|
|
|
|
|
|
|
next if $j == 1; |
|
100
|
|
|
|
|
|
|
$func_body .= qq!,! unless $j == 2; |
|
101
|
|
|
|
|
|
|
$func_body .= ' '.substr($vl, 1, 3)."=[$vl]"; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
$func_body .= qq!";\n!; |
|
104
|
|
|
|
|
|
|
$func_body .= qq!}\n!; |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
$HSub{$hl->[0]} = $func_body; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
my @result; |
|
110
|
|
|
|
|
|
|
my $err = ''; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my @HParam; |
|
113
|
|
|
|
|
|
|
for my $hl (@HList) { |
|
114
|
|
|
|
|
|
|
my $handler = eval 'sub '.$HSub{$hl->[0]}; |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
if ($@) { |
|
117
|
|
|
|
|
|
|
die "Error-0040: Can't eval 'sub ".$HSub{$hl->[0]}."' because $@"; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
unless (ref($handler) eq 'CODE') { |
|
121
|
|
|
|
|
|
|
die "Error-0050: Expected ref(handler) = 'CODE', but found '".ref($handler)."'"; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
push @HParam, $hl->[0], $handler; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
my $XmlParser = XML::Parser->new or die "Error-0060: Can't create XML::Parser -> new"; |
|
128
|
|
|
|
|
|
|
$XmlParser->setHandlers(@HParam); |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my @current; |
|
131
|
|
|
|
|
|
|
my @RList; |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
for (split m{\n}xms, $xml) { |
|
134
|
|
|
|
|
|
|
if (m{\A \s* \#! (.*) \z}xms) { |
|
135
|
|
|
|
|
|
|
my $remark = $1; |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
if ($remark =~ m{\A \s* =+ \s* \z}xms) { |
|
138
|
|
|
|
|
|
|
push @RList, { xml => [@current] } if @current; |
|
139
|
|
|
|
|
|
|
@current = (); |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
else { |
|
143
|
|
|
|
|
|
|
s{\s+ \z}''xms; |
|
144
|
|
|
|
|
|
|
push @current, $_; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
push @RList, { xml => [@current] } if @current; |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
my %HitCount = map { $_->[1] => 0 } @HList; |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
my $TestCount = @HList + 1; |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
for my $rl (@RList) { |
|
155
|
|
|
|
|
|
|
# get_result($XmlParser, map {"$_\n"} @{$rl->{xml}}); |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
@result = (); |
|
158
|
|
|
|
|
|
|
$err = ''; |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
my $ExpatNB = $XmlParser->parse_start or die "Error-0070: Can't create XML::Parser -> parse_start"; |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
eval { |
|
163
|
|
|
|
|
|
|
for my $buf (map {"$_\n"} @{$rl->{xml}}) { |
|
164
|
|
|
|
|
|
|
$ExpatNB->parse_more($buf); |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
}; |
|
167
|
|
|
|
|
|
|
if ($@) { |
|
168
|
|
|
|
|
|
|
$err = $@; |
|
169
|
|
|
|
|
|
|
$ExpatNB->release; |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
else { |
|
172
|
|
|
|
|
|
|
eval { |
|
173
|
|
|
|
|
|
|
$ExpatNB->parse_done; |
|
174
|
|
|
|
|
|
|
}; |
|
175
|
|
|
|
|
|
|
if ($@) { |
|
176
|
|
|
|
|
|
|
$err = $@; |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
} |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
$rl->{err} = $err; |
|
181
|
|
|
|
|
|
|
$rl->{res} = [@result]; |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
$TestCount += 2 + @result; |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
unless ($err eq '') { |
|
186
|
|
|
|
|
|
|
$err =~ m{at \s+ line \s+ (\d+), \s+ column \s+ (\d+), \s+ byte \s+ (\d+) \s+ at \s+}xms |
|
187
|
|
|
|
|
|
|
or die "Error-0080: Can't decompose error-line '$err'"; |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
$rl->{e_line} = $1; |
|
190
|
|
|
|
|
|
|
$rl->{e_col} = $2; |
|
191
|
|
|
|
|
|
|
$rl->{e_bytes} = $3; |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
if ($check_positions) { |
|
194
|
|
|
|
|
|
|
$TestCount += 3; |
|
195
|
|
|
|
|
|
|
} |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
for my $res (@result) { |
|
199
|
|
|
|
|
|
|
my $word = !defined($res) ? '!!!!' : $res =~ m{\A (\w{4}) }xms ? $1 : '????'; |
|
200
|
|
|
|
|
|
|
$HitCount{$word}++; |
|
201
|
|
|
|
|
|
|
} |
|
202
|
|
|
|
|
|
|
} |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
my $result = ''; |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
open my $ofh, '>', \$result or die "Error-0090: Can't open > '\\\$result' because $!"; |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
for (split m{\n}xms, $template) { |
|
209
|
|
|
|
|
|
|
if (m{\A \s* %}xms) { |
|
210
|
|
|
|
|
|
|
m{\A %include \s+ (\w+) \z}xms |
|
211
|
|
|
|
|
|
|
or die "Error-0100: Can't parse %include from '$_'"; |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
my $subject = $1; |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
if ($subject eq 'test_more') { |
|
216
|
|
|
|
|
|
|
say {$ofh} "use Test::More tests => $TestCount;" |
|
217
|
|
|
|
|
|
|
} |
|
218
|
|
|
|
|
|
|
elsif ($subject eq 'handlers') { |
|
219
|
|
|
|
|
|
|
my $ctr = 0; |
|
220
|
|
|
|
|
|
|
for my $hl (@HList) { $ctr++; |
|
221
|
|
|
|
|
|
|
printf {$ofh} " [%3d, %-12s => \\&handle_%-13s %-6s, occurs => %4d, %-65s ],\n", |
|
222
|
|
|
|
|
|
|
$ctr, $hl->[0], $hl->[0].',', "'$hl->[1]'", $HitCount{$hl->[1]}, sprintf("'%-12s %s'", $hl->[0], $hl->[2]); |
|
223
|
|
|
|
|
|
|
} |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
elsif ($subject eq 'cases') { |
|
226
|
|
|
|
|
|
|
say {$ofh} '# No of get_result is ', scalar(@RList); |
|
227
|
|
|
|
|
|
|
say {$ofh} ''; |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
my $tno = 0; |
|
230
|
|
|
|
|
|
|
for my $rl (@RList) { $tno++; |
|
231
|
|
|
|
|
|
|
say {$ofh} '{'; |
|
232
|
|
|
|
|
|
|
say {$ofh} ' get_result($XmlParser,'; |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
for my $lx (@{$rl->{xml}}) { |
|
235
|
|
|
|
|
|
|
if ($lx =~ m![\\{}]!xms) { |
|
236
|
|
|
|
|
|
|
die "Error-0110: Found invalid character in xml line '$lx'"; |
|
237
|
|
|
|
|
|
|
} |
|
238
|
|
|
|
|
|
|
say {$ofh} " q{$lx}.qq{\\n},"; |
|
239
|
|
|
|
|
|
|
} |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
say {$ofh} ' );'; |
|
242
|
|
|
|
|
|
|
say {$ofh} ''; |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
say {$ofh} ' my @expected = ('; |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
for my $ls (@{$rl->{res}}) { |
|
247
|
|
|
|
|
|
|
if ($ls =~ m![\\{}]!xms) { |
|
248
|
|
|
|
|
|
|
die "Error-0120: Found invalid character in result line '$ls'"; |
|
249
|
|
|
|
|
|
|
} |
|
250
|
|
|
|
|
|
|
say {$ofh} " q{$ls},"; |
|
251
|
|
|
|
|
|
|
} |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
say {$ofh} ' );'; |
|
254
|
|
|
|
|
|
|
say {$ofh} ''; |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
my $ecode = $rl->{err}; |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
if ($ecode eq '') { |
|
259
|
|
|
|
|
|
|
say {$ofh} q{ is($err, '', 'Test-}, sprintf('%03d', $tno), q{a: No error');}; |
|
260
|
|
|
|
|
|
|
} |
|
261
|
|
|
|
|
|
|
else { |
|
262
|
|
|
|
|
|
|
$ecode =~ m{\A (.*?) \s+ at \s+ line \s+ \d+}xms |
|
263
|
|
|
|
|
|
|
or die "Error-0130: Can't parse message from ecode = '$ecode'"; |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
my $emsg = $1; |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
$emsg =~ s{\A \s+}''xms; |
|
268
|
|
|
|
|
|
|
$emsg =~ m{\A [\w\s()\-]* \z}xms |
|
269
|
|
|
|
|
|
|
or die "Error-0140: Found invalid character in message = '$emsg'"; |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
$emsg =~ s{\s+}' \\s+ 'xmsg; |
|
272
|
|
|
|
|
|
|
$emsg =~ s{([()])}"\\$1"xmsg; |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
say {$ofh} q! like($err, qr{!, $emsg, q!}xms, 'Test-!, sprintf('%03d', $tno), q!a: error');!; |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
if ($check_positions) { |
|
277
|
|
|
|
|
|
|
say {$ofh} q!!; |
|
278
|
|
|
|
|
|
|
say {$ofh} q! my $e_line = -1;!; |
|
279
|
|
|
|
|
|
|
say {$ofh} q! my $e_col = -1;!; |
|
280
|
|
|
|
|
|
|
say {$ofh} q! my $e_bytes = -1;!; |
|
281
|
|
|
|
|
|
|
say {$ofh} q!!; |
|
282
|
|
|
|
|
|
|
say {$ofh} q! if ($err =~ m{at \s+ line \s+ (\d+), \s+ column \s+ (\d+), \s+ byte \s+ (\d+) \s+ at \s+}xms) {!; |
|
283
|
|
|
|
|
|
|
say {$ofh} q! $e_line = $1;!; |
|
284
|
|
|
|
|
|
|
say {$ofh} q! $e_col = $2;!; |
|
285
|
|
|
|
|
|
|
say {$ofh} q! $e_bytes = $3;!; |
|
286
|
|
|
|
|
|
|
say {$ofh} q! }!; |
|
287
|
|
|
|
|
|
|
say {$ofh} q!!; |
|
288
|
|
|
|
|
|
|
say {$ofh} q! is($e_line, !.sprintf('%4d', $rl->{e_line}) .q!, 'Test-!, sprintf('%03d', $tno), q!v1: error - lineno');!; |
|
289
|
|
|
|
|
|
|
say {$ofh} q! is($e_col, !.sprintf('%4d', $rl->{e_col}) .q!, 'Test-!, sprintf('%03d', $tno), q!v2: error - column');!; |
|
290
|
|
|
|
|
|
|
say {$ofh} q! is($e_bytes, !.sprintf('%4d', $rl->{e_bytes}).q!, 'Test-!, sprintf('%03d', $tno), q!v3: error - bytes');!; |
|
291
|
|
|
|
|
|
|
say {$ofh} q!!; |
|
292
|
|
|
|
|
|
|
} |
|
293
|
|
|
|
|
|
|
} |
|
294
|
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
say {$ofh} q{ is(scalar(@result), scalar(@expected), 'Test-}, sprintf('%03d', $tno), q{b: Number of results');}; |
|
296
|
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
say {$ofh} q{ verify('}, sprintf('%03d', $tno), q{', \\@result, \\@expected);}; |
|
298
|
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
say {$ofh} '}'; |
|
300
|
|
|
|
|
|
|
say {$ofh} ''; |
|
301
|
|
|
|
|
|
|
} |
|
302
|
|
|
|
|
|
|
} |
|
303
|
|
|
|
|
|
|
elsif ($subject eq 'handles') { |
|
304
|
|
|
|
|
|
|
my $i = 0; |
|
305
|
|
|
|
|
|
|
for my $hl (@HList) { $i++; |
|
306
|
|
|
|
|
|
|
say {$ofh} 'sub handle_', $hl->[0], ' ', $HSub{$hl->[0]}; |
|
307
|
|
|
|
|
|
|
} |
|
308
|
|
|
|
|
|
|
} |
|
309
|
|
|
|
|
|
|
else { |
|
310
|
|
|
|
|
|
|
die "Error-0150: Found invalid %include subject '$subject'"; |
|
311
|
|
|
|
|
|
|
} |
|
312
|
|
|
|
|
|
|
} |
|
313
|
|
|
|
|
|
|
else { |
|
314
|
|
|
|
|
|
|
say {$ofh} $_; |
|
315
|
|
|
|
|
|
|
} |
|
316
|
|
|
|
|
|
|
} |
|
317
|
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
close $ofh; |
|
319
|
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
return $result; |
|
321
|
|
|
|
|
|
|
} |
|
322
|
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
sub test_2_xml { |
|
324
|
|
|
|
|
|
|
my ($input) = @_; |
|
325
|
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
my $perl = parm_2_text($input); |
|
327
|
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
my ($def1, $def2, $def3) = $perl =~ m{\A (\N*) \n (\N*) \n (\N*) \n}xms |
|
329
|
|
|
|
|
|
|
or die "Error-0160: Can't extract use-statements from '". |
|
330
|
|
|
|
|
|
|
(substr($perl, 0, 50) =~ s{\n}'\\n'xmsgr)."...'"; |
|
331
|
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
unless ($def1 eq 'use 5.014;') { |
|
333
|
|
|
|
|
|
|
die "Error-0170: Expected def1 to be 'use 5.014;', but found '$def1'"; |
|
334
|
|
|
|
|
|
|
} |
|
335
|
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
unless ($def2 eq 'use warnings;') { |
|
337
|
|
|
|
|
|
|
die "Error-0180: Expected def2 to be 'use warnings;', but found '$def2'"; |
|
338
|
|
|
|
|
|
|
} |
|
339
|
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
unless ($def3 eq '# Generate Tests for XML::Parsepp') { |
|
341
|
|
|
|
|
|
|
die "Error-0190: Expected def3 to be '# Generate Tests for XML::Parsepp', but found '$def3'"; |
|
342
|
|
|
|
|
|
|
} |
|
343
|
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
$perl =~ m{\n\# \s No \s of \s get_result \s is \s (\d+) \n}xms |
|
345
|
|
|
|
|
|
|
or die "Error-0200: Can't find 'No of get_result...'"; |
|
346
|
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
my $gr_count = $1; |
|
348
|
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
my @gr_list = $perl =~ m{get_result\( (.*?) \);}xmsg; |
|
350
|
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
unless (@gr_list == $gr_count) { |
|
352
|
|
|
|
|
|
|
die "Error-0210: Found ".scalar(@gr_list)." get_result, but expected $gr_count"; |
|
353
|
|
|
|
|
|
|
} |
|
354
|
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
my $result = ''; |
|
356
|
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
open my $ofh, '>', \$result or die "Error-0220: Can't open > '\\\$result' because $!"; |
|
358
|
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
say {$ofh} '#! Testdata for XML::Parsepp'; |
|
360
|
|
|
|
|
|
|
say {$ofh} '#! Ver 0.01'; |
|
361
|
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
for my $i (0..$#gr_list) { |
|
363
|
|
|
|
|
|
|
my $text = $gr_list[$i]; |
|
364
|
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
say {$ofh} '#! ===' unless $i == 0; |
|
366
|
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
my @lines = split m{\n}xms, $text; |
|
368
|
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
my $first = shift @lines; |
|
370
|
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
unless (defined $first) { |
|
372
|
|
|
|
|
|
|
die "Error-0230: Too few elements in lines"; |
|
373
|
|
|
|
|
|
|
} |
|
374
|
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
unless ($first eq '$XmlParser,') { |
|
376
|
|
|
|
|
|
|
die "Error-0240: found first line = >>$first<<, but expected >>\$XmlParser,<<"; |
|
377
|
|
|
|
|
|
|
} |
|
378
|
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
for my $fragment (@lines) { |
|
380
|
|
|
|
|
|
|
next if $fragment =~ m{\A \s* \z}xms; |
|
381
|
|
|
|
|
|
|
my ($gr_xml) = $fragment =~ m/\A \s* q\{ ([^\}]*) \}\.qq\{\\n\}, \s* \z/xms |
|
382
|
|
|
|
|
|
|
or do { |
|
383
|
|
|
|
|
|
|
local $" = "<<, >>"; |
|
384
|
|
|
|
|
|
|
die "Error-0250: Can't parse fragment q{...} >>$fragment<<, all lines are (>>@lines<<)"; |
|
385
|
|
|
|
|
|
|
}; |
|
386
|
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
say {$ofh} $gr_xml; |
|
388
|
|
|
|
|
|
|
} |
|
389
|
|
|
|
|
|
|
} |
|
390
|
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
close $ofh; |
|
392
|
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
return $result; |
|
394
|
|
|
|
|
|
|
} |
|
395
|
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
sub parm_2_text { |
|
397
|
|
|
|
|
|
|
my ($inp) = @_; |
|
398
|
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
my $data; |
|
400
|
|
|
|
|
|
|
if (ref($inp)) { |
|
401
|
|
|
|
|
|
|
if (ref($inp) eq 'GLOB') { |
|
402
|
|
|
|
|
|
|
$data = do { local $/; <$inp>; }; |
|
403
|
|
|
|
|
|
|
} |
|
404
|
|
|
|
|
|
|
else { |
|
405
|
|
|
|
|
|
|
$data = $$inp; |
|
406
|
|
|
|
|
|
|
} |
|
407
|
|
|
|
|
|
|
} |
|
408
|
|
|
|
|
|
|
else { |
|
409
|
|
|
|
|
|
|
open my $fh, '<', $inp or die "Error-0260: Can't open < '$inp' because $!"; |
|
410
|
|
|
|
|
|
|
$data = do { local $/; <$fh>; }; |
|
411
|
|
|
|
|
|
|
} |
|
412
|
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
return $data; |
|
414
|
|
|
|
|
|
|
} |
|
415
|
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
$template = <<'EOTXT'; |
|
417
|
|
|
|
|
|
|
use 5.014; |
|
418
|
|
|
|
|
|
|
use warnings; |
|
419
|
|
|
|
|
|
|
# Generate Tests for XML::Parsepp |
|
420
|
|
|
|
|
|
|
|
|
421
|
|
|
|
|
|
|
%include test_more |
|
422
|
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
my $XML_module = 'XML::Parsepp'; |
|
424
|
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
use_ok($XML_module); |
|
426
|
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
my @result; |
|
428
|
|
|
|
|
|
|
my $err = ''; |
|
429
|
|
|
|
|
|
|
my $line_more; |
|
430
|
|
|
|
|
|
|
my $line_done; |
|
431
|
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
my $XmlParser = $XML_module->new or die "Error-0010: Can't create $XML_module -> new"; |
|
433
|
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
my @Handlers = ( |
|
435
|
|
|
|
|
|
|
%include handlers |
|
436
|
|
|
|
|
|
|
); |
|
437
|
|
|
|
|
|
|
|
|
438
|
|
|
|
|
|
|
my @HParam; |
|
439
|
|
|
|
|
|
|
for my $H (@Handlers) { |
|
440
|
|
|
|
|
|
|
push @HParam, $H->[1], $H->[2]; |
|
441
|
|
|
|
|
|
|
} |
|
442
|
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
my %HInd; |
|
444
|
|
|
|
|
|
|
my @HCount; |
|
445
|
|
|
|
|
|
|
for my $i (0..$#Handlers) { |
|
446
|
|
|
|
|
|
|
$HInd{$Handlers[$i][3]} = $i; |
|
447
|
|
|
|
|
|
|
$HCount[$i] = 0; |
|
448
|
|
|
|
|
|
|
} |
|
449
|
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
$XmlParser->setHandlers(@HParam); |
|
451
|
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
# most testcases have been inspired by... |
|
453
|
|
|
|
|
|
|
# http://www.u-picardie.fr/~ferment/xml/xml02.html |
|
454
|
|
|
|
|
|
|
# http://www.comptechdoc.org/independent/web/dtd/dtddekeywords.html |
|
455
|
|
|
|
|
|
|
# http://xmlwriter.net/xml_guide/attlist_declaration.shtml |
|
456
|
|
|
|
|
|
|
# ************************************************************************************* |
|
457
|
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
%include cases |
|
459
|
|
|
|
|
|
|
# **************************************************************************************************************************** |
|
460
|
|
|
|
|
|
|
# **************************************************************************************************************************** |
|
461
|
|
|
|
|
|
|
# **************************************************************************************************************************** |
|
462
|
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
{ |
|
464
|
|
|
|
|
|
|
for my $i (0..$#Handlers) { |
|
465
|
|
|
|
|
|
|
is($HCount[$i], $Handlers[$i][5], 'Test-890c-'.sprintf('%03d', $i).': correct counts for <'.$Handlers[$i][3].'>'); |
|
466
|
|
|
|
|
|
|
} |
|
467
|
|
|
|
|
|
|
} |
|
468
|
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
# **************************************************************************************************************************** |
|
470
|
|
|
|
|
|
|
# **************************************************************************************************************************** |
|
471
|
|
|
|
|
|
|
# **************************************************************************************************************************** |
|
472
|
|
|
|
|
|
|
|
|
473
|
|
|
|
|
|
|
sub verify { |
|
474
|
|
|
|
|
|
|
my ($num, $res, $exp) = @_; |
|
475
|
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
for my $i (0..$#$exp) { |
|
477
|
|
|
|
|
|
|
is($res->[$i], $exp->[$i], 'Test-'.$num.'c-'.sprintf('%03d', $i).': correct result'); |
|
478
|
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
my $word = !defined($res->[$i]) ? '!!!!' : $res->[$i] =~ m{\A (\w{4}) }xms ? $1 : '????'; |
|
480
|
|
|
|
|
|
|
my $ind = $HInd{$word}; |
|
481
|
|
|
|
|
|
|
if (defined $ind) { |
|
482
|
|
|
|
|
|
|
$HCount[$ind]++; |
|
483
|
|
|
|
|
|
|
} |
|
484
|
|
|
|
|
|
|
} |
|
485
|
|
|
|
|
|
|
} |
|
486
|
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
sub get_result { |
|
488
|
|
|
|
|
|
|
my $Parser = shift; |
|
489
|
|
|
|
|
|
|
@result = (); |
|
490
|
|
|
|
|
|
|
$err = ''; |
|
491
|
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
my $ExpatNB = $Parser->parse_start or die "Error-0020: Can't create XML::Parser->parse_start"; |
|
493
|
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
eval { |
|
495
|
|
|
|
|
|
|
for my $buf (@_) { |
|
496
|
|
|
|
|
|
|
$ExpatNB->parse_more($buf); |
|
497
|
|
|
|
|
|
|
} |
|
498
|
|
|
|
|
|
|
}; |
|
499
|
|
|
|
|
|
|
if ($@) { |
|
500
|
|
|
|
|
|
|
$err = $@; |
|
501
|
|
|
|
|
|
|
$ExpatNB->release; |
|
502
|
|
|
|
|
|
|
} |
|
503
|
|
|
|
|
|
|
else { |
|
504
|
|
|
|
|
|
|
eval { |
|
505
|
|
|
|
|
|
|
$ExpatNB->parse_done; |
|
506
|
|
|
|
|
|
|
}; |
|
507
|
|
|
|
|
|
|
if ($@) { |
|
508
|
|
|
|
|
|
|
$err = $@; |
|
509
|
|
|
|
|
|
|
} |
|
510
|
|
|
|
|
|
|
} |
|
511
|
|
|
|
|
|
|
} |
|
512
|
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
%include handles |
|
514
|
|
|
|
|
|
|
EOTXT |
|
515
|
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
1; |
|
517
|
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
__END__ |