/[suikacvs]/markup/html/whatpm/t/HTML-tree.t
Suika

Contents of /markup/html/whatpm/t/HTML-tree.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.46 - (show annotations) (download) (as text)
Sun Sep 6 12:53:19 2009 UTC (15 years, 10 months ago) by wakaba
Branch: MAIN
CVS Tags: HEAD
Changes since 1.45: +2 -1 lines
File MIME type: application/x-troff
++ whatpm/t/ChangeLog	6 Sep 2009 12:52:28 -0000
	* tree-test-frames.dat: New test data file.

	* HTML-tree.t: Added the new test data file.

2009-09-06  Wakaba  <wakaba@suika.fam.cx>

++ whatpm/Whatpm/ChangeLog	6 Sep 2009 12:53:01 -0000
	* HTML.pm.src: The first cut to implement the |frameset-ok| flag
	concept (HTML5 revision 2703).

2009-09-06  Wakaba  <wakaba@suika.fam.cx>

1 #!/usr/bin/perl
2 use strict;
3
4 my $DEBUG = $ENV{DEBUG};
5
6 use lib qw[/home/wakaba/work/manakai2/lib];
7 my $test_dir_name = 't/';
8 my $dir_name = 't/tree-construction/';
9
10 use Test;
11 BEGIN { plan tests => 5058 }
12
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 if ($DEBUG) {
22 my $not_found = {%{$Whatpm::HTML::Debug::cp or {}}};
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 use Whatpm::HTML;
36 use Whatpm::NanoDOM;
37 use Whatpm::Charset::UnicodeChecker;
38 use Whatpm::HTML::Dumper qw/dumptree/;
39
40 sub test ($) {
41 my $test = shift;
42
43 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 my $doc = Whatpm::NanoDOM::Document->new;
55 my @errors;
56 my @shoulds;
57
58 $SIG{INT} = sub {
59 print scalar dumptree ($doc);
60 exit;
61 };
62
63 my $onerror = sub {
64 my %opt = @_;
65 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 };
71
72 my $chk = sub {
73 return Whatpm::Charset::UnicodeChecker->new_handle ($_[0], 'html5');
74 }; # $chk
75
76 my $result;
77 unless (defined $test->{element}) {
78 Whatpm::HTML->parse_char_string
79 ($test->{data}->[0] => $doc, $onerror, $chk);
80 $result = dumptree ($doc);
81 } else {
82 my $el = $doc->create_element_ns
83 ('http://www.w3.org/1999/xhtml', [undef, $test->{element}]);
84 Whatpm::HTML->set_inner_html ($el, $test->{data}->[0], $onerror, $chk);
85 $result = dumptree ($el);
86 }
87
88 warn "No #errors section ($test->{data}->[0])" unless $test->{errors};
89
90 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
97 $test->{document}->[0] .= "\x0A" if length $test->{document}->[0];
98 ok $result, $test->{document}->[0],
99 'Document tree: ' . Data::Dumper::qquote ($test->{data}->[0]);
100 } # test
101
102 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-frames.dat
125 ${test_dir_name}tree-test-foreign.dat
126 ];
127
128 require 't/testfiles.pl';
129 execute_test ($_, {
130 errors => {is_list => 1},
131 shoulds => {is_list => 1},
132 document => {is_prefixed => 1},
133 'document-fragment' => {is_prefixed => 1},
134 }, \&test) for @FILES;
135
136 ## License: Public Domain.
137 ## $Date: 2008/10/14 13:24:53 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24