/[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.43 - (hide annotations) (download) (as text)
Tue Oct 14 07:49:55 2008 UTC (16 years, 9 months ago) by wakaba
Branch: MAIN
Changes since 1.42: +5 -74 lines
File MIME type: application/x-troff
++ whatpm/t/ChangeLog	14 Oct 2008 07:47:45 -0000
	* HTML-tree.t: Serialization code moved to Whatpm::HTML::Dumper.

2008-10-14  Wakaba  <wakaba@suika.fam.cx>

++ whatpm/Whatpm/HTML/ChangeLog	14 Oct 2008 07:47:03 -0000
	* Dumper.pm: New module.

2008-10-14  Wakaba  <wakaba@suika.fam.cx>

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.41 BEGIN { plan tests => 4935 }
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.39 my @FILES = grep {$_} split /\s+/, qq[
36 wakaba 1.12 ${test_dir_name}tokenizer-test-2.dat
37 wakaba 1.31 ${test_dir_name}tokenizer-test-3.dat
38 wakaba 1.2 ${dir_name}tests1.dat
39     ${dir_name}tests2.dat
40     ${dir_name}tests3.dat
41     ${dir_name}tests4.dat
42 wakaba 1.11 ${dir_name}tests5.dat
43     ${dir_name}tests6.dat
44 wakaba 1.27 ${dir_name}tests7.dat
45 wakaba 1.38 ${dir_name}tests8.dat
46     ${dir_name}tests9.dat
47     ${dir_name}tests10.dat
48     ${dir_name}tests11.dat
49     ${dir_name}tests12.dat
50 wakaba 1.2 ${test_dir_name}tree-test-1.dat
51 wakaba 1.14 ${test_dir_name}tree-test-2.dat
52 wakaba 1.29 ${test_dir_name}tree-test-3.dat
53 wakaba 1.34 ${test_dir_name}tree-test-void.dat
54 wakaba 1.35 ${test_dir_name}tree-test-flow.dat
55     ${test_dir_name}tree-test-phrasing.dat
56 wakaba 1.37 ${test_dir_name}tree-test-form.dat
57 wakaba 1.36 ${test_dir_name}tree-test-foreign.dat
58 wakaba 1.39 ];
59    
60     require 't/testfiles.pl';
61     execute_test ($_, {
62     errors => {is_list => 1},
63     shoulds => {is_list => 1},
64     document => {is_prefixed => 1},
65     'document-fragment' => {is_prefixed => 1},
66     }, \&test) for @FILES;
67 wakaba 1.1
68 wakaba 1.4 use Whatpm::HTML;
69     use Whatpm::NanoDOM;
70 wakaba 1.33 use Whatpm::Charset::UnicodeChecker;
71 wakaba 1.43 use Whatpm::HTML::Dumper qw/dumptree/;
72 wakaba 1.1
73     sub test ($) {
74     my $test = shift;
75    
76 wakaba 1.39 if ($test->{'document-fragment'}) {
77     if (@{$test->{'document-fragment'}->[1]}) {
78     ## NOTE: Old format.
79     $test->{element} = $test->{'document-fragment'}->[1]->[0];
80     $test->{document} ||= $test->{'document-fragment'};
81     } else {
82     ## NOTE: New format.
83     $test->{element} = $test->{'document-fragment'}->[0];
84     }
85     }
86    
87 wakaba 1.4 my $doc = Whatpm::NanoDOM::Document->new;
88 wakaba 1.1 my @errors;
89 wakaba 1.30 my @shoulds;
90 wakaba 1.1
91     $SIG{INT} = sub {
92 wakaba 1.43 print scalar dumptree ($doc);
93 wakaba 1.1 exit;
94     };
95 wakaba 1.3
96 wakaba 1.5 my $onerror = sub {
97     my %opt = @_;
98 wakaba 1.30 if ($opt{level} eq 's') {
99     push @shoulds, join ':', $opt{line}, $opt{column}, $opt{type};
100     } else {
101     push @errors, join ':', $opt{line}, $opt{column}, $opt{type};
102     }
103 wakaba 1.5 };
104 wakaba 1.33
105     my $chk = sub {
106     return Whatpm::Charset::UnicodeChecker->new_handle ($_[0], 'html5');
107     }; # $chk
108    
109 wakaba 1.5 my $result;
110     unless (defined $test->{element}) {
111 wakaba 1.39 Whatpm::HTML->parse_char_string
112     ($test->{data}->[0] => $doc, $onerror, $chk);
113 wakaba 1.43 $result = dumptree ($doc);
114 wakaba 1.5 } else {
115     my $el = $doc->create_element_ns
116     ('http://www.w3.org/1999/xhtml', [undef, $test->{element}]);
117 wakaba 1.39 Whatpm::HTML->set_inner_html ($el, $test->{data}->[0], $onerror, $chk);
118 wakaba 1.43 $result = dumptree ($el);
119 wakaba 1.5 }
120 wakaba 1.39
121 wakaba 1.42 warn "No #errors section ($test->{data}->[0])" unless $test->{errors};
122 wakaba 1.5
123 wakaba 1.39 ok scalar @errors, scalar @{$test->{errors}->[0] or []},
124     'Parse error: ' . Data::Dumper::qquote ($test->{data}->[0]) . '; ' .
125     join (', ', @errors) . ';' . join (', ', @{$test->{errors}->[0] or []});
126     ok scalar @shoulds, scalar @{$test->{shoulds}->[0] or []},
127     'SHOULD-level error: ' . Data::Dumper::qquote ($test->{data}->[0]) . '; ' .
128     join (', ', @shoulds) . ';' . join (', ', @{$test->{shoulds}->[0] or []});
129 wakaba 1.1
130 wakaba 1.41 $test->{document}->[0] .= "\x0A" if length $test->{document}->[0];
131     ok $result, $test->{document}->[0],
132 wakaba 1.39 'Document tree: ' . Data::Dumper::qquote ($test->{data}->[0]);
133 wakaba 1.1 } # test
134    
135     ## License: Public Domain.
136 wakaba 1.43 ## $Date: 2008/10/14 07:40:52 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24