| 49 |
} |
} |
| 50 |
} |
} |
| 51 |
|
|
| 52 |
for my $file_name (grep {$_} split /\s+/, qq[ |
my @FILES = grep {$_} split /\s+/, qq[ |
| 53 |
${test_dir_name}tokenizer-test-2.dat |
${test_dir_name}tokenizer-test-2.dat |
| 54 |
${test_dir_name}tokenizer-test-3.dat |
${test_dir_name}tokenizer-test-3.dat |
| 55 |
${dir_name}tests1.dat |
${dir_name}tests1.dat |
| 59 |
${dir_name}tests5.dat |
${dir_name}tests5.dat |
| 60 |
${dir_name}tests6.dat |
${dir_name}tests6.dat |
| 61 |
${dir_name}tests7.dat |
${dir_name}tests7.dat |
| 62 |
|
${dir_name}tests8.dat |
| 63 |
|
${dir_name}tests9.dat |
| 64 |
|
${dir_name}tests10.dat |
| 65 |
|
${dir_name}tests11.dat |
| 66 |
|
${dir_name}tests12.dat |
| 67 |
${test_dir_name}tree-test-1.dat |
${test_dir_name}tree-test-1.dat |
| 68 |
${test_dir_name}tree-test-2.dat |
${test_dir_name}tree-test-2.dat |
| 69 |
${test_dir_name}tree-test-3.dat |
${test_dir_name}tree-test-3.dat |
| 72 |
${test_dir_name}tree-test-phrasing.dat |
${test_dir_name}tree-test-phrasing.dat |
| 73 |
${test_dir_name}tree-test-form.dat |
${test_dir_name}tree-test-form.dat |
| 74 |
${test_dir_name}tree-test-foreign.dat |
${test_dir_name}tree-test-foreign.dat |
| 75 |
]) { |
]; |
| 76 |
open my $file, '<', $file_name |
|
| 77 |
or die "$0: $file_name: $!"; |
require 't/testfiles.pl'; |
| 78 |
print "# $file_name\n"; |
execute_test ($_, { |
| 79 |
|
errors => {is_list => 1}, |
| 80 |
my $test; |
shoulds => {is_list => 1}, |
| 81 |
my $mode = 'data'; |
document => {is_prefixed => 1}, |
| 82 |
my $escaped; |
'document-fragment' => {is_prefixed => 1}, |
| 83 |
while (<$file>) { |
}, \&test) for @FILES; |
|
s/\x0D\x0A/\x0A/; |
|
|
if (/^#data$/) { |
|
|
undef $test; |
|
|
$test->{data} = ''; |
|
|
$mode = 'data'; |
|
|
undef $escaped; |
|
|
} elsif (/^#data escaped$/) { |
|
|
undef $test; |
|
|
$test->{data} = ''; |
|
|
$mode = 'data'; |
|
|
$escaped = 1; |
|
|
} elsif (/^#errors$/) { |
|
|
$test->{errors} = []; |
|
|
$mode = 'errors'; |
|
|
$test->{data} =~ s/\x0D?\x0A\z//; |
|
|
$test->{data} =~ s/\\u([0-9A-Fa-f]{4})/chr hex $1/ge if $escaped; |
|
|
$test->{data} =~ s/\\U([0-9A-Fa-f]{8})/chr hex $1/ge if $escaped; |
|
|
undef $escaped; |
|
|
} elsif (/^#shoulds$/) { |
|
|
$test->{shoulds} = []; |
|
|
$mode = 'shoulds'; |
|
|
} elsif (/^#document$/) { |
|
|
$test->{document} = ''; |
|
|
$mode = 'document'; |
|
|
undef $escaped; |
|
|
} elsif (/^#document escaped$/) { |
|
|
$test->{document} = ''; |
|
|
$mode = 'document'; |
|
|
$escaped = 1; |
|
|
} elsif (/^#document-fragment$/) { |
|
|
$test->{element} = ''; |
|
|
$mode = 'element'; |
|
|
undef $escaped; |
|
|
} elsif (/^#document-fragment (\S+)$/) { |
|
|
$test->{document} = ''; |
|
|
$mode = 'document'; |
|
|
$test->{element} = $1; |
|
|
undef $escaped; |
|
|
} elsif (/^#document-fragment (\S+) escaped$/) { |
|
|
$test->{document} = ''; |
|
|
$mode = 'document'; |
|
|
$test->{element} = $1; |
|
|
$escaped = 1; |
|
|
} elsif (defined $test->{document} and /^$/) { |
|
|
$test->{document} =~ s/\\u([0-9A-Fa-f]{4})/chr hex $1/ge if $escaped; |
|
|
$test->{document} =~ s/\\U([0-9A-Fa-f]{8})/chr hex $1/ge if $escaped; |
|
|
test ($test); |
|
|
undef $test; |
|
|
} else { |
|
|
if ($mode eq 'data' or $mode eq 'document') { |
|
|
$test->{$mode} .= $_; |
|
|
} elsif ($mode eq 'element') { |
|
|
tr/\x0D\x0A//d; |
|
|
$test->{$mode} .= $_; |
|
|
} elsif ($mode eq 'errors') { |
|
|
tr/\x0D\x0A//d; |
|
|
push @{$test->{errors}}, $_; |
|
|
} elsif ($mode eq 'shoulds') { |
|
|
tr/\x0D\x0A//d; |
|
|
push @{$test->{shoulds}}, $_; |
|
|
} |
|
|
} |
|
|
} |
|
|
test ($test) if $test->{errors}; |
|
|
} |
|
| 84 |
|
|
| 85 |
use Whatpm::HTML; |
use Whatpm::HTML; |
| 86 |
use Whatpm::NanoDOM; |
use Whatpm::NanoDOM; |
| 89 |
sub test ($) { |
sub test ($) { |
| 90 |
my $test = shift; |
my $test = shift; |
| 91 |
|
|
| 92 |
|
if ($test->{'document-fragment'}) { |
| 93 |
|
if (@{$test->{'document-fragment'}->[1]}) { |
| 94 |
|
## NOTE: Old format. |
| 95 |
|
$test->{element} = $test->{'document-fragment'}->[1]->[0]; |
| 96 |
|
$test->{document} ||= $test->{'document-fragment'}; |
| 97 |
|
} else { |
| 98 |
|
## NOTE: New format. |
| 99 |
|
$test->{element} = $test->{'document-fragment'}->[0]; |
| 100 |
|
} |
| 101 |
|
} |
| 102 |
|
|
| 103 |
my $doc = Whatpm::NanoDOM::Document->new; |
my $doc = Whatpm::NanoDOM::Document->new; |
| 104 |
my @errors; |
my @errors; |
| 105 |
my @shoulds; |
my @shoulds; |
| 124 |
|
|
| 125 |
my $result; |
my $result; |
| 126 |
unless (defined $test->{element}) { |
unless (defined $test->{element}) { |
| 127 |
Whatpm::HTML->parse_char_string ($test->{data} => $doc, $onerror, $chk); |
Whatpm::HTML->parse_char_string |
| 128 |
|
($test->{data}->[0] => $doc, $onerror, $chk); |
| 129 |
$result = serialize ($doc); |
$result = serialize ($doc); |
| 130 |
} else { |
} else { |
| 131 |
my $el = $doc->create_element_ns |
my $el = $doc->create_element_ns |
| 132 |
('http://www.w3.org/1999/xhtml', [undef, $test->{element}]); |
('http://www.w3.org/1999/xhtml', [undef, $test->{element}]); |
| 133 |
Whatpm::HTML->set_inner_html ($el, $test->{data}, $onerror, $chk); |
Whatpm::HTML->set_inner_html ($el, $test->{data}->[0], $onerror, $chk); |
| 134 |
$result = serialize ($el); |
$result = serialize ($el); |
| 135 |
} |
} |
| 136 |
|
|
| 137 |
|
warn "No #errors section" unless $test->{errors}; |
| 138 |
|
|
| 139 |
ok scalar @errors, scalar @{$test->{errors}}, |
ok scalar @errors, scalar @{$test->{errors}->[0] or []}, |
| 140 |
'Parse error: ' . Data::Dumper::qquote ($test->{data}) . '; ' . |
'Parse error: ' . Data::Dumper::qquote ($test->{data}->[0]) . '; ' . |
| 141 |
join (', ', @errors) . ';' . join (', ', @{$test->{errors}}); |
join (', ', @errors) . ';' . join (', ', @{$test->{errors}->[0] or []}); |
| 142 |
ok scalar @shoulds, scalar @{$test->{shoulds} or []}, |
ok scalar @shoulds, scalar @{$test->{shoulds}->[0] or []}, |
| 143 |
'SHOULD-level error: ' . Data::Dumper::qquote ($test->{data}) . '; ' . |
'SHOULD-level error: ' . Data::Dumper::qquote ($test->{data}->[0]) . '; ' . |
| 144 |
join (', ', @shoulds) . ';' . join (', ', @{$test->{shoulds} or []}); |
join (', ', @shoulds) . ';' . join (', ', @{$test->{shoulds}->[0] or []}); |
| 145 |
|
|
| 146 |
ok $result, $test->{document}, |
ok $result, $test->{document}->[0] . "\x0A", |
| 147 |
'Document tree: ' . Data::Dumper::qquote ($test->{data}); |
'Document tree: ' . Data::Dumper::qquote ($test->{data}->[0]); |
| 148 |
} # test |
} # test |
| 149 |
|
|
| 150 |
|
## NOTE: Spec: <http://wiki.whatwg.org/wiki/Parser_tests>. |
| 151 |
sub serialize ($) { |
sub serialize ($) { |
| 152 |
my $node = shift; |
my $node = shift; |
| 153 |
my $r = ''; |
my $r = ''; |
| 157 |
my $child = shift @node; |
my $child = shift @node; |
| 158 |
my $nt = $child->[0]->node_type; |
my $nt = $child->[0]->node_type; |
| 159 |
if ($nt == $child->[0]->ELEMENT_NODE) { |
if ($nt == $child->[0]->ELEMENT_NODE) { |
| 160 |
$r .= '| ' . $child->[1] . '<' . $child->[0]->tag_name . ">\x0A"; ## ISSUE: case? |
$r .= $child->[1] . '<' . $child->[0]->tag_name . ">\x0A"; ## ISSUE: case? |
| 161 |
|
|
| 162 |
for my $attr (sort {$a->[0] cmp $b->[0]} map { [$_->name, $_->value] } |
for my $attr (sort {$a->[0] cmp $b->[0]} map { [$_->name, $_->value] } |
| 163 |
@{$child->[0]->attributes}) { |
@{$child->[0]->attributes}) { |
| 164 |
$r .= '| ' . $child->[1] . ' ' . $attr->[0] . '="'; ## ISSUE: case? |
$r .= $child->[1] . ' ' . $attr->[0] . '="'; ## ISSUE: case? |
| 165 |
$r .= $attr->[1] . '"' . "\x0A"; |
$r .= $attr->[1] . '"' . "\x0A"; |
| 166 |
} |
} |
| 167 |
|
|
| 168 |
unshift @node, |
unshift @node, |
| 169 |
map { [$_, $child->[1] . ' '] } @{$child->[0]->child_nodes}; |
map { [$_, $child->[1] . ' '] } @{$child->[0]->child_nodes}; |
| 170 |
} elsif ($nt == $child->[0]->TEXT_NODE) { |
} elsif ($nt == $child->[0]->TEXT_NODE) { |
| 171 |
$r .= '| ' . $child->[1] . '"' . $child->[0]->data . '"' . "\x0A"; |
$r .= $child->[1] . '"' . $child->[0]->data . '"' . "\x0A"; |
| 172 |
} elsif ($nt == $child->[0]->COMMENT_NODE) { |
} elsif ($nt == $child->[0]->COMMENT_NODE) { |
| 173 |
$r .= '| ' . $child->[1] . '<!-- ' . $child->[0]->data . " -->\x0A"; |
$r .= $child->[1] . '<!-- ' . $child->[0]->data . " -->\x0A"; |
| 174 |
} elsif ($nt == $child->[0]->DOCUMENT_TYPE_NODE) { |
} elsif ($nt == $child->[0]->DOCUMENT_TYPE_NODE) { |
| 175 |
$r .= '| ' . $child->[1] . '<!DOCTYPE ' . $child->[0]->name; |
$r .= $child->[1] . '<!DOCTYPE ' . $child->[0]->name; |
| 176 |
my $pubid = $child->[0]->public_id; |
my $pubid = $child->[0]->public_id; |
|
$r .= ' PUBLIC "' . $pubid . '"' if length $pubid; |
|
| 177 |
my $sysid = $child->[0]->system_id; |
my $sysid = $child->[0]->system_id; |
| 178 |
$r .= ' SYSTEM' if not length $pubid and length $sysid; |
if (length $pubid or length $sysid) { |
| 179 |
$r .= ' "' . $sysid . '"' if length $sysid; |
$r .= ' "' . $pubid . '"'; |
| 180 |
|
$r .= ' "' . $sysid . '"'; |
| 181 |
|
} |
| 182 |
$r .= ">\x0A"; |
$r .= ">\x0A"; |
| 183 |
} else { |
} else { |
| 184 |
$r .= '| ' . $child->[1] . $child->[0]->node_type . "\x0A"; # error |
$r .= $child->[1] . $child->[0]->node_type . "\x0A"; # error |
| 185 |
} |
} |
| 186 |
} |
} |
| 187 |
|
|