1 |
wakaba |
1.1 |
#!/usr/bin/perl -w |
2 |
|
|
use strict; |
3 |
wakaba |
1.2 |
BEGIN { require 'manakai/genlib.pl' } |
4 |
wakaba |
1.1 |
|
5 |
wakaba |
1.6 |
use Message::Util::QName::Filter { |
6 |
|
|
ManakaiDOMLS2003 => q<http://suika.fam.cx/~wakaba/archive/2004/9/27/mdom-old-ls#>, |
7 |
wakaba |
1.1 |
}; |
8 |
|
|
use Message::DOM::ManakaiDOMLS2003; |
9 |
|
|
use Message::DOM::DOMLS qw/MODE_SYNCHRONOUS/; |
10 |
|
|
|
11 |
wakaba |
1.3 |
require 'dommemlist.pl.tmp'; ## Generated by mkdommemlist.pl |
12 |
|
|
|
13 |
wakaba |
1.9 |
use Getopt::Long; |
14 |
|
|
use Pod::Usage; |
15 |
|
|
my %Opt = (); |
16 |
wakaba |
1.3 |
GetOptions ( |
17 |
wakaba |
1.9 |
'debug' => \$Opt{debug}, |
18 |
|
|
'help' => \$Opt{help}, |
19 |
|
|
'output-file-name=s' => \$Opt{output_file_name}, |
20 |
|
|
'verbose!' => \$Opt{verbose}, |
21 |
|
|
) or pod2usage (2); |
22 |
|
|
pod2usage ({-exitval => 0, -verbose => 1}) if $Opt{help}; |
23 |
|
|
$Opt{file_name} = shift; |
24 |
|
|
pod2usage ({-exitval => 2, -verbose => 0}) unless $Opt{file_name}; |
25 |
|
|
$Message::DOM::DOMFeature::DEBUG = 1 if $Opt{debug}; |
26 |
|
|
|
27 |
|
|
sub status_msg ($) { |
28 |
|
|
my $s = shift; |
29 |
|
|
$s .= "\n" unless $s =~ /\n$/; |
30 |
|
|
print STDERR $s; |
31 |
|
|
} |
32 |
|
|
|
33 |
|
|
sub status_msg_ ($) { |
34 |
|
|
my $s = shift; |
35 |
|
|
print STDERR $s; |
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
sub verbose_msg ($) { |
39 |
|
|
my $s = shift; |
40 |
|
|
$s .= "\n" unless $s =~ /\n$/; |
41 |
|
|
print STDERR $s if $Opt{verbose}; |
42 |
|
|
} |
43 |
wakaba |
1.8 |
|
44 |
wakaba |
1.9 |
sub verbose_msg_ ($) { |
45 |
|
|
my $s = shift; |
46 |
|
|
print STDERR $s if $Opt{verbose}; |
47 |
wakaba |
1.3 |
} |
48 |
|
|
|
49 |
wakaba |
1.9 |
my $start_time; |
50 |
|
|
BEGIN { $start_time = time } |
51 |
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
wakaba |
1.4 |
our $Method; |
55 |
|
|
our $IFMethod; |
56 |
wakaba |
1.3 |
our $Attr; |
57 |
wakaba |
1.1 |
my $Assert = { |
58 |
|
|
qw/assertDOMException 1 |
59 |
wakaba |
1.5 |
assertEquals 1 |
60 |
wakaba |
1.3 |
assertFalse 1 |
61 |
wakaba |
1.5 |
assertInstanceOf 1 |
62 |
wakaba |
1.1 |
assertNotNull 1 |
63 |
wakaba |
1.3 |
assertNull 1 |
64 |
wakaba |
1.5 |
assertSame 1 |
65 |
wakaba |
1.4 |
assertSize 1 |
66 |
wakaba |
1.5 |
assertTrue 1 |
67 |
|
|
assertURIEquals 1/ |
68 |
wakaba |
1.1 |
}; |
69 |
|
|
my $Misc = { |
70 |
wakaba |
1.5 |
qw/append 1 |
71 |
|
|
assign 1 |
72 |
|
|
decrement 1 |
73 |
|
|
fail 1 |
74 |
|
|
if 1 |
75 |
wakaba |
1.3 |
implementationAttribute 1 |
76 |
wakaba |
1.5 |
increment 1 |
77 |
|
|
for 1 |
78 |
|
|
plus 1 |
79 |
|
|
var 1 |
80 |
|
|
while 1/ |
81 |
wakaba |
1.1 |
}; |
82 |
wakaba |
1.3 |
my $Condition = { |
83 |
|
|
qw/condition 1 |
84 |
|
|
contains 1 |
85 |
|
|
contentType 1 |
86 |
wakaba |
1.5 |
equals 1 |
87 |
|
|
greater 1 |
88 |
|
|
greaterOrEquals 1 |
89 |
wakaba |
1.3 |
hasSize 1 |
90 |
|
|
implementationAttribute 1 |
91 |
wakaba |
1.5 |
instanceOf 1 |
92 |
|
|
isNull 1 |
93 |
|
|
less 1 |
94 |
|
|
lessOrEquals 1 |
95 |
wakaba |
1.3 |
not 1 |
96 |
wakaba |
1.5 |
notEquals 1 |
97 |
wakaba |
1.3 |
notNull 1 |
98 |
|
|
or 1/ |
99 |
|
|
}; |
100 |
|
|
|
101 |
|
|
my $Status = {Number => 0, our => {Info => 1}}; |
102 |
|
|
|
103 |
|
|
sub to_perl_value ($;%) { |
104 |
|
|
my ($s, %opt) = @_; |
105 |
|
|
if (defined $s) { |
106 |
|
|
if ($s =~ /^(?!\d)\w+$/) { |
107 |
wakaba |
1.5 |
if ({true => 1, false => 1}->{$s}) { |
108 |
|
|
return {true => '1', false => '0'}->{$s}; |
109 |
|
|
} else { |
110 |
|
|
return perl_var (type => '$', local_name => $s); |
111 |
|
|
} |
112 |
wakaba |
1.3 |
} else { |
113 |
|
|
return $s; |
114 |
|
|
} |
115 |
|
|
} elsif (defined $opt{default}) { |
116 |
|
|
return $opt{default}; |
117 |
|
|
} else { |
118 |
|
|
return ''; |
119 |
|
|
} |
120 |
|
|
} |
121 |
wakaba |
1.1 |
|
122 |
|
|
sub body2code ($) { |
123 |
|
|
my $parent = shift; |
124 |
|
|
my $result = ''; |
125 |
wakaba |
1.9 |
my $children = $parent->child_nodes; |
126 |
wakaba |
1.1 |
for (my $i = 0; $i < $children->length; $i++) { |
127 |
|
|
my $child = $children->item ($i); |
128 |
wakaba |
1.9 |
if ($child->node_type == $child->ELEMENT_NODE) { |
129 |
|
|
my $ln = $child->local_name; |
130 |
wakaba |
1.1 |
if ($Method->{$ln} or $Attr->{$ln} or |
131 |
|
|
$Assert->{$ln} or $Misc->{$ln}) { |
132 |
|
|
$result .= node2code ($child); |
133 |
|
|
} else { |
134 |
wakaba |
1.9 |
valid_err q<Unknown element type: >.$child->local_name, |
135 |
wakaba |
1.1 |
node => $child; |
136 |
|
|
} |
137 |
wakaba |
1.9 |
} elsif ($child->node_type == $child->COMMENT_NODE) { |
138 |
wakaba |
1.1 |
$result .= perl_comment $child->data; |
139 |
wakaba |
1.9 |
} elsif ($child->node_type == $child->TEXT_NODE) { |
140 |
wakaba |
1.1 |
if ($child->data =~ /\S/) { |
141 |
|
|
valid_err q<Unknown character data: >.$child->data, |
142 |
|
|
node => $child; |
143 |
|
|
} |
144 |
|
|
} else { |
145 |
wakaba |
1.9 |
valid_err q<Unknown type of node: >.$child->node_type, |
146 |
wakaba |
1.1 |
node => $child; |
147 |
|
|
} |
148 |
|
|
} |
149 |
|
|
$result; |
150 |
|
|
} |
151 |
|
|
|
152 |
wakaba |
1.3 |
sub condition2code ($;%) { |
153 |
|
|
my ($parent, %opt) = @_; |
154 |
|
|
my $result = ''; |
155 |
|
|
my @result; |
156 |
wakaba |
1.9 |
my $children = $parent->child_nodes; |
157 |
wakaba |
1.3 |
for (my $i = 0; $i < $children->length; $i++) { |
158 |
|
|
my $child = $children->item ($i); |
159 |
wakaba |
1.9 |
if ($child->node_type == $child->ELEMENT_NODE) { |
160 |
|
|
my $ln = $child->local_name; |
161 |
wakaba |
1.3 |
if ($Condition->{$ln}) { |
162 |
|
|
push @result, node2code ($child); |
163 |
|
|
} else { |
164 |
wakaba |
1.9 |
valid_err q<Unknown element type: >.$child->local_name, |
165 |
wakaba |
1.3 |
node => $child; |
166 |
|
|
} |
167 |
wakaba |
1.9 |
} elsif ($child->node_type == $child->COMMENT_NODE) { |
168 |
wakaba |
1.3 |
$result .= perl_comment $child->data; |
169 |
wakaba |
1.9 |
} elsif ($child->node_type == $child->TEXT_NODE) { |
170 |
wakaba |
1.3 |
if ($child->data =~ /\S/) { |
171 |
|
|
valid_err q<Unknown character data: >.$child->data, |
172 |
|
|
node => $child; |
173 |
|
|
} |
174 |
|
|
} else { |
175 |
wakaba |
1.9 |
valid_err q<Unknown type of node: >.$child->node_type, |
176 |
wakaba |
1.3 |
node => $child; |
177 |
|
|
} |
178 |
|
|
} |
179 |
|
|
$result .= join (($opt{join}||='or' eq 'or' ? ' || ' : |
180 |
|
|
$opt{join} eq 'and' ? ' && ' : |
181 |
|
|
valid_err q<Multiple condition not supported>, |
182 |
|
|
node => $parent), |
183 |
|
|
map {"($_)"} @result); |
184 |
|
|
$result; |
185 |
|
|
} #condition2code |
186 |
|
|
|
187 |
|
|
sub node2code ($); |
188 |
wakaba |
1.1 |
sub node2code ($) { |
189 |
|
|
my $node = shift; |
190 |
|
|
my $result = ''; |
191 |
wakaba |
1.9 |
if ($node->node_type != $node->ELEMENT_NODE) { |
192 |
|
|
if ($node->node_type == $node->COMMENT_NODE) { |
193 |
wakaba |
1.3 |
$result .= perl_comment $node->data; |
194 |
wakaba |
1.9 |
} elsif ($node->node_type == $node->TEXT_NODE) { |
195 |
wakaba |
1.3 |
if ($node->data =~ /\S/) { |
196 |
|
|
valid_err q<Unknown character data: >.$node->data, |
197 |
|
|
node => $node; |
198 |
|
|
} |
199 |
|
|
} else { |
200 |
wakaba |
1.9 |
valid_err q<Unknown type of node: >.$node->node_type, |
201 |
wakaba |
1.3 |
node => $node; |
202 |
|
|
} |
203 |
|
|
return $result; |
204 |
|
|
} |
205 |
wakaba |
1.9 |
my $ln = $node->local_name; |
206 |
wakaba |
1.1 |
|
207 |
|
|
if ($ln eq 'var') { |
208 |
wakaba |
1.9 |
my $name = $node->get_attribute_ns (undef, 'name'); |
209 |
wakaba |
1.5 |
my $var = perl_var |
210 |
wakaba |
1.3 |
local_name => $name, |
211 |
wakaba |
1.1 |
scope => 'my', |
212 |
|
|
type => '$'; |
213 |
wakaba |
1.9 |
my $type = $node->get_attribute_ns (undef, 'type'); |
214 |
wakaba |
1.5 |
$result .= perl_comment $type; |
215 |
wakaba |
1.9 |
if ($node->has_attribute_ns (undef, 'isNull') and |
216 |
|
|
$node->get_attribute_ns (undef, 'isNull') eq 'true') { |
217 |
wakaba |
1.5 |
$result .= perl_statement perl_assign $var => 'undef'; |
218 |
wakaba |
1.9 |
} elsif ($node->has_attribute_ns (undef, 'value')) { |
219 |
wakaba |
1.5 |
$result .= perl_statement |
220 |
|
|
perl_assign |
221 |
|
|
$var |
222 |
wakaba |
1.9 |
=> to_perl_value ($node->get_attribute_ns (undef, 'value')); |
223 |
wakaba |
1.5 |
} else { |
224 |
|
|
if ($type eq 'List' or $type eq 'Collection') { |
225 |
|
|
my @member; |
226 |
wakaba |
1.9 |
my $children = $node->child_nodes; |
227 |
wakaba |
1.5 |
for (my $i = 0; $i < $children->length; $i++) { |
228 |
|
|
my $child = $children->item ($i); |
229 |
wakaba |
1.9 |
if ($child->node_type == $child->ELEMENT_NODE) { |
230 |
|
|
if ($child->local_name eq 'member') { |
231 |
wakaba |
1.5 |
push @member, perl_code_literal |
232 |
wakaba |
1.9 |
(to_perl_value ($child->text_content)); |
233 |
wakaba |
1.5 |
} else { |
234 |
|
|
valid_err q<Unsupported element type>, node => $child; |
235 |
|
|
} |
236 |
wakaba |
1.9 |
} elsif ($child->node_type == $child->COMMENT_NODE) { |
237 |
wakaba |
1.5 |
$result .= perl_comment $child->data; |
238 |
|
|
} |
239 |
|
|
} |
240 |
|
|
$result .= perl_statement |
241 |
|
|
perl_assign |
242 |
|
|
$var |
243 |
|
|
=> perl_list \@member; |
244 |
|
|
} elsif ($type =~ /Monitor/) { |
245 |
|
|
valid_err qq<Type $type not supported>, node => $node; |
246 |
wakaba |
1.9 |
} elsif ($node->has_child_nodes) { |
247 |
wakaba |
1.5 |
valid_err q<Children not supported>, node => $node; |
248 |
|
|
} else { |
249 |
|
|
$result .= perl_statement $var; |
250 |
|
|
} |
251 |
wakaba |
1.3 |
} |
252 |
wakaba |
1.9 |
$Status->{var}->{$name}->{type} = $node->get_attribute_ns (undef, 'type'); |
253 |
wakaba |
1.3 |
} elsif ($ln eq 'load') { |
254 |
wakaba |
1.1 |
$result .= perl_statement |
255 |
|
|
perl_assign |
256 |
|
|
perl_var |
257 |
|
|
(type => '$', |
258 |
wakaba |
1.9 |
local_name => $node->get_attribute_ns (undef, 'var')) |
259 |
wakaba |
1.1 |
=> 'load (' . |
260 |
wakaba |
1.9 |
perl_literal ($node->get_attribute_ns (undef, 'href')). |
261 |
wakaba |
1.1 |
')'; |
262 |
wakaba |
1.7 |
} elsif ($ln eq 'hasFeature' and |
263 |
wakaba |
1.9 |
not $node->has_attribute_ns (undef, 'var')) { |
264 |
wakaba |
1.7 |
## If there is a "hasFeature" element in "body" and |
265 |
|
|
## it does not have "var" attribute, then it is part of the |
266 |
|
|
## implementation condition. |
267 |
|
|
$result .= perl_statement 'hasFeature ('. |
268 |
wakaba |
1.9 |
to_perl_value ($node->get_attribute_ns (undef, 'feature'), |
269 |
wakaba |
1.7 |
default => 'undef') . ', '. |
270 |
wakaba |
1.9 |
to_perl_value ($node->get_attribute_ns (undef, 'version'), |
271 |
wakaba |
1.7 |
default => 'undef') . ')'; |
272 |
wakaba |
1.9 |
} elsif ($Method->{$ln} or $Attr->{$ln}) { |
273 |
|
|
MA: { |
274 |
|
|
M: { |
275 |
|
|
last M unless $Method->{$ln}; |
276 |
wakaba |
1.1 |
$result .= perl_var (type => '$', |
277 |
wakaba |
1.9 |
local_name => $node->get_attribute_ns (undef, 'var')). |
278 |
wakaba |
1.1 |
' = ' |
279 |
wakaba |
1.9 |
if $node->has_attribute_ns (undef, 'var'); |
280 |
wakaba |
1.4 |
my $param; |
281 |
wakaba |
1.9 |
if ($node->has_attribute_ns (undef, 'interface')) { |
282 |
|
|
my $if = $node->get_attribute_ns (undef, 'interface'); |
283 |
wakaba |
1.5 |
$param = $IFMethod->{$if}->{$ln}; |
284 |
|
|
unless ($param) { |
285 |
wakaba |
1.9 |
last M if $Attr->{$ln}; |
286 |
wakaba |
1.5 |
valid_err "Method $if.$ln not supported", node => $node; |
287 |
|
|
} |
288 |
|
|
if ($if eq 'Element' and $ln eq 'getElementsByTagName' and |
289 |
wakaba |
1.9 |
not $node->has_attribute_ns (undef, 'name') and |
290 |
|
|
$node->has_attribute_ns (undef, 'tagname')) { |
291 |
|
|
$node->set_attribute_ns (undef, 'name' |
292 |
|
|
=> $node->get_attribute_ns (undef, 'tagname')); |
293 |
wakaba |
1.5 |
} |
294 |
wakaba |
1.4 |
} else { |
295 |
|
|
$param = $Method->{$ln}; |
296 |
|
|
} |
297 |
wakaba |
1.1 |
$result .= perl_var (type => '$', |
298 |
wakaba |
1.9 |
local_name => $node->get_attribute_ns (undef, 'obj')). |
299 |
|
|
'->'.$param->[0].' ('. |
300 |
wakaba |
1.3 |
join (', ', |
301 |
|
|
map { |
302 |
wakaba |
1.9 |
to_perl_value ($node->get_attribute_ns (undef, $_), |
303 |
wakaba |
1.3 |
default => 'undef') |
304 |
wakaba |
1.9 |
} @$param[1..$#$param]). |
305 |
wakaba |
1.1 |
");\n"; |
306 |
wakaba |
1.9 |
last MA; |
307 |
|
|
} # M |
308 |
|
|
A: { |
309 |
|
|
if ($node->has_attribute_ns (undef, 'var')) { |
310 |
wakaba |
1.1 |
$result .= perl_var (type => '$', |
311 |
wakaba |
1.9 |
local_name => $node->get_attribute_ns (undef, 'var')). |
312 |
wakaba |
1.1 |
' = '; |
313 |
wakaba |
1.9 |
} elsif ($node->has_attribute_ns (undef, 'value')) { |
314 |
wakaba |
1.3 |
# |
315 |
wakaba |
1.1 |
} else { |
316 |
wakaba |
1.3 |
valid_err q<Unknown operation to an attribute>, node => $node; |
317 |
wakaba |
1.1 |
} |
318 |
wakaba |
1.5 |
my $obj = perl_var (type => '$', |
319 |
wakaba |
1.9 |
local_name => $node->get_attribute_ns (undef, 'obj')); |
320 |
|
|
my $if = $node->get_attribute_ns (undef, 'interface'); |
321 |
wakaba |
1.5 |
if (defined $if and $if eq 'DOMString') { |
322 |
|
|
if ($ln eq 'length') { |
323 |
|
|
$result .= 'length '.$obj; |
324 |
|
|
} else { |
325 |
|
|
valid_err q<$if.$ln not supported>, node => $node; |
326 |
|
|
} |
327 |
|
|
} else { |
328 |
wakaba |
1.9 |
$result .= $obj.'->'.$Attr->{$ln}; |
329 |
wakaba |
1.5 |
} |
330 |
wakaba |
1.9 |
if ($node->has_attribute_ns (undef, 'var')) { |
331 |
wakaba |
1.1 |
$result .= ";\n"; |
332 |
wakaba |
1.9 |
} elsif ($node->has_attribute_ns (undef, 'value')) { |
333 |
|
|
$result .= " (".to_perl_value ($node->get_attribute_ns (undef, 'value')). |
334 |
wakaba |
1.3 |
");\n"; |
335 |
|
|
} |
336 |
wakaba |
1.9 |
} # A |
337 |
|
|
} # MA |
338 |
wakaba |
1.3 |
} elsif ($ln eq 'assertEquals') { |
339 |
wakaba |
1.9 |
my $expected = $node->get_attribute_ns (undef, 'expected'); |
340 |
wakaba |
1.3 |
my $expectedType = $Status->{var}->{$expected}->{type} || ''; |
341 |
|
|
$result .= 'assertEquals'. |
342 |
|
|
({Collection => 'Collection', |
343 |
|
|
List => 'List'}->{$expectedType}||''); |
344 |
wakaba |
1.9 |
my $ignoreCase = $node->get_attribute_ns (undef, 'ignoreCase') || 'false'; |
345 |
wakaba |
1.3 |
if ($ignoreCase eq 'auto') { |
346 |
|
|
$result .= 'AutoCase ('. |
347 |
wakaba |
1.9 |
perl_literal ($node->get_attribute_ns (undef, 'context') || |
348 |
wakaba |
1.3 |
'element'). |
349 |
|
|
', '; |
350 |
|
|
} else { |
351 |
|
|
$result .= ' ('; |
352 |
wakaba |
1.1 |
} |
353 |
wakaba |
1.9 |
$result .= perl_literal ($node->get_attribute_ns (undef, 'id')).', '; |
354 |
wakaba |
1.3 |
$result .= join ", ", map { |
355 |
|
|
$ignoreCase eq 'true' |
356 |
|
|
? ($expectedType eq 'Collection' or |
357 |
|
|
$expectedType eq 'List') |
358 |
|
|
? "toLowerArray ($_)" : "lc ($_)" |
359 |
|
|
: $_ |
360 |
|
|
} map { |
361 |
|
|
to_perl_value ($_) |
362 |
|
|
} ( |
363 |
|
|
$expected, |
364 |
wakaba |
1.9 |
$node->get_attribute_ns (undef, 'actual'), |
365 |
wakaba |
1.3 |
); |
366 |
|
|
$result .= ");\n"; |
367 |
|
|
$Status->{Number}++; |
368 |
wakaba |
1.5 |
} elsif ($ln eq 'assertInstanceOf') { |
369 |
|
|
my $obj = perl_code_literal |
370 |
wakaba |
1.9 |
(to_perl_value ($node->get_attribute_ns (undef, 'obj'))); |
371 |
wakaba |
1.5 |
$result .= perl_statement 'assertInstanceOf ('. |
372 |
|
|
perl_list |
373 |
wakaba |
1.9 |
($node->get_attribute_ns (undef, 'id'), |
374 |
|
|
$node->get_attribute_ns (undef, 'type'), |
375 |
wakaba |
1.5 |
$obj). |
376 |
|
|
')'; |
377 |
wakaba |
1.9 |
if ($node->has_child_nodes) { |
378 |
wakaba |
1.5 |
$result .= perl_if |
379 |
|
|
'isInstanceOf ('. |
380 |
|
|
perl_list |
381 |
wakaba |
1.9 |
($node->get_attribute_ns (undef, 'type'), |
382 |
wakaba |
1.5 |
$obj) . ')', |
383 |
|
|
body2code ($node); |
384 |
|
|
} |
385 |
|
|
$Status->{Number}++; |
386 |
|
|
} elsif ($ln eq 'assertSame') { |
387 |
wakaba |
1.9 |
my $expected = to_perl_value ($node->get_attribute_ns (undef, 'expected')); |
388 |
|
|
my $actual = to_perl_value ($node->get_attribute_ns (undef, 'actual')); |
389 |
wakaba |
1.5 |
$result .= perl_statement 'assertSame ('. |
390 |
|
|
perl_list |
391 |
wakaba |
1.9 |
($node->get_attribute_ns (undef, 'id'), |
392 |
wakaba |
1.5 |
$expected, $actual). |
393 |
|
|
')'; |
394 |
wakaba |
1.9 |
if ($node->has_child_nodes) { |
395 |
wakaba |
1.5 |
$result .= perl_if |
396 |
|
|
'same ('.(perl_list $expected, $actual).')', |
397 |
|
|
body2code ($node); |
398 |
|
|
} |
399 |
|
|
$Status->{Number}++; |
400 |
wakaba |
1.4 |
} elsif ($ln eq 'assertSize') { |
401 |
wakaba |
1.9 |
my $size = to_perl_value ($node->get_attribute_ns (undef, 'size')); |
402 |
|
|
my $coll = to_perl_value ($node->get_attribute_ns (undef, 'collection')); |
403 |
wakaba |
1.4 |
$result .= perl_statement 'assertSize ('. |
404 |
|
|
perl_list |
405 |
wakaba |
1.9 |
($node->get_attribute_ns (undef, 'id'), |
406 |
wakaba |
1.4 |
perl_code_literal $size, perl_code_literal $coll). |
407 |
|
|
')'; |
408 |
wakaba |
1.9 |
if ($node->has_child_nodes) { |
409 |
wakaba |
1.4 |
$result .= perl_if |
410 |
|
|
qq<$size == size ($coll)>, |
411 |
wakaba |
1.5 |
body2code ($node); |
412 |
wakaba |
1.4 |
} |
413 |
wakaba |
1.5 |
$Status->{Number}++; |
414 |
wakaba |
1.3 |
} elsif ($ln eq 'assertTrue' or $ln eq 'assertFalse') { |
415 |
|
|
my $condition; |
416 |
wakaba |
1.9 |
if ($node->has_attribute_ns (undef, 'actual')) { |
417 |
wakaba |
1.3 |
$condition = perl_var (type => '$', |
418 |
wakaba |
1.9 |
local_name => $node->get_attribute_ns |
419 |
wakaba |
1.3 |
(undef, 'actual')); |
420 |
wakaba |
1.9 |
if ($node->has_child_nodes) { |
421 |
wakaba |
1.1 |
valid_err q<Child of $ln found but not supported>, |
422 |
|
|
node => $node; |
423 |
|
|
} |
424 |
wakaba |
1.9 |
} elsif ($node->has_child_nodes) { |
425 |
wakaba |
1.3 |
$condition = condition2code ($node); |
426 |
wakaba |
1.1 |
} else { |
427 |
wakaba |
1.3 |
valid_err $ln.q< w/o @actual not supported>, node => $node; |
428 |
wakaba |
1.1 |
} |
429 |
wakaba |
1.3 |
$result .= perl_statement $ln . ' ('. |
430 |
wakaba |
1.9 |
perl_literal ($node->get_attribute_ns (undef, 'id')).', '. |
431 |
wakaba |
1.3 |
$condition. ')'; |
432 |
|
|
$Status->{Number}++; |
433 |
wakaba |
1.5 |
} elsif ($ln eq 'assertNotNull' or $ln eq 'assertNull') { |
434 |
|
|
$result .= perl_statement $ln . ' (' . |
435 |
wakaba |
1.9 |
perl_literal ($node->get_attribute_ns (undef, 'id')).', '. |
436 |
wakaba |
1.1 |
perl_var (type => '$', |
437 |
wakaba |
1.9 |
local_name => $node->get_attribute_ns (undef, 'actual')). |
438 |
wakaba |
1.1 |
')'; |
439 |
wakaba |
1.9 |
if ($node->has_child_nodes) { |
440 |
wakaba |
1.5 |
valid_err q<Child of $ln found but not supported>, |
441 |
wakaba |
1.1 |
node => $node; |
442 |
wakaba |
1.5 |
} |
443 |
|
|
$Status->{Number}++; |
444 |
|
|
} elsif ($ln eq 'assertURIEquals') { |
445 |
|
|
$result .= perl_statement 'assertURIEquals ('. |
446 |
|
|
perl_list |
447 |
wakaba |
1.9 |
($node->get_attribute_ns (undef, 'id'), |
448 |
wakaba |
1.5 |
perl_code_literal |
449 |
wakaba |
1.9 |
(to_perl_value ($node->get_attribute_ns (undef, 'scheme'), |
450 |
wakaba |
1.5 |
default => 'undef')), |
451 |
|
|
perl_code_literal |
452 |
wakaba |
1.9 |
(to_perl_value ($node->get_attribute_ns (undef, 'path'), |
453 |
wakaba |
1.5 |
default => 'undef')), |
454 |
|
|
perl_code_literal |
455 |
wakaba |
1.9 |
(to_perl_value ($node->get_attribute_ns (undef, 'host'), |
456 |
wakaba |
1.5 |
default => 'undef')), |
457 |
|
|
perl_code_literal |
458 |
wakaba |
1.9 |
(to_perl_value ($node->get_attribute_ns (undef, 'file'), |
459 |
wakaba |
1.5 |
default => 'undef')), |
460 |
|
|
perl_code_literal |
461 |
wakaba |
1.9 |
(to_perl_value ($node->get_attribute_ns (undef, 'name'), |
462 |
wakaba |
1.5 |
default => 'undef')), |
463 |
|
|
perl_code_literal |
464 |
wakaba |
1.9 |
(to_perl_value ($node->get_attribute_ns (undef, 'query'), |
465 |
wakaba |
1.5 |
default => 'undef')), |
466 |
|
|
perl_code_literal |
467 |
wakaba |
1.9 |
(to_perl_value ($node->get_attribute_ns (undef, 'fragment'), |
468 |
wakaba |
1.5 |
default => 'undef')), |
469 |
|
|
perl_code_literal |
470 |
wakaba |
1.9 |
(to_perl_value ($node->get_attribute_ns (undef, 'isAbsolute'), |
471 |
wakaba |
1.5 |
default => 'undef')), |
472 |
|
|
perl_code_literal |
473 |
wakaba |
1.9 |
(to_perl_value ($node->get_attribute_ns (undef, 'actual')))). |
474 |
wakaba |
1.5 |
')'; |
475 |
wakaba |
1.3 |
$Status->{Number}++; |
476 |
wakaba |
1.1 |
} elsif ($ln eq 'assertDOMException') { |
477 |
|
|
$Status->{use}->{'Message::Util::Error'} = 1; |
478 |
|
|
$result .= q[ |
479 |
|
|
{ |
480 |
|
|
my $success = 0; |
481 |
|
|
try { |
482 |
|
|
]; |
483 |
wakaba |
1.9 |
my $children = $node->child_nodes; |
484 |
wakaba |
1.1 |
my $errname; |
485 |
|
|
for (my $i = 0; $i < $children->length; $i++) { |
486 |
|
|
my $child = $children->item ($i); |
487 |
wakaba |
1.9 |
$errname = $child->local_name if $child->node_type == $child->ELEMENT_NODE; |
488 |
wakaba |
1.1 |
$result .= body2code ($child); |
489 |
|
|
} |
490 |
|
|
$result .= q[ |
491 |
wakaba |
1.7 |
} catch Message::DOM::IF::DOMException with { |
492 |
wakaba |
1.1 |
my $err = shift; |
493 |
|
|
$success = 1 if $err->{-type} eq ].perl_literal ($errname).q[; |
494 |
wakaba |
1.5 |
}; |
495 |
wakaba |
1.9 |
assertTrue (].perl_literal ($node->get_attribute_ns (undef, 'id')). |
496 |
wakaba |
1.1 |
q[, $success); |
497 |
|
|
} |
498 |
|
|
]; |
499 |
wakaba |
1.3 |
$Status->{Number}++; |
500 |
|
|
} elsif ($ln eq 'contentType') { |
501 |
|
|
$result .= '$builder->{contentType} eq '. |
502 |
wakaba |
1.9 |
perl_literal ($node->get_attribute_ns (undef, 'type')); |
503 |
wakaba |
1.3 |
$Status->{our}->{builder} = 1; |
504 |
wakaba |
1.5 |
} elsif ($ln eq 'for-each') { |
505 |
wakaba |
1.9 |
my $collection = $node->get_attribute_ns (undef, 'collection'); |
506 |
wakaba |
1.5 |
my $collType = $Status->{var}->{$collection}->{type}; |
507 |
|
|
my $coll = to_perl_value ($collection); |
508 |
wakaba |
1.8 |
my $assert; |
509 |
|
|
my $code; |
510 |
|
|
{ |
511 |
|
|
local $Status->{Number} = 0; |
512 |
|
|
$code = body2code ($node); |
513 |
|
|
$assert = $Status->{Number}; |
514 |
|
|
} |
515 |
|
|
$Status->{Number_local} = 1; |
516 |
wakaba |
1.5 |
$result .= 'for (my $i = 0; $i < '. |
517 |
|
|
({'Collection'=>1,'List'=>1}->{$collType} |
518 |
|
|
? '@{'.$coll.'}' : $coll.'->length'). |
519 |
|
|
'; $i++) {'. |
520 |
wakaba |
1.8 |
perl_statement (qq<plan_local ($assert)>). |
521 |
wakaba |
1.5 |
perl_statement |
522 |
|
|
(perl_assign |
523 |
wakaba |
1.9 |
to_perl_value ($node->get_attribute_ns (undef, 'member')) |
524 |
wakaba |
1.5 |
=> $coll . ({'Collection'=>1,'List'=>1}->{$collType} |
525 |
|
|
? '->[$i]' : '->item ($i)')). |
526 |
wakaba |
1.8 |
$code. |
527 |
wakaba |
1.5 |
'}'; |
528 |
|
|
} elsif ($ln eq 'try') { |
529 |
wakaba |
1.9 |
my $children = $node->child_nodes; |
530 |
wakaba |
1.5 |
my $true = ''; |
531 |
|
|
my $false = ''; |
532 |
|
|
for (my $i = 0; $i < $children->length; $i++) { |
533 |
|
|
my $child = $children->item ($i); |
534 |
wakaba |
1.9 |
if ($child->node_type == $child->ELEMENT_NODE) { |
535 |
|
|
if ($child->local_name eq 'catch') { |
536 |
wakaba |
1.5 |
valid_err q<Multiple 'catch'es found>, node => $child |
537 |
|
|
if $false; |
538 |
|
|
my @case; |
539 |
wakaba |
1.9 |
my $children2 = $child->child_nodes; |
540 |
wakaba |
1.5 |
for (my $j = 0; $j < $children2->length; $j++) { |
541 |
|
|
my $child2 = $children2->item ($j); |
542 |
wakaba |
1.9 |
if ($child2->node_type == $child2->ELEMENT_NODE) { |
543 |
|
|
if ($child2->local_name eq 'ImplementationException') { |
544 |
wakaba |
1.5 |
valid_err q<Element type not supported>, node => $child2; |
545 |
|
|
} else { |
546 |
|
|
push @case, '$err->{-type} eq '. |
547 |
wakaba |
1.9 |
perl_literal ($child2->get_attribute_ns (undef, 'code')) |
548 |
wakaba |
1.5 |
=> body2code ($child2); |
549 |
|
|
} |
550 |
|
|
} else { |
551 |
|
|
$false .= node2code ($child2); |
552 |
|
|
} |
553 |
|
|
} |
554 |
|
|
$false .= perl_cases @case, else => perl_statement '$err->throw'; |
555 |
|
|
} else { |
556 |
|
|
$true .= node2code ($child); |
557 |
|
|
} |
558 |
|
|
} else { |
559 |
|
|
$true .= node2code ($child); |
560 |
|
|
} |
561 |
|
|
} |
562 |
|
|
$result = "try { |
563 |
|
|
$true |
564 |
wakaba |
1.7 |
} catch Message::DOM::DOMMain::ManakaiDOMException with { |
565 |
wakaba |
1.5 |
my \$err = shift; |
566 |
|
|
$false |
567 |
|
|
};"; |
568 |
|
|
$Status->{use}->{'Message::Util::Error'} = 1; |
569 |
wakaba |
1.3 |
} elsif ($ln eq 'if') { |
570 |
wakaba |
1.9 |
my $children = $node->child_nodes; |
571 |
wakaba |
1.3 |
my $condition; |
572 |
|
|
my $true = ''; |
573 |
wakaba |
1.5 |
my $false = ''; |
574 |
|
|
my $assert_true = 0; |
575 |
|
|
my $assert_false = 0; |
576 |
wakaba |
1.3 |
for (my $i = 0; $i < $children->length; $i++) { |
577 |
|
|
my $child = $children->item ($i); |
578 |
wakaba |
1.9 |
if ($child->node_type == $child->ELEMENT_NODE) { |
579 |
wakaba |
1.3 |
if (not $condition) { |
580 |
|
|
$condition = node2code ($child); |
581 |
wakaba |
1.9 |
} elsif ($child->local_name eq 'else') { |
582 |
wakaba |
1.3 |
valid_err q<Multiple 'else's found>, node => $child |
583 |
wakaba |
1.5 |
if $false; |
584 |
|
|
local $Status->{Number} = 0; |
585 |
|
|
$false = body2code ($child); |
586 |
|
|
$assert_false = $Status->{Number}; |
587 |
wakaba |
1.3 |
} else { |
588 |
wakaba |
1.5 |
local $Status->{Number} = 0; |
589 |
|
|
$true .= node2code ($child); |
590 |
|
|
$assert_true += $Status->{Number}; |
591 |
wakaba |
1.3 |
} |
592 |
|
|
} else { |
593 |
wakaba |
1.5 |
$true .= node2code ($child); |
594 |
wakaba |
1.3 |
} |
595 |
|
|
} |
596 |
wakaba |
1.5 |
if ($assert_true == $assert_false) { |
597 |
|
|
$Status->{Number} += $assert_true; |
598 |
|
|
} elsif ($assert_true > $assert_false) { |
599 |
wakaba |
1.8 |
$false .= perl_statement 'skip_n ('. |
600 |
|
|
perl_list ($assert_true - $assert_false, |
601 |
|
|
msg => q<Conditional>).')'; |
602 |
wakaba |
1.5 |
$Status->{Number} += $assert_true; |
603 |
|
|
} else { |
604 |
wakaba |
1.8 |
$true .= perl_statement 'skip_n ('. |
605 |
|
|
perl_list ($assert_false - $assert_true, |
606 |
|
|
msg => q<Conditional>).')'; |
607 |
wakaba |
1.5 |
$Status->{Number} += $assert_false; |
608 |
|
|
} |
609 |
wakaba |
1.3 |
$result = perl_if |
610 |
|
|
$condition, |
611 |
wakaba |
1.5 |
$true, |
612 |
|
|
$false ? $false : undef; |
613 |
|
|
} elsif ($ln eq 'while') { |
614 |
wakaba |
1.9 |
my $children = $node->child_nodes; |
615 |
wakaba |
1.5 |
my $condition; |
616 |
|
|
my $true = ''; |
617 |
|
|
my $assert = 0; |
618 |
|
|
{ |
619 |
|
|
local $Status->{Number} = 0; |
620 |
|
|
for (my $i = 0; $i < $children->length; $i++) { |
621 |
|
|
my $child = $children->item ($i); |
622 |
wakaba |
1.9 |
if ($child->node_type == $child->ELEMENT_NODE) { |
623 |
wakaba |
1.5 |
if (not $condition) { |
624 |
|
|
$condition = node2code ($child); |
625 |
|
|
} else { |
626 |
|
|
$true .= node2code ($child); |
627 |
|
|
} |
628 |
|
|
} else { |
629 |
|
|
$true .= node2code ($child); |
630 |
|
|
} |
631 |
|
|
} |
632 |
|
|
$assert = $Status->{Number}; |
633 |
|
|
} |
634 |
wakaba |
1.8 |
$Status->{Number_local} = 1; |
635 |
wakaba |
1.5 |
$result .= "while ($condition) { |
636 |
wakaba |
1.8 |
plan_local ($assert); |
637 |
wakaba |
1.5 |
$true |
638 |
|
|
}"; |
639 |
wakaba |
1.3 |
} elsif ($ln eq 'or') { |
640 |
|
|
$result .= condition2code ($node, join => 'or'); |
641 |
|
|
} elsif ($ln eq 'not') { |
642 |
|
|
$result .= 'not '.condition2code ($node, join => 'nosupport'); |
643 |
wakaba |
1.5 |
} elsif ($ln eq 'notNull' or $ln eq 'isNull') { |
644 |
wakaba |
1.3 |
$result .= 'defined '. |
645 |
|
|
perl_var (type => '$', |
646 |
wakaba |
1.9 |
local_name => $node->get_attribute_ns (undef, 'obj')); |
647 |
wakaba |
1.5 |
$result = 'not ' . $result if $ln eq 'isNull'; |
648 |
|
|
} elsif ({less => 1, lessOrEquals => 1, |
649 |
|
|
greater => 1, greaterOrEquals => 1}->{$ln}) { |
650 |
wakaba |
1.9 |
$result .= to_perl_value ($node->get_attribute_ns (undef, 'actual')). |
651 |
wakaba |
1.5 |
{less => '<', lessOrEquals => '<=', |
652 |
|
|
greater => '>', greaterOrEquals => '>='}->{$ln}. |
653 |
wakaba |
1.9 |
to_perl_value ($node->get_attribute_ns (undef, 'expected')); |
654 |
wakaba |
1.5 |
} elsif ($ln eq 'equals' or $ln eq 'notEquals') { |
655 |
wakaba |
1.9 |
my $case = $node->get_attribute_ns (undef, 'ignoreCase'); |
656 |
wakaba |
1.5 |
if ($case and $case eq 'auto') { |
657 |
|
|
$result .= 'equalsAutoCase (' . |
658 |
|
|
perl_list |
659 |
wakaba |
1.9 |
($node->get_attribute_ns (undef, 'context') || 'element', |
660 |
wakaba |
1.5 |
to_perl_value |
661 |
wakaba |
1.9 |
($node->get_attribute_ns (undef, 'expected')), |
662 |
wakaba |
1.5 |
to_perl_value |
663 |
wakaba |
1.9 |
($node->get_attribute_ns (undef, 'actual'))) . ')'; |
664 |
wakaba |
1.5 |
} else { |
665 |
|
|
my $expected = to_perl_value |
666 |
wakaba |
1.9 |
($node->get_attribute_ns (undef, 'expected')); |
667 |
wakaba |
1.5 |
my $actual = to_perl_value |
668 |
wakaba |
1.9 |
($node->get_attribute_ns (undef, 'actual')); |
669 |
wakaba |
1.5 |
if ($case eq 'true') { |
670 |
|
|
$result = "(uc ($expected) eq uc ($actual))"; |
671 |
wakaba |
1.9 |
} elsif ($node->has_attribute_ns (undef, 'bitmask')) { |
672 |
wakaba |
1.5 |
my $bm = ' & ' . to_perl_value |
673 |
wakaba |
1.9 |
($node->get_attribute_ns (undef, 'bitmask')); |
674 |
wakaba |
1.5 |
$result = "($expected$bm == $actual$bm)"; |
675 |
|
|
} else { |
676 |
|
|
$result = "($expected eq $actual)"; |
677 |
|
|
} |
678 |
|
|
} |
679 |
|
|
$result = "(not $result)" if $ln eq 'notEquals'; |
680 |
|
|
} elsif ($ln eq 'increment' or $ln eq 'decrement') { |
681 |
|
|
$result .= perl_statement |
682 |
wakaba |
1.9 |
to_perl_value ($node->get_attribute_ns (undef, 'var')). |
683 |
wakaba |
1.5 |
{increment => ' += ', decrement => ' -= '}->{$ln}. |
684 |
wakaba |
1.9 |
to_perl_value ($node->get_attribute_ns (undef, 'value')); |
685 |
wakaba |
1.5 |
} elsif ({qw/plus 1 subtract 1 mult 1 divide 1/}->{$ln}) { |
686 |
|
|
$result .= perl_statement |
687 |
|
|
(perl_assign |
688 |
wakaba |
1.9 |
to_perl_value ($node->get_attribute_ns (undef, 'var')) |
689 |
|
|
=> to_perl_value ($node->get_attribute_ns (undef, 'op1')). |
690 |
wakaba |
1.5 |
{qw<plus + subtract - mult * divide />}->{$ln}. |
691 |
wakaba |
1.9 |
to_perl_value ($node->get_attribute_ns (undef, 'op2'))); |
692 |
wakaba |
1.5 |
} elsif ($ln eq 'append') { |
693 |
|
|
$result .= perl_statement |
694 |
|
|
'push @{'. |
695 |
wakaba |
1.9 |
to_perl_value ($node->get_attribute_ns (undef, 'collection')). |
696 |
wakaba |
1.5 |
'}, '. |
697 |
wakaba |
1.9 |
to_perl_value ($node->get_attribute_ns (undef, 'item')); |
698 |
wakaba |
1.5 |
} elsif ($ln eq 'instanceOf') { |
699 |
|
|
$result .= 'isInstanceOf ('. |
700 |
wakaba |
1.9 |
perl_list ($node->get_attribute_ns (undef, 'type'), |
701 |
wakaba |
1.5 |
perl_code_literal to_perl_value |
702 |
wakaba |
1.9 |
($node->get_attribute_ns (undef, 'obj'))). |
703 |
wakaba |
1.5 |
')'; |
704 |
|
|
} elsif ($ln eq 'assign') { |
705 |
|
|
$result .= perl_statement |
706 |
|
|
perl_assign |
707 |
wakaba |
1.9 |
to_perl_value ($node->get_attribute_ns (undef, 'var')) |
708 |
|
|
=> to_perl_value ($node->get_attribute_ns (undef, 'value')); |
709 |
wakaba |
1.5 |
} elsif ($ln eq 'fail') { |
710 |
|
|
$result .= perl_statement 'fail ('. |
711 |
wakaba |
1.9 |
perl_literal ($node->get_attribute_ns (undef, 'id')). ')'; |
712 |
wakaba |
1.1 |
} else { |
713 |
|
|
valid_err q<Unknown element type: >.$ln; |
714 |
|
|
} |
715 |
|
|
$result; |
716 |
|
|
} |
717 |
|
|
|
718 |
wakaba |
1.3 |
our $result = ''; |
719 |
|
|
|
720 |
wakaba |
1.9 |
my $input = ''; |
721 |
wakaba |
1.1 |
{ |
722 |
wakaba |
1.9 |
open my $in, '<', $Opt{file_name} or die "$0: $Opt{file_name}: $!"; |
723 |
|
|
while (<$in>) { |
724 |
|
|
$input .= $_; |
725 |
|
|
} |
726 |
wakaba |
1.1 |
} |
727 |
|
|
|
728 |
wakaba |
1.3 |
{ |
729 |
wakaba |
1.9 |
my $dom = $Message::DOM::ImplementationRegistry |
730 |
|
|
->get_implementation |
731 |
|
|
({Core => undef, |
732 |
|
|
XML => undef, |
733 |
|
|
ExpandedURI q<ManakaiDOMLS2003:LS> => ''}); |
734 |
|
|
|
735 |
|
|
my $parser = $dom->create_ls_parser (MODE_SYNCHRONOUS); |
736 |
|
|
my $in = $dom->create_ls_input; |
737 |
|
|
$in->string_data ($input); |
738 |
|
|
|
739 |
|
|
status_msg_ q<Parsing XML entity...>; |
740 |
|
|
my $src = $parser->parse ($in)->document_element; |
741 |
|
|
status_msg q<done>; |
742 |
|
|
|
743 |
|
|
status_msg_ q<Generating test script...>; |
744 |
|
|
{ |
745 |
|
|
my $children = $src->owner_document->child_nodes; |
746 |
|
|
for (my $i = 0; $i < $children->length; $i++) { |
747 |
|
|
my $node = $children->item ($i); |
748 |
|
|
if ($node->node_type == $node->COMMENT_NODE) { |
749 |
|
|
if ($node->data =~ /Copyright/) { |
750 |
|
|
$result .= perl_comment |
751 |
|
|
qq<This script was generated by "$0"\n>. |
752 |
|
|
qq<and is a derived work from the source document\n>. |
753 |
|
|
qq<"$Opt{file_name}".\n>. |
754 |
|
|
qq<The source document contained the following notice:\n>. |
755 |
|
|
$node->data; |
756 |
|
|
} else { |
757 |
|
|
$result .= perl_comment $node->data; |
758 |
|
|
} |
759 |
|
|
} |
760 |
wakaba |
1.1 |
} |
761 |
|
|
} |
762 |
wakaba |
1.9 |
|
763 |
|
|
my $child = $src->child_nodes; |
764 |
wakaba |
1.1 |
|
765 |
|
|
for (my $i = 0; $i < $child->length; $i++) { |
766 |
|
|
my $node = $child->item ($i); |
767 |
wakaba |
1.9 |
if ($node->node_type == $node->ELEMENT_NODE) { |
768 |
|
|
my $ln = $node->local_name; |
769 |
wakaba |
1.1 |
if ($ln eq 'metadata') { |
770 |
wakaba |
1.9 |
my $md = $node->child_nodes; |
771 |
wakaba |
1.1 |
for (my $j = 0; $j < $md->length; $j++) { |
772 |
|
|
my $node = $md->item ($j); |
773 |
wakaba |
1.9 |
if ($node->node_type == $node->ELEMENT_NODE) { |
774 |
|
|
my $ln = $node->local_name; |
775 |
wakaba |
1.3 |
if ($ln eq 'title') { |
776 |
|
|
$result .= perl_statement |
777 |
|
|
perl_assign |
778 |
|
|
'$Info->{Name}' |
779 |
wakaba |
1.9 |
=> perl_literal $node->text_content; |
780 |
wakaba |
1.3 |
} elsif ($ln eq 'description') { |
781 |
|
|
$result .= perl_statement |
782 |
|
|
perl_assign |
783 |
|
|
'$Info->{Description}' |
784 |
wakaba |
1.9 |
=> perl_literal $node->text_content; |
785 |
wakaba |
1.1 |
} else { |
786 |
|
|
# valid_err q<Unknown element type: >.$ln, |
787 |
|
|
# node => $node; |
788 |
|
|
} |
789 |
wakaba |
1.9 |
} elsif ($node->node_type == $node->TEXT_NODE) { |
790 |
wakaba |
1.1 |
if ($node->data =~ /\S/) { |
791 |
|
|
valid_err q<Unknown character data: >.$node->data, |
792 |
|
|
node => $node; |
793 |
|
|
} |
794 |
wakaba |
1.9 |
} elsif ($node->node_type == $node->COMMENT_NODE) { |
795 |
wakaba |
1.1 |
$result .= perl_comment $node->data; |
796 |
|
|
} else { |
797 |
wakaba |
1.9 |
valid_err q<Unknown node type: >.$node->node_type, |
798 |
wakaba |
1.1 |
node => $node; |
799 |
|
|
} |
800 |
|
|
} |
801 |
wakaba |
1.3 |
} elsif ($ln eq 'implementationAttribute') { |
802 |
wakaba |
1.7 |
$result .= perl_statement 'impl_attr ('. |
803 |
|
|
perl_list |
804 |
wakaba |
1.9 |
($node->get_attribute_ns (undef, 'name'), |
805 |
|
|
$node->get_attribute_ns (undef, 'value')).')'; |
806 |
wakaba |
1.1 |
} else { |
807 |
|
|
$result .= node2code ($node); |
808 |
|
|
} |
809 |
wakaba |
1.9 |
} elsif ($node->node_type == $node->COMMENT_NODE) { |
810 |
wakaba |
1.1 |
$result .= perl_comment $node->data; |
811 |
wakaba |
1.9 |
} elsif ($node->node_type == $node->TEXT_NODE) { |
812 |
wakaba |
1.1 |
if ($node->data =~ /\S/) { |
813 |
|
|
valid_err q<Unknown character data: >.$node->data, |
814 |
|
|
node => $node; |
815 |
|
|
} |
816 |
|
|
} else { |
817 |
wakaba |
1.9 |
valid_err q<Unknown type of node: >.$node->node_type, |
818 |
wakaba |
1.1 |
node => $node; |
819 |
|
|
} |
820 |
|
|
} |
821 |
wakaba |
1.3 |
} |
822 |
|
|
|
823 |
|
|
my $pre = "#!/usr/bin/perl -w\nuse strict;\n"; |
824 |
|
|
$pre .= perl_statement ('require '.perl_literal 'manakai/domtest.pl'); |
825 |
|
|
$pre .= perl_statement |
826 |
|
|
('use Message::Util::Error') |
827 |
|
|
if $Status->{use}->{'Message::Util::Error'}; |
828 |
|
|
for (keys %{$Status->{our}}) { |
829 |
|
|
$pre .= perl_statement perl_var type => '$', local_name => $_, |
830 |
|
|
scope => 'our'; |
831 |
|
|
} |
832 |
wakaba |
1.8 |
my $plan = $Status->{Number_local} ? 'plan_local' : 'plan'; |
833 |
|
|
$pre .= perl_statement qq<$plan (>.(0+$Status->{Number}).q<)>; |
834 |
|
|
|
835 |
|
|
$result .= perl_statement q<end_of_test ()>; |
836 |
wakaba |
1.9 |
status_msg q<done>; |
837 |
wakaba |
1.1 |
|
838 |
wakaba |
1.9 |
{ |
839 |
|
|
my $output; |
840 |
|
|
my $out_file_path = $Opt{output_file_name}; |
841 |
|
|
defined $out_file_path |
842 |
|
|
? (open $output, '>', $out_file_path or die "$0: $out_file_path: $!") |
843 |
|
|
: ($output = \*STDOUT); |
844 |
|
|
|
845 |
|
|
status_msg_ sprintf qq<Writing Perl script %s...>, |
846 |
|
|
defined $out_file_path |
847 |
|
|
? q<">.$out_file_path.q<"> |
848 |
|
|
: 'to stdout'; |
849 |
|
|
print $output $pre.$result; |
850 |
|
|
close $output; |
851 |
|
|
status_msg q<done>; |
852 |
|
|
} |
853 |
wakaba |
1.7 |
|
854 |
|
|
1; |
855 |
|
|
|
856 |
|
|
__END__ |
857 |
|
|
|
858 |
|
|
=head1 NAME |
859 |
|
|
|
860 |
|
|
domtest2perl - DOM Test Suite XML Test File to Perl Test Code Converter |
861 |
|
|
|
862 |
|
|
=head1 SYNOPSIS |
863 |
|
|
|
864 |
|
|
perl path/to/domtest2perl.pl input.xml > output.pl |
865 |
|
|
perl path/to/domtest2perl.pl input.xml --output-file=output.pl |
866 |
|
|
|
867 |
|
|
=over 4 |
868 |
|
|
|
869 |
|
|
=item I<input.xml> |
870 |
|
|
|
871 |
|
|
The name of file to input. It should be an XML document |
872 |
|
|
in the DOM Test Suite. |
873 |
|
|
|
874 |
|
|
=item I<output.pl> |
875 |
|
|
|
876 |
|
|
The name of file to output. It is overwritten if already exists. |
877 |
|
|
|
878 |
|
|
=back |
879 |
|
|
|
880 |
|
|
=head1 SEE ALSO |
881 |
|
|
|
882 |
|
|
I<Document Object Model (DOM) Conformance Test Suites>, |
883 |
|
|
<http://www.w3.org/DOM/Test/>. |
884 |
|
|
|
885 |
|
|
F<domts2perl.pl> |
886 |
|
|
|
887 |
|
|
F<mkdommemlist.pl> |
888 |
|
|
|
889 |
|
|
=head1 LICENSE |
890 |
|
|
|
891 |
|
|
Copyright 2004-2005 Wakaba <w@suika.fam.cx>. All rights reserved. |
892 |
|
|
|
893 |
|
|
This program is free software; you can redistribute it and/or |
894 |
|
|
modify it under the same terms as Perl itself. |
895 |
|
|
|
896 |
|
|
=cut |
897 |
wakaba |
1.1 |
|