| 1 |
#!/usr/bin/perl |
#!/usr/bin/perl |
| 2 |
use strict; |
use strict; |
| 3 |
|
|
| 4 |
|
my $DEBUG = $ENV{DEBUG}; |
| 5 |
|
|
| 6 |
|
use lib qw[/home/wakaba/work/manakai2/lib]; |
| 7 |
|
|
| 8 |
my $dir_name; |
my $dir_name; |
| 9 |
my $test_dir_name; |
my $test_dir_name; |
| 10 |
BEGIN { |
BEGIN { |
| 24 |
} |
} |
| 25 |
|
|
| 26 |
use Test; |
use Test; |
| 27 |
BEGIN { plan tests => 774 } |
BEGIN { plan tests => 3105 } |
| 28 |
|
|
| 29 |
use Data::Dumper; |
use Data::Dumper; |
| 30 |
$Data::Dumper::Useqq = 1; |
$Data::Dumper::Useqq = 1; |
| 34 |
return q<qq'> . $s . q<'>; |
return q<qq'> . $s . q<'>; |
| 35 |
} # Data::Dumper::qquote |
} # Data::Dumper::qquote |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
if ($DEBUG) { |
| 39 |
|
my $not_found = {%{$Whatpm::HTML::Debug::cp or {}}}; |
| 40 |
|
$Whatpm::HTML::Debug::cp_pass = sub { |
| 41 |
|
my $id = shift; |
| 42 |
|
delete $not_found->{$id}; |
| 43 |
|
}; |
| 44 |
|
|
| 45 |
|
END { |
| 46 |
|
for my $id (sort {$a <=> $b || $a cmp $b} keys %$not_found) { |
| 47 |
|
print "# checkpoint $id is not reached\n"; |
| 48 |
|
} |
| 49 |
|
} |
| 50 |
|
} |
| 51 |
|
|
| 52 |
for my $file_name (grep {$_} split /\s+/, qq[ |
for my $file_name (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 |
| 55 |
${dir_name}tests1.dat |
${dir_name}tests1.dat |
| 56 |
${dir_name}tests2.dat |
${dir_name}tests2.dat |
| 57 |
${dir_name}tests3.dat |
${dir_name}tests3.dat |
| 58 |
${dir_name}tests4.dat |
${dir_name}tests4.dat |
| 59 |
${dir_name}tests5.dat |
${dir_name}tests5.dat |
| 60 |
${dir_name}tests6.dat |
${dir_name}tests6.dat |
| 61 |
|
${dir_name}tests7.dat |
| 62 |
${test_dir_name}tree-test-1.dat |
${test_dir_name}tree-test-1.dat |
| 63 |
${test_dir_name}tree-test-2.dat |
${test_dir_name}tree-test-2.dat |
| 64 |
|
${test_dir_name}tree-test-3.dat |
| 65 |
]) { |
]) { |
| 66 |
open my $file, '<', $file_name |
open my $file, '<', $file_name |
| 67 |
or die "$0: $file_name: $!"; |
or die "$0: $file_name: $!"; |
| 87 |
$mode = 'errors'; |
$mode = 'errors'; |
| 88 |
$test->{data} =~ s/\x0D?\x0A\z//; |
$test->{data} =~ s/\x0D?\x0A\z//; |
| 89 |
$test->{data} =~ s/\\u([0-9A-Fa-f]{4})/chr hex $1/ge if $escaped; |
$test->{data} =~ s/\\u([0-9A-Fa-f]{4})/chr hex $1/ge if $escaped; |
| 90 |
|
$test->{data} =~ s/\\U([0-9A-Fa-f]{8})/chr hex $1/ge if $escaped; |
| 91 |
undef $escaped; |
undef $escaped; |
| 92 |
|
} elsif (/^#shoulds$/) { |
| 93 |
|
$test->{shoulds} = []; |
| 94 |
|
$mode = 'shoulds'; |
| 95 |
} elsif (/^#document$/) { |
} elsif (/^#document$/) { |
| 96 |
$test->{document} = ''; |
$test->{document} = ''; |
| 97 |
$mode = 'document'; |
$mode = 'document'; |
| 116 |
$escaped = 1; |
$escaped = 1; |
| 117 |
} elsif (defined $test->{document} and /^$/) { |
} elsif (defined $test->{document} and /^$/) { |
| 118 |
$test->{document} =~ s/\\u([0-9A-Fa-f]{4})/chr hex $1/ge if $escaped; |
$test->{document} =~ s/\\u([0-9A-Fa-f]{4})/chr hex $1/ge if $escaped; |
| 119 |
|
$test->{document} =~ s/\\U([0-9A-Fa-f]{8})/chr hex $1/ge if $escaped; |
| 120 |
test ($test); |
test ($test); |
| 121 |
undef $test; |
undef $test; |
| 122 |
} else { |
} else { |
| 128 |
} elsif ($mode eq 'errors') { |
} elsif ($mode eq 'errors') { |
| 129 |
tr/\x0D\x0A//d; |
tr/\x0D\x0A//d; |
| 130 |
push @{$test->{errors}}, $_; |
push @{$test->{errors}}, $_; |
| 131 |
|
} elsif ($mode eq 'shoulds') { |
| 132 |
|
tr/\x0D\x0A//d; |
| 133 |
|
push @{$test->{shoulds}}, $_; |
| 134 |
} |
} |
| 135 |
} |
} |
| 136 |
} |
} |
| 139 |
|
|
| 140 |
use Whatpm::HTML; |
use Whatpm::HTML; |
| 141 |
use Whatpm::NanoDOM; |
use Whatpm::NanoDOM; |
| 142 |
|
use Whatpm::Charset::UnicodeChecker; |
| 143 |
|
|
| 144 |
sub test ($) { |
sub test ($) { |
| 145 |
my $test = shift; |
my $test = shift; |
| 146 |
|
|
| 147 |
my $doc = Whatpm::NanoDOM::Document->new; |
my $doc = Whatpm::NanoDOM::Document->new; |
| 148 |
my @errors; |
my @errors; |
| 149 |
|
my @shoulds; |
| 150 |
|
|
| 151 |
$SIG{INT} = sub { |
$SIG{INT} = sub { |
| 152 |
print scalar serialize ($doc); |
print scalar serialize ($doc); |
| 155 |
|
|
| 156 |
my $onerror = sub { |
my $onerror = sub { |
| 157 |
my %opt = @_; |
my %opt = @_; |
| 158 |
push @errors, join ':', $opt{line}, $opt{column}, $opt{type}; |
if ($opt{level} eq 's') { |
| 159 |
|
push @shoulds, join ':', $opt{line}, $opt{column}, $opt{type}; |
| 160 |
|
} else { |
| 161 |
|
push @errors, join ':', $opt{line}, $opt{column}, $opt{type}; |
| 162 |
|
} |
| 163 |
}; |
}; |
| 164 |
|
|
| 165 |
|
my $chk = sub { |
| 166 |
|
return Whatpm::Charset::UnicodeChecker->new_handle ($_[0], 'html5'); |
| 167 |
|
}; # $chk |
| 168 |
|
|
| 169 |
my $result; |
my $result; |
| 170 |
unless (defined $test->{element}) { |
unless (defined $test->{element}) { |
| 171 |
Whatpm::HTML->parse_string ($test->{data} => $doc, $onerror); |
Whatpm::HTML->parse_char_string ($test->{data} => $doc, $onerror, $chk); |
| 172 |
$result = serialize ($doc); |
$result = serialize ($doc); |
| 173 |
} else { |
} else { |
| 174 |
my $el = $doc->create_element_ns |
my $el = $doc->create_element_ns |
| 175 |
('http://www.w3.org/1999/xhtml', [undef, $test->{element}]); |
('http://www.w3.org/1999/xhtml', [undef, $test->{element}]); |
| 176 |
Whatpm::HTML->set_inner_html ($el, $test->{data}, $onerror); |
Whatpm::HTML->set_inner_html ($el, $test->{data}, $onerror, $chk); |
| 177 |
$result = serialize ($el); |
$result = serialize ($el); |
| 178 |
} |
} |
| 179 |
|
|
| 180 |
ok scalar @errors, scalar @{$test->{errors}}, |
ok scalar @errors, scalar @{$test->{errors}}, |
| 181 |
'Parse error: ' . $test->{data} . '; ' . |
'Parse error: ' . Data::Dumper::qquote ($test->{data}) . '; ' . |
| 182 |
join (', ', @errors) . ';' . join (', ', @{$test->{errors}}); |
join (', ', @errors) . ';' . join (', ', @{$test->{errors}}); |
| 183 |
|
ok scalar @shoulds, scalar @{$test->{shoulds} or []}, |
| 184 |
|
'SHOULD-level error: ' . Data::Dumper::qquote ($test->{data}) . '; ' . |
| 185 |
|
join (', ', @shoulds) . ';' . join (', ', @{$test->{shoulds} or []}); |
| 186 |
|
|
| 187 |
ok $result, $test->{document}, 'Document tree: ' . $test->{data}; |
ok $result, $test->{document}, |
| 188 |
|
'Document tree: ' . Data::Dumper::qquote ($test->{data}); |
| 189 |
} # test |
} # test |
| 190 |
|
|
| 191 |
sub serialize ($) { |
sub serialize ($) { |
| 212 |
} elsif ($nt == $child->[0]->COMMENT_NODE) { |
} elsif ($nt == $child->[0]->COMMENT_NODE) { |
| 213 |
$r .= '| ' . $child->[1] . '<!-- ' . $child->[0]->data . " -->\x0A"; |
$r .= '| ' . $child->[1] . '<!-- ' . $child->[0]->data . " -->\x0A"; |
| 214 |
} elsif ($nt == $child->[0]->DOCUMENT_TYPE_NODE) { |
} elsif ($nt == $child->[0]->DOCUMENT_TYPE_NODE) { |
| 215 |
$r .= '| ' . $child->[1] . '<!DOCTYPE ' . $child->[0]->name . ">\x0A"; |
$r .= '| ' . $child->[1] . '<!DOCTYPE ' . $child->[0]->name; |
| 216 |
|
my $pubid = $child->[0]->public_id; |
| 217 |
|
$r .= ' PUBLIC "' . $pubid . '"' if length $pubid; |
| 218 |
|
my $sysid = $child->[0]->system_id; |
| 219 |
|
$r .= ' SYSTEM' if not length $pubid and length $sysid; |
| 220 |
|
$r .= ' "' . $sysid . '"' if length $sysid; |
| 221 |
|
$r .= ">\x0A"; |
| 222 |
} else { |
} else { |
| 223 |
$r .= '| ' . $child->[1] . $child->[0]->node_type . "\x0A"; # error |
$r .= '| ' . $child->[1] . $child->[0]->node_type . "\x0A"; # error |
| 224 |
} |
} |