1 |
wakaba |
1.1 |
#!/usr/bin/perl |
2 |
|
|
use strict; |
3 |
|
|
|
4 |
wakaba |
1.23 |
my $DEBUG = $ENV{DEBUG}; |
5 |
wakaba |
1.33 |
|
6 |
wakaba |
1.32 |
use lib qw[/home/wakaba/work/manakai2/lib]; |
7 |
wakaba |
1.41 |
my $test_dir_name = 't/'; |
8 |
|
|
my $dir_name = 't/tree-construction/'; |
9 |
wakaba |
1.1 |
|
10 |
|
|
use Test; |
11 |
wakaba |
1.45 |
BEGIN { plan tests => 5058 } |
12 |
wakaba |
1.1 |
|
13 |
|
|
use Data::Dumper; |
14 |
|
|
$Data::Dumper::Useqq = 1; |
15 |
|
|
sub Data::Dumper::qquote { |
16 |
|
|
my $s = shift; |
17 |
|
|
$s =~ s/([^\x20\x21-\x26\x28-\x5B\x5D-\x7E])/sprintf '\x{%02X}', ord $1/ge; |
18 |
|
|
return q<qq'> . $s . q<'>; |
19 |
|
|
} # Data::Dumper::qquote |
20 |
|
|
|
21 |
wakaba |
1.23 |
if ($DEBUG) { |
22 |
wakaba |
1.25 |
my $not_found = {%{$Whatpm::HTML::Debug::cp or {}}}; |
23 |
wakaba |
1.23 |
$Whatpm::HTML::Debug::cp_pass = sub { |
24 |
|
|
my $id = shift; |
25 |
|
|
delete $not_found->{$id}; |
26 |
|
|
}; |
27 |
|
|
|
28 |
|
|
END { |
29 |
|
|
for my $id (sort {$a <=> $b || $a cmp $b} keys %$not_found) { |
30 |
|
|
print "# checkpoint $id is not reached\n"; |
31 |
|
|
} |
32 |
|
|
} |
33 |
|
|
} |
34 |
|
|
|
35 |
wakaba |
1.4 |
use Whatpm::HTML; |
36 |
|
|
use Whatpm::NanoDOM; |
37 |
wakaba |
1.33 |
use Whatpm::Charset::UnicodeChecker; |
38 |
wakaba |
1.43 |
use Whatpm::HTML::Dumper qw/dumptree/; |
39 |
wakaba |
1.1 |
|
40 |
|
|
sub test ($) { |
41 |
|
|
my $test = shift; |
42 |
|
|
|
43 |
wakaba |
1.39 |
if ($test->{'document-fragment'}) { |
44 |
|
|
if (@{$test->{'document-fragment'}->[1]}) { |
45 |
|
|
## NOTE: Old format. |
46 |
|
|
$test->{element} = $test->{'document-fragment'}->[1]->[0]; |
47 |
|
|
$test->{document} ||= $test->{'document-fragment'}; |
48 |
|
|
} else { |
49 |
|
|
## NOTE: New format. |
50 |
|
|
$test->{element} = $test->{'document-fragment'}->[0]; |
51 |
|
|
} |
52 |
|
|
} |
53 |
|
|
|
54 |
wakaba |
1.4 |
my $doc = Whatpm::NanoDOM::Document->new; |
55 |
wakaba |
1.1 |
my @errors; |
56 |
wakaba |
1.30 |
my @shoulds; |
57 |
wakaba |
1.1 |
|
58 |
|
|
$SIG{INT} = sub { |
59 |
wakaba |
1.43 |
print scalar dumptree ($doc); |
60 |
wakaba |
1.1 |
exit; |
61 |
|
|
}; |
62 |
wakaba |
1.3 |
|
63 |
wakaba |
1.5 |
my $onerror = sub { |
64 |
|
|
my %opt = @_; |
65 |
wakaba |
1.30 |
if ($opt{level} eq 's') { |
66 |
|
|
push @shoulds, join ':', $opt{line}, $opt{column}, $opt{type}; |
67 |
|
|
} else { |
68 |
|
|
push @errors, join ':', $opt{line}, $opt{column}, $opt{type}; |
69 |
|
|
} |
70 |
wakaba |
1.5 |
}; |
71 |
wakaba |
1.33 |
|
72 |
|
|
my $chk = sub { |
73 |
|
|
return Whatpm::Charset::UnicodeChecker->new_handle ($_[0], 'html5'); |
74 |
|
|
}; # $chk |
75 |
|
|
|
76 |
wakaba |
1.5 |
my $result; |
77 |
|
|
unless (defined $test->{element}) { |
78 |
wakaba |
1.39 |
Whatpm::HTML->parse_char_string |
79 |
|
|
($test->{data}->[0] => $doc, $onerror, $chk); |
80 |
wakaba |
1.43 |
$result = dumptree ($doc); |
81 |
wakaba |
1.5 |
} else { |
82 |
|
|
my $el = $doc->create_element_ns |
83 |
|
|
('http://www.w3.org/1999/xhtml', [undef, $test->{element}]); |
84 |
wakaba |
1.39 |
Whatpm::HTML->set_inner_html ($el, $test->{data}->[0], $onerror, $chk); |
85 |
wakaba |
1.43 |
$result = dumptree ($el); |
86 |
wakaba |
1.5 |
} |
87 |
wakaba |
1.39 |
|
88 |
wakaba |
1.42 |
warn "No #errors section ($test->{data}->[0])" unless $test->{errors}; |
89 |
wakaba |
1.5 |
|
90 |
wakaba |
1.39 |
ok scalar @errors, scalar @{$test->{errors}->[0] or []}, |
91 |
|
|
'Parse error: ' . Data::Dumper::qquote ($test->{data}->[0]) . '; ' . |
92 |
|
|
join (', ', @errors) . ';' . join (', ', @{$test->{errors}->[0] or []}); |
93 |
|
|
ok scalar @shoulds, scalar @{$test->{shoulds}->[0] or []}, |
94 |
|
|
'SHOULD-level error: ' . Data::Dumper::qquote ($test->{data}->[0]) . '; ' . |
95 |
|
|
join (', ', @shoulds) . ';' . join (', ', @{$test->{shoulds}->[0] or []}); |
96 |
wakaba |
1.1 |
|
97 |
wakaba |
1.41 |
$test->{document}->[0] .= "\x0A" if length $test->{document}->[0]; |
98 |
|
|
ok $result, $test->{document}->[0], |
99 |
wakaba |
1.39 |
'Document tree: ' . Data::Dumper::qquote ($test->{data}->[0]); |
100 |
wakaba |
1.1 |
} # test |
101 |
|
|
|
102 |
wakaba |
1.44 |
my @FILES = grep {$_} split /\s+/, qq[ |
103 |
|
|
${test_dir_name}tokenizer-test-2.dat |
104 |
|
|
${test_dir_name}tokenizer-test-3.dat |
105 |
|
|
${dir_name}tests1.dat |
106 |
|
|
${dir_name}tests2.dat |
107 |
|
|
${dir_name}tests3.dat |
108 |
|
|
${dir_name}tests4.dat |
109 |
|
|
${dir_name}tests5.dat |
110 |
|
|
${dir_name}tests6.dat |
111 |
|
|
${dir_name}tests7.dat |
112 |
|
|
${dir_name}tests8.dat |
113 |
|
|
${dir_name}tests9.dat |
114 |
|
|
${dir_name}tests10.dat |
115 |
|
|
${dir_name}tests11.dat |
116 |
|
|
${dir_name}tests12.dat |
117 |
|
|
${test_dir_name}tree-test-1.dat |
118 |
|
|
${test_dir_name}tree-test-2.dat |
119 |
|
|
${test_dir_name}tree-test-3.dat |
120 |
|
|
${test_dir_name}tree-test-void.dat |
121 |
|
|
${test_dir_name}tree-test-flow.dat |
122 |
|
|
${test_dir_name}tree-test-phrasing.dat |
123 |
|
|
${test_dir_name}tree-test-form.dat |
124 |
|
|
${test_dir_name}tree-test-foreign.dat |
125 |
|
|
]; |
126 |
|
|
|
127 |
|
|
require 't/testfiles.pl'; |
128 |
|
|
execute_test ($_, { |
129 |
|
|
errors => {is_list => 1}, |
130 |
|
|
shoulds => {is_list => 1}, |
131 |
|
|
document => {is_prefixed => 1}, |
132 |
|
|
'document-fragment' => {is_prefixed => 1}, |
133 |
|
|
}, \&test) for @FILES; |
134 |
|
|
|
135 |
wakaba |
1.1 |
## License: Public Domain. |
136 |
wakaba |
1.45 |
## $Date: 2008/10/14 09:00:57 $ |