13 |
require 'dommemlist.pl.tmp'; ## Generated by mkdommemlist.pl |
require 'dommemlist.pl.tmp'; ## Generated by mkdommemlist.pl |
14 |
|
|
15 |
my $output_filename; |
my $output_filename; |
|
my $output_file; |
|
16 |
GetOptions ( |
GetOptions ( |
17 |
'output-file=s' => \$output_filename, |
'output-file=s' => \$output_filename, |
18 |
); |
); |
19 |
|
|
20 |
if (defined $output_filename) { |
if (defined $output_filename) { |
21 |
open $output_file, '>', $output_filename or die "$0: $output_filename: $!"; |
open my $f, '>', $output_filename or die "$0: $output_filename: $!"; |
22 |
|
our $ResultOutput = $f; |
23 |
} else { |
} else { |
24 |
$output_file = \*STDOUT; |
our $ResultOutput = \*STDOUT; |
25 |
} |
} |
26 |
|
|
27 |
our $Method; |
our $Method; |
73 |
|
|
74 |
my $Status = {Number => 0, our => {Info => 1}}; |
my $Status = {Number => 0, our => {Info => 1}}; |
75 |
|
|
|
## Defined in genlib.pl but redefined. |
|
|
sub output_result ($) { |
|
|
print $output_file shift; |
|
|
} |
|
|
|
|
76 |
sub to_perl_value ($;%) { |
sub to_perl_value ($;%) { |
77 |
my ($s, %opt) = @_; |
my ($s, %opt) = @_; |
78 |
if (defined $s) { |
if (defined $s) { |
232 |
=> 'load (' . |
=> 'load (' . |
233 |
perl_literal ($node->getAttributeNS (undef, 'href')). |
perl_literal ($node->getAttributeNS (undef, 'href')). |
234 |
')'; |
')'; |
235 |
} elsif ($Method->{$ln}) { |
} elsif ($ln eq 'hasFeature' and |
236 |
|
not $node->hasAttributeNS (undef, 'var')) { |
237 |
|
## If there is a "hasFeature" element in "body" and |
238 |
|
## it does not have "var" attribute, then it is part of the |
239 |
|
## implementation condition. |
240 |
|
$result .= perl_statement 'hasFeature ('. |
241 |
|
to_perl_value ($node->getAttributeNS (undef, 'feature'), |
242 |
|
default => 'undef') . ', '. |
243 |
|
to_perl_value ($node->getAttributeNS (undef, 'version'), |
244 |
|
default => 'undef') . ')'; |
245 |
|
} elsif ($Method->{$ln}) { |
246 |
$result .= perl_var (type => '$', |
$result .= perl_var (type => '$', |
247 |
local_name => $node->getAttributeNS (undef, 'var')). |
local_name => $node->getAttributeNS (undef, 'var')). |
248 |
' = ' |
' = ' |
453 |
$result .= body2code ($child); |
$result .= body2code ($child); |
454 |
} |
} |
455 |
$result .= q[ |
$result .= q[ |
456 |
} catch Message::DOM::DOMException with { |
} catch Message::DOM::IF::DOMException with { |
457 |
my $err = shift; |
my $err = shift; |
458 |
$success = 1 if $err->{-type} eq ].perl_literal ($errname).q[; |
$success = 1 if $err->{-type} eq ].perl_literal ($errname).q[; |
459 |
}; |
}; |
470 |
my $collection = $node->getAttributeNS (undef, 'collection'); |
my $collection = $node->getAttributeNS (undef, 'collection'); |
471 |
my $collType = $Status->{var}->{$collection}->{type}; |
my $collType = $Status->{var}->{$collection}->{type}; |
472 |
my $coll = to_perl_value ($collection); |
my $coll = to_perl_value ($collection); |
473 |
|
my $assert; |
474 |
|
my $code; |
475 |
|
{ |
476 |
|
local $Status->{Number} = 0; |
477 |
|
$code = body2code ($node); |
478 |
|
$assert = $Status->{Number}; |
479 |
|
} |
480 |
|
$Status->{Number_local} = 1; |
481 |
$result .= 'for (my $i = 0; $i < '. |
$result .= 'for (my $i = 0; $i < '. |
482 |
({'Collection'=>1,'List'=>1}->{$collType} |
({'Collection'=>1,'List'=>1}->{$collType} |
483 |
? '@{'.$coll.'}' : $coll.'->length'). |
? '@{'.$coll.'}' : $coll.'->length'). |
484 |
'; $i++) {'. |
'; $i++) {'. |
485 |
|
perl_statement (qq<plan_local ($assert)>). |
486 |
perl_statement |
perl_statement |
487 |
(perl_assign |
(perl_assign |
488 |
to_perl_value ($node->getAttributeNS (undef, 'member')) |
to_perl_value ($node->getAttributeNS (undef, 'member')) |
489 |
=> $coll . ({'Collection'=>1,'List'=>1}->{$collType} |
=> $coll . ({'Collection'=>1,'List'=>1}->{$collType} |
490 |
? '->[$i]' : '->item ($i)')). |
? '->[$i]' : '->item ($i)')). |
491 |
body2code ($node). |
$code. |
492 |
'}'; |
'}'; |
493 |
} elsif ($ln eq 'try') { |
} elsif ($ln eq 'try') { |
494 |
my $children = $node->childNodes; |
my $children = $node->childNodes; |
526 |
} |
} |
527 |
$result = "try { |
$result = "try { |
528 |
$true |
$true |
529 |
} catch Message::DOM::ManakaiDOMException with { |
} catch Message::DOM::DOMMain::ManakaiDOMException with { |
530 |
my \$err = shift; |
my \$err = shift; |
531 |
$false |
$false |
532 |
};"; |
};"; |
561 |
if ($assert_true == $assert_false) { |
if ($assert_true == $assert_false) { |
562 |
$Status->{Number} += $assert_true; |
$Status->{Number} += $assert_true; |
563 |
} elsif ($assert_true > $assert_false) { |
} elsif ($assert_true > $assert_false) { |
564 |
$false .= perl_statement ('is_ok ()') x ($assert_true - $assert_false); |
$false .= perl_statement 'skip_n ('. |
565 |
|
perl_list ($assert_true - $assert_false, |
566 |
|
msg => q<Conditional>).')'; |
567 |
$Status->{Number} += $assert_true; |
$Status->{Number} += $assert_true; |
568 |
} else { |
} else { |
569 |
$true .= perl_statement ('is_ok ()') x ($assert_false - $assert_true); |
$true .= perl_statement 'skip_n ('. |
570 |
|
perl_list ($assert_false - $assert_true, |
571 |
|
msg => q<Conditional>).')'; |
572 |
$Status->{Number} += $assert_false; |
$Status->{Number} += $assert_false; |
573 |
} |
} |
574 |
$result = perl_if |
$result = perl_if |
596 |
} |
} |
597 |
$assert = $Status->{Number}; |
$assert = $Status->{Number}; |
598 |
} |
} |
599 |
$Status->{Number} += $assert; |
$Status->{Number_local} = 1; |
600 |
$result .= "while ($condition) { |
$result .= "while ($condition) { |
601 |
|
plan_local ($assert); |
602 |
$true |
$true |
603 |
}"; |
}"; |
604 |
} elsif ($ln eq 'or') { |
} elsif ($ln eq 'or') { |
682 |
|
|
683 |
our $result = ''; |
our $result = ''; |
684 |
|
|
685 |
|
my $input_filename; |
686 |
my $input; |
my $input; |
687 |
{ |
{ |
688 |
local $/ = undef; |
local $/ = undef; |
689 |
$input = <>; |
$input = <>; |
690 |
|
$input_filename = $ARGV; |
691 |
} |
} |
692 |
|
|
693 |
{ |
{ |
711 |
if ($node->data =~ /Copyright/) { |
if ($node->data =~ /Copyright/) { |
712 |
$result .= perl_comment |
$result .= perl_comment |
713 |
qq<This script was generated by "$0"\n>. |
qq<This script was generated by "$0"\n>. |
714 |
qq<and is a derived work from the source document.\n>. |
qq<and is a derived work from the source document\n>. |
715 |
|
qq<"$input_filename".\n>. |
716 |
qq<The source document contained the following notice:\n>. |
qq<The source document contained the following notice:\n>. |
717 |
$node->data; |
$node->data; |
718 |
} else { |
} else { |
761 |
} |
} |
762 |
} |
} |
763 |
} elsif ($ln eq 'implementationAttribute') { |
} elsif ($ln eq 'implementationAttribute') { |
764 |
$result .= perl_comment |
$result .= perl_statement 'impl_attr ('. |
765 |
sprintf 'Implementation attribute: @name=%s, @value=%s', |
perl_list |
766 |
$node->getAttributeNS (undef, 'name'), |
($node->getAttributeNS (undef, 'name'), |
767 |
$node->getAttributeNS (undef, 'value'); |
$node->getAttributeNS (undef, 'value')).')'; |
768 |
} else { |
} else { |
769 |
$result .= node2code ($node); |
$result .= node2code ($node); |
770 |
} |
} |
791 |
$pre .= perl_statement perl_var type => '$', local_name => $_, |
$pre .= perl_statement perl_var type => '$', local_name => $_, |
792 |
scope => 'our'; |
scope => 'our'; |
793 |
} |
} |
794 |
$pre .= perl_statement q<plan (>.(0+$Status->{Number}).q<)>; |
my $plan = $Status->{Number_local} ? 'plan_local' : 'plan'; |
795 |
|
$pre .= perl_statement qq<$plan (>.(0+$Status->{Number}).q<)>; |
796 |
|
|
797 |
|
$result .= perl_statement q<end_of_test ()>; |
798 |
|
|
799 |
output_result $pre.$result; |
output_result $pre.$result; |
800 |
|
|
801 |
|
1; |
802 |
|
|
803 |
|
__END__ |
804 |
|
|
805 |
|
=head1 NAME |
806 |
|
|
807 |
|
domtest2perl - DOM Test Suite XML Test File to Perl Test Code Converter |
808 |
|
|
809 |
|
=head1 SYNOPSIS |
810 |
|
|
811 |
|
perl path/to/domtest2perl.pl input.xml > output.pl |
812 |
|
perl path/to/domtest2perl.pl input.xml --output-file=output.pl |
813 |
|
|
814 |
|
=over 4 |
815 |
|
|
816 |
|
=item I<input.xml> |
817 |
|
|
818 |
|
The name of file to input. It should be an XML document |
819 |
|
in the DOM Test Suite. |
820 |
|
|
821 |
|
=item I<output.pl> |
822 |
|
|
823 |
|
The name of file to output. It is overwritten if already exists. |
824 |
|
|
825 |
|
=back |
826 |
|
|
827 |
|
=head1 SEE ALSO |
828 |
|
|
829 |
|
I<Document Object Model (DOM) Conformance Test Suites>, |
830 |
|
<http://www.w3.org/DOM/Test/>. |
831 |
|
|
832 |
|
F<domts2perl.pl> |
833 |
|
|
834 |
|
F<mkdommemlist.pl> |
835 |
|
|
836 |
|
=head1 LICENSE |
837 |
|
|
838 |
|
Copyright 2004-2005 Wakaba <w@suika.fam.cx>. All rights reserved. |
839 |
|
|
840 |
|
This program is free software; you can redistribute it and/or |
841 |
|
modify it under the same terms as Perl itself. |
842 |
|
|
843 |
|
=cut |
844 |
|
|