| 20 |
} |
} |
| 21 |
|
|
| 22 |
use Test; |
use Test; |
| 23 |
BEGIN { plan tests => 422 } |
BEGIN { plan tests => 774 } |
| 24 |
|
|
| 25 |
use Data::Dumper; |
use Data::Dumper; |
| 26 |
$Data::Dumper::Useqq = 1; |
$Data::Dumper::Useqq = 1; |
| 31 |
} # Data::Dumper::qquote |
} # Data::Dumper::qquote |
| 32 |
|
|
| 33 |
for my $file_name (grep {$_} split /\s+/, qq[ |
for my $file_name (grep {$_} split /\s+/, qq[ |
| 34 |
|
${test_dir_name}tokenizer-test-2.dat |
| 35 |
${dir_name}tests1.dat |
${dir_name}tests1.dat |
| 36 |
${dir_name}tests2.dat |
${dir_name}tests2.dat |
| 37 |
${dir_name}tests3.dat |
${dir_name}tests3.dat |
| 38 |
${dir_name}tests4.dat |
${dir_name}tests4.dat |
| 39 |
|
${dir_name}tests5.dat |
| 40 |
|
${dir_name}tests6.dat |
| 41 |
${test_dir_name}tree-test-1.dat |
${test_dir_name}tree-test-1.dat |
| 42 |
|
${test_dir_name}tree-test-2.dat |
| 43 |
]) { |
]) { |
| 44 |
open my $file, '<', $file_name |
open my $file, '<', $file_name |
| 45 |
or die "$0: $file_name: $!"; |
or die "$0: $file_name: $!"; |
| 46 |
|
print "# $file_name\n"; |
| 47 |
|
|
| 48 |
my $test; |
my $test; |
| 49 |
my $mode = 'data'; |
my $mode = 'data'; |
| 50 |
|
my $escaped; |
| 51 |
while (<$file>) { |
while (<$file>) { |
| 52 |
s/\x0D\x0A/\x0A/; |
s/\x0D\x0A/\x0A/; |
| 53 |
if (/^#data$/) { |
if (/^#data$/) { |
| 54 |
undef $test; |
undef $test; |
| 55 |
$test->{data} = ''; |
$test->{data} = ''; |
| 56 |
$mode = 'data'; |
$mode = 'data'; |
| 57 |
|
undef $escaped; |
| 58 |
|
} elsif (/^#data escaped$/) { |
| 59 |
|
undef $test; |
| 60 |
|
$test->{data} = ''; |
| 61 |
|
$mode = 'data'; |
| 62 |
|
$escaped = 1; |
| 63 |
} elsif (/^#errors$/) { |
} elsif (/^#errors$/) { |
| 64 |
$test->{errors} = []; |
$test->{errors} = []; |
| 65 |
$mode = 'errors'; |
$mode = 'errors'; |
| 66 |
$test->{data} =~ s/\x0D?\x0A\z//; |
$test->{data} =~ s/\x0D?\x0A\z//; |
| 67 |
|
$test->{data} =~ s/\\u([0-9A-Fa-f]{4})/chr hex $1/ge if $escaped; |
| 68 |
|
undef $escaped; |
| 69 |
} elsif (/^#document$/) { |
} elsif (/^#document$/) { |
| 70 |
$test->{document} = ''; |
$test->{document} = ''; |
| 71 |
$mode = 'document'; |
$mode = 'document'; |
| 72 |
|
undef $escaped; |
| 73 |
|
} elsif (/^#document escaped$/) { |
| 74 |
|
$test->{document} = ''; |
| 75 |
|
$mode = 'document'; |
| 76 |
|
$escaped = 1; |
| 77 |
|
} elsif (/^#document-fragment$/) { |
| 78 |
|
$test->{element} = ''; |
| 79 |
|
$mode = 'element'; |
| 80 |
|
undef $escaped; |
| 81 |
} elsif (/^#document-fragment (\S+)$/) { |
} elsif (/^#document-fragment (\S+)$/) { |
| 82 |
$test->{document} = ''; |
$test->{document} = ''; |
| 83 |
$mode = 'document'; |
$mode = 'document'; |
| 84 |
$test->{element} = $1; |
$test->{element} = $1; |
| 85 |
|
undef $escaped; |
| 86 |
|
} elsif (/^#document-fragment (\S+) escaped$/) { |
| 87 |
|
$test->{document} = ''; |
| 88 |
|
$mode = 'document'; |
| 89 |
|
$test->{element} = $1; |
| 90 |
|
$escaped = 1; |
| 91 |
} elsif (defined $test->{document} and /^$/) { |
} elsif (defined $test->{document} and /^$/) { |
| 92 |
|
$test->{document} =~ s/\\u([0-9A-Fa-f]{4})/chr hex $1/ge if $escaped; |
| 93 |
test ($test); |
test ($test); |
| 94 |
undef $test; |
undef $test; |
| 95 |
} else { |
} else { |
| 96 |
if ($mode eq 'data' or $mode eq 'document') { |
if ($mode eq 'data' or $mode eq 'document') { |
| 97 |
$test->{$mode} .= $_; |
$test->{$mode} .= $_; |
| 98 |
|
} elsif ($mode eq 'element') { |
| 99 |
|
tr/\x0D\x0A//d; |
| 100 |
|
$test->{$mode} .= $_; |
| 101 |
} elsif ($mode eq 'errors') { |
} elsif ($mode eq 'errors') { |
| 102 |
tr/\x0D\x0A//d; |
tr/\x0D\x0A//d; |
| 103 |
push @{$test->{errors}}, $_; |
push @{$test->{errors}}, $_; |
| 137 |
} |
} |
| 138 |
|
|
| 139 |
ok scalar @errors, scalar @{$test->{errors}}, |
ok scalar @errors, scalar @{$test->{errors}}, |
| 140 |
'Parse error: ' . $test->{data} . '; ' . |
'Parse error: ' . Data::Dumper::qquote ($test->{data}) . '; ' . |
| 141 |
join (', ', @errors) . ';' . join (', ', @{$test->{errors}}); |
join (', ', @errors) . ';' . join (', ', @{$test->{errors}}); |
| 142 |
|
|
| 143 |
ok $result, $test->{document}, 'Document tree: ' . $test->{data}; |
ok $result, $test->{document}, |
| 144 |
|
'Document tree: ' . Data::Dumper::qquote ($test->{data}); |
| 145 |
} # test |
} # test |
| 146 |
|
|
| 147 |
sub serialize ($) { |
sub serialize ($) { |