| 4 |
my $DEBUG = $ENV{DEBUG}; |
my $DEBUG = $ENV{DEBUG}; |
| 5 |
|
|
| 6 |
use lib qw[/home/wakaba/work/manakai2/lib]; |
use lib qw[/home/wakaba/work/manakai2/lib]; |
| 7 |
|
my $test_dir_name = 't/'; |
| 8 |
my $dir_name; |
my $dir_name = 't/tree-construction/'; |
|
my $test_dir_name; |
|
|
BEGIN { |
|
|
$test_dir_name = 't/'; |
|
|
$dir_name = 't/tree-construction/'; |
|
|
my $skip = "You don't have make command"; |
|
|
eval q{ |
|
|
system ("cd $test_dir_name; make tree-construction-files") == 0 or die |
|
|
unless -f $dir_name.'tests1.dat'; |
|
|
$skip = ''; |
|
|
}; |
|
|
if ($skip) { |
|
|
print "1..1\n"; |
|
|
print "ok 1 # $skip\n"; |
|
|
exit; |
|
|
} |
|
|
} |
|
| 9 |
|
|
| 10 |
use Test; |
use Test; |
| 11 |
BEGIN { plan tests => 3105 } |
BEGIN { plan tests => 5058 } |
| 12 |
|
|
| 13 |
use Data::Dumper; |
use Data::Dumper; |
| 14 |
$Data::Dumper::Useqq = 1; |
$Data::Dumper::Useqq = 1; |
| 18 |
return q<qq'> . $s . q<'>; |
return q<qq'> . $s . q<'>; |
| 19 |
} # Data::Dumper::qquote |
} # Data::Dumper::qquote |
| 20 |
|
|
|
|
|
| 21 |
if ($DEBUG) { |
if ($DEBUG) { |
| 22 |
my $not_found = {%{$Whatpm::HTML::Debug::cp or {}}}; |
my $not_found = {%{$Whatpm::HTML::Debug::cp or {}}}; |
| 23 |
$Whatpm::HTML::Debug::cp_pass = sub { |
$Whatpm::HTML::Debug::cp_pass = sub { |
| 32 |
} |
} |
| 33 |
} |
} |
| 34 |
|
|
|
my @FILES = grep {$_} split /\s+/, qq[ |
|
|
${test_dir_name}tokenizer-test-2.dat |
|
|
${test_dir_name}tokenizer-test-3.dat |
|
|
${dir_name}tests1.dat |
|
|
${dir_name}tests2.dat |
|
|
${dir_name}tests3.dat |
|
|
${dir_name}tests4.dat |
|
|
${dir_name}tests5.dat |
|
|
${dir_name}tests6.dat |
|
|
${dir_name}tests7.dat |
|
|
${dir_name}tests8.dat |
|
|
${dir_name}tests9.dat |
|
|
${dir_name}tests10.dat |
|
|
${dir_name}tests11.dat |
|
|
${dir_name}tests12.dat |
|
|
${test_dir_name}tree-test-1.dat |
|
|
${test_dir_name}tree-test-2.dat |
|
|
${test_dir_name}tree-test-3.dat |
|
|
${test_dir_name}tree-test-void.dat |
|
|
${test_dir_name}tree-test-flow.dat |
|
|
${test_dir_name}tree-test-phrasing.dat |
|
|
${test_dir_name}tree-test-form.dat |
|
|
${test_dir_name}tree-test-foreign.dat |
|
|
]; |
|
|
|
|
|
require 't/testfiles.pl'; |
|
|
execute_test ($_, { |
|
|
errors => {is_list => 1}, |
|
|
shoulds => {is_list => 1}, |
|
|
document => {is_prefixed => 1}, |
|
|
'document-fragment' => {is_prefixed => 1}, |
|
|
}, \&test) for @FILES; |
|
|
|
|
| 35 |
use Whatpm::HTML; |
use Whatpm::HTML; |
| 36 |
use Whatpm::NanoDOM; |
use Whatpm::NanoDOM; |
| 37 |
use Whatpm::Charset::UnicodeChecker; |
use Whatpm::Charset::UnicodeChecker; |
| 38 |
|
use Whatpm::HTML::Dumper qw/dumptree/; |
| 39 |
|
|
| 40 |
sub test ($) { |
sub test ($) { |
| 41 |
my $test = shift; |
my $test = shift; |
| 56 |
my @shoulds; |
my @shoulds; |
| 57 |
|
|
| 58 |
$SIG{INT} = sub { |
$SIG{INT} = sub { |
| 59 |
print scalar serialize ($doc); |
print scalar dumptree ($doc); |
| 60 |
exit; |
exit; |
| 61 |
}; |
}; |
| 62 |
|
|
| 77 |
unless (defined $test->{element}) { |
unless (defined $test->{element}) { |
| 78 |
Whatpm::HTML->parse_char_string |
Whatpm::HTML->parse_char_string |
| 79 |
($test->{data}->[0] => $doc, $onerror, $chk); |
($test->{data}->[0] => $doc, $onerror, $chk); |
| 80 |
$result = serialize ($doc); |
$result = dumptree ($doc); |
| 81 |
} else { |
} else { |
| 82 |
my $el = $doc->create_element_ns |
my $el = $doc->create_element_ns |
| 83 |
('http://www.w3.org/1999/xhtml', [undef, $test->{element}]); |
('http://www.w3.org/1999/xhtml', [undef, $test->{element}]); |
| 84 |
Whatpm::HTML->set_inner_html ($el, $test->{data}->[0], $onerror, $chk); |
Whatpm::HTML->set_inner_html ($el, $test->{data}->[0], $onerror, $chk); |
| 85 |
$result = serialize ($el); |
$result = dumptree ($el); |
| 86 |
} |
} |
| 87 |
|
|
| 88 |
warn "No #errors section" unless $test->{errors}; |
warn "No #errors section ($test->{data}->[0])" unless $test->{errors}; |
| 89 |
|
|
| 90 |
ok scalar @errors, scalar @{$test->{errors}->[0] or []}, |
ok scalar @errors, scalar @{$test->{errors}->[0] or []}, |
| 91 |
'Parse error: ' . Data::Dumper::qquote ($test->{data}->[0]) . '; ' . |
'Parse error: ' . Data::Dumper::qquote ($test->{data}->[0]) . '; ' . |
| 94 |
'SHOULD-level error: ' . Data::Dumper::qquote ($test->{data}->[0]) . '; ' . |
'SHOULD-level error: ' . Data::Dumper::qquote ($test->{data}->[0]) . '; ' . |
| 95 |
join (', ', @shoulds) . ';' . join (', ', @{$test->{shoulds}->[0] or []}); |
join (', ', @shoulds) . ';' . join (', ', @{$test->{shoulds}->[0] or []}); |
| 96 |
|
|
| 97 |
ok $result, $test->{document}->[0] . "\x0A", |
$test->{document}->[0] .= "\x0A" if length $test->{document}->[0]; |
| 98 |
|
ok $result, $test->{document}->[0], |
| 99 |
'Document tree: ' . Data::Dumper::qquote ($test->{data}->[0]); |
'Document tree: ' . Data::Dumper::qquote ($test->{data}->[0]); |
| 100 |
} # test |
} # test |
| 101 |
|
|
| 102 |
## NOTE: Spec: <http://wiki.whatwg.org/wiki/Parser_tests>. |
my @FILES = grep {$_} split /\s+/, qq[ |
| 103 |
sub serialize ($) { |
${test_dir_name}tokenizer-test-2.dat |
| 104 |
my $node = shift; |
${test_dir_name}tokenizer-test-3.dat |
| 105 |
my $r = ''; |
${dir_name}tests1.dat |
| 106 |
|
${dir_name}tests2.dat |
| 107 |
my @node = map { [$_, ''] } @{$node->child_nodes}; |
${dir_name}tests3.dat |
| 108 |
while (@node) { |
${dir_name}tests4.dat |
| 109 |
my $child = shift @node; |
${dir_name}tests5.dat |
| 110 |
my $nt = $child->[0]->node_type; |
${dir_name}tests6.dat |
| 111 |
if ($nt == $child->[0]->ELEMENT_NODE) { |
${dir_name}tests7.dat |
| 112 |
$r .= $child->[1] . '<' . $child->[0]->tag_name . ">\x0A"; ## ISSUE: case? |
${dir_name}tests8.dat |
| 113 |
|
${dir_name}tests9.dat |
| 114 |
for my $attr (sort {$a->[0] cmp $b->[0]} map { [$_->name, $_->value] } |
${dir_name}tests10.dat |
| 115 |
@{$child->[0]->attributes}) { |
${dir_name}tests11.dat |
| 116 |
$r .= $child->[1] . ' ' . $attr->[0] . '="'; ## ISSUE: case? |
${dir_name}tests12.dat |
| 117 |
$r .= $attr->[1] . '"' . "\x0A"; |
${test_dir_name}tree-test-1.dat |
| 118 |
} |
${test_dir_name}tree-test-2.dat |
| 119 |
|
${test_dir_name}tree-test-3.dat |
| 120 |
unshift @node, |
${test_dir_name}tree-test-void.dat |
| 121 |
map { [$_, $child->[1] . ' '] } @{$child->[0]->child_nodes}; |
${test_dir_name}tree-test-flow.dat |
| 122 |
} elsif ($nt == $child->[0]->TEXT_NODE) { |
${test_dir_name}tree-test-phrasing.dat |
| 123 |
$r .= $child->[1] . '"' . $child->[0]->data . '"' . "\x0A"; |
${test_dir_name}tree-test-form.dat |
| 124 |
} elsif ($nt == $child->[0]->COMMENT_NODE) { |
${test_dir_name}tree-test-frames.dat |
| 125 |
$r .= $child->[1] . '<!-- ' . $child->[0]->data . " -->\x0A"; |
${test_dir_name}tree-test-foreign.dat |
| 126 |
} elsif ($nt == $child->[0]->DOCUMENT_TYPE_NODE) { |
]; |
| 127 |
$r .= $child->[1] . '<!DOCTYPE ' . $child->[0]->name; |
|
| 128 |
my $pubid = $child->[0]->public_id; |
require 't/testfiles.pl'; |
| 129 |
my $sysid = $child->[0]->system_id; |
execute_test ($_, { |
| 130 |
if (length $pubid or length $sysid) { |
errors => {is_list => 1}, |
| 131 |
$r .= ' "' . $pubid . '"'; |
shoulds => {is_list => 1}, |
| 132 |
$r .= ' "' . $sysid . '"'; |
document => {is_prefixed => 1}, |
| 133 |
} |
'document-fragment' => {is_prefixed => 1}, |
| 134 |
$r .= ">\x0A"; |
}, \&test) for @FILES; |
|
} else { |
|
|
$r .= $child->[1] . $child->[0]->node_type . "\x0A"; # error |
|
|
} |
|
|
} |
|
|
|
|
|
return $r; |
|
|
} # serialize |
|
| 135 |
|
|
| 136 |
## License: Public Domain. |
## License: Public Domain. |
| 137 |
## $Date$ |
## $Date$ |