| 1 |
#!/usr/bin/perl |
#!/usr/bin/perl |
| 2 |
use strict; |
use strict; |
| 3 |
|
|
| 4 |
|
my $DEBUG = $ENV{DEBUG}; |
| 5 |
|
|
| 6 |
my $dir_name; |
my $dir_name; |
| 7 |
my $test_dir_name; |
my $test_dir_name; |
| 8 |
BEGIN { |
BEGIN { |
| 22 |
} |
} |
| 23 |
|
|
| 24 |
use Test; |
use Test; |
| 25 |
BEGIN { plan tests => 422 } |
BEGIN { plan tests => 1920 } |
| 26 |
|
|
| 27 |
use Data::Dumper; |
use Data::Dumper; |
| 28 |
$Data::Dumper::Useqq = 1; |
$Data::Dumper::Useqq = 1; |
| 32 |
return q<qq'> . $s . q<'>; |
return q<qq'> . $s . q<'>; |
| 33 |
} # Data::Dumper::qquote |
} # Data::Dumper::qquote |
| 34 |
|
|
| 35 |
|
|
| 36 |
|
if ($DEBUG) { |
| 37 |
|
my $not_found = {%{$Whatpm::HTML::Debug::cp or {}}}; |
| 38 |
|
$Whatpm::HTML::Debug::cp_pass = sub { |
| 39 |
|
my $id = shift; |
| 40 |
|
delete $not_found->{$id}; |
| 41 |
|
}; |
| 42 |
|
|
| 43 |
|
END { |
| 44 |
|
for my $id (sort {$a <=> $b || $a cmp $b} keys %$not_found) { |
| 45 |
|
print "# checkpoint $id is not reached\n"; |
| 46 |
|
} |
| 47 |
|
} |
| 48 |
|
} |
| 49 |
|
|
| 50 |
for my $file_name (grep {$_} split /\s+/, qq[ |
for my $file_name (grep {$_} split /\s+/, qq[ |
| 51 |
|
${test_dir_name}tokenizer-test-2.dat |
| 52 |
${dir_name}tests1.dat |
${dir_name}tests1.dat |
| 53 |
${dir_name}tests2.dat |
${dir_name}tests2.dat |
| 54 |
${dir_name}tests3.dat |
${dir_name}tests3.dat |
| 55 |
${dir_name}tests4.dat |
${dir_name}tests4.dat |
| 56 |
|
${dir_name}tests5.dat |
| 57 |
|
${dir_name}tests6.dat |
| 58 |
|
${dir_name}tests7.dat |
| 59 |
${test_dir_name}tree-test-1.dat |
${test_dir_name}tree-test-1.dat |
| 60 |
|
${test_dir_name}tree-test-2.dat |
| 61 |
]) { |
]) { |
| 62 |
open my $file, '<', $file_name |
open my $file, '<', $file_name |
| 63 |
or die "$0: $file_name: $!"; |
or die "$0: $file_name: $!"; |
| 64 |
|
print "# $file_name\n"; |
| 65 |
|
|
| 66 |
my $test; |
my $test; |
| 67 |
my $mode = 'data'; |
my $mode = 'data'; |
| 68 |
|
my $escaped; |
| 69 |
while (<$file>) { |
while (<$file>) { |
| 70 |
s/\x0D\x0A/\x0A/; |
s/\x0D\x0A/\x0A/; |
| 71 |
if (/^#data$/) { |
if (/^#data$/) { |
| 72 |
undef $test; |
undef $test; |
| 73 |
$test->{data} = ''; |
$test->{data} = ''; |
| 74 |
$mode = 'data'; |
$mode = 'data'; |
| 75 |
|
undef $escaped; |
| 76 |
|
} elsif (/^#data escaped$/) { |
| 77 |
|
undef $test; |
| 78 |
|
$test->{data} = ''; |
| 79 |
|
$mode = 'data'; |
| 80 |
|
$escaped = 1; |
| 81 |
} elsif (/^#errors$/) { |
} elsif (/^#errors$/) { |
| 82 |
$test->{errors} = []; |
$test->{errors} = []; |
| 83 |
$mode = 'errors'; |
$mode = 'errors'; |
| 84 |
$test->{data} =~ s/\x0D?\x0A\z//; |
$test->{data} =~ s/\x0D?\x0A\z//; |
| 85 |
|
$test->{data} =~ s/\\u([0-9A-Fa-f]{4})/chr hex $1/ge if $escaped; |
| 86 |
|
$test->{data} =~ s/\\U([0-9A-Fa-f]{8})/chr hex $1/ge if $escaped; |
| 87 |
|
undef $escaped; |
| 88 |
} elsif (/^#document$/) { |
} elsif (/^#document$/) { |
| 89 |
$test->{document} = ''; |
$test->{document} = ''; |
| 90 |
$mode = 'document'; |
$mode = 'document'; |
| 91 |
|
undef $escaped; |
| 92 |
|
} elsif (/^#document escaped$/) { |
| 93 |
|
$test->{document} = ''; |
| 94 |
|
$mode = 'document'; |
| 95 |
|
$escaped = 1; |
| 96 |
|
} elsif (/^#document-fragment$/) { |
| 97 |
|
$test->{element} = ''; |
| 98 |
|
$mode = 'element'; |
| 99 |
|
undef $escaped; |
| 100 |
} elsif (/^#document-fragment (\S+)$/) { |
} elsif (/^#document-fragment (\S+)$/) { |
| 101 |
$test->{document} = ''; |
$test->{document} = ''; |
| 102 |
$mode = 'document'; |
$mode = 'document'; |
| 103 |
$test->{element} = $1; |
$test->{element} = $1; |
| 104 |
|
undef $escaped; |
| 105 |
|
} elsif (/^#document-fragment (\S+) escaped$/) { |
| 106 |
|
$test->{document} = ''; |
| 107 |
|
$mode = 'document'; |
| 108 |
|
$test->{element} = $1; |
| 109 |
|
$escaped = 1; |
| 110 |
} elsif (defined $test->{document} and /^$/) { |
} elsif (defined $test->{document} and /^$/) { |
| 111 |
|
$test->{document} =~ s/\\u([0-9A-Fa-f]{4})/chr hex $1/ge if $escaped; |
| 112 |
|
$test->{document} =~ s/\\U([0-9A-Fa-f]{8})/chr hex $1/ge if $escaped; |
| 113 |
test ($test); |
test ($test); |
| 114 |
undef $test; |
undef $test; |
| 115 |
} else { |
} else { |
| 116 |
if ($mode eq 'data' or $mode eq 'document') { |
if ($mode eq 'data' or $mode eq 'document') { |
| 117 |
$test->{$mode} .= $_; |
$test->{$mode} .= $_; |
| 118 |
|
} elsif ($mode eq 'element') { |
| 119 |
|
tr/\x0D\x0A//d; |
| 120 |
|
$test->{$mode} .= $_; |
| 121 |
} elsif ($mode eq 'errors') { |
} elsif ($mode eq 'errors') { |
| 122 |
tr/\x0D\x0A//d; |
tr/\x0D\x0A//d; |
| 123 |
push @{$test->{errors}}, $_; |
push @{$test->{errors}}, $_; |
| 157 |
} |
} |
| 158 |
|
|
| 159 |
ok scalar @errors, scalar @{$test->{errors}}, |
ok scalar @errors, scalar @{$test->{errors}}, |
| 160 |
'Parse error: ' . $test->{data} . '; ' . |
'Parse error: ' . Data::Dumper::qquote ($test->{data}) . '; ' . |
| 161 |
join (', ', @errors) . ';' . join (', ', @{$test->{errors}}); |
join (', ', @errors) . ';' . join (', ', @{$test->{errors}}); |
| 162 |
|
|
| 163 |
ok $result, $test->{document}, 'Document tree: ' . $test->{data}; |
ok $result, $test->{document}, |
| 164 |
|
'Document tree: ' . Data::Dumper::qquote ($test->{data}); |
| 165 |
} # test |
} # test |
| 166 |
|
|
| 167 |
sub serialize ($) { |
sub serialize ($) { |
| 188 |
} elsif ($nt == $child->[0]->COMMENT_NODE) { |
} elsif ($nt == $child->[0]->COMMENT_NODE) { |
| 189 |
$r .= '| ' . $child->[1] . '<!-- ' . $child->[0]->data . " -->\x0A"; |
$r .= '| ' . $child->[1] . '<!-- ' . $child->[0]->data . " -->\x0A"; |
| 190 |
} elsif ($nt == $child->[0]->DOCUMENT_TYPE_NODE) { |
} elsif ($nt == $child->[0]->DOCUMENT_TYPE_NODE) { |
| 191 |
$r .= '| ' . $child->[1] . '<!DOCTYPE ' . $child->[0]->name . ">\x0A"; |
$r .= '| ' . $child->[1] . '<!DOCTYPE ' . $child->[0]->name; |
| 192 |
|
my $pubid = $child->[0]->public_id; |
| 193 |
|
$r .= ' PUBLIC "' . $pubid . '"' if length $pubid; |
| 194 |
|
my $sysid = $child->[0]->system_id; |
| 195 |
|
$r .= ' SYSTEM' if not length $pubid and length $sysid; |
| 196 |
|
$r .= ' "' . $sysid . '"' if length $sysid; |
| 197 |
|
$r .= ">\x0A"; |
| 198 |
} else { |
} else { |
| 199 |
$r .= '| ' . $child->[1] . $child->[0]->node_type . "\x0A"; # error |
$r .= '| ' . $child->[1] . $child->[0]->node_type . "\x0A"; # error |
| 200 |
} |
} |