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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.17 by wakaba, Sat Jun 30 14:13:20 2007 UTC revision 1.31 by wakaba, Sat Sep 13 04:19:56 2008 UTC
# Line 1  Line 1 
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 {
# Line 20  BEGIN { Line 22  BEGIN {
22  }  }
23    
24  use Test;  use Test;
25  BEGIN { plan tests => 632 }  BEGIN { plan tests => 3105 }
26    
27  use Data::Dumper;  use Data::Dumper;
28  $Data::Dumper::Useqq = 1;  $Data::Dumper::Useqq = 1;
# Line 30  sub Data::Dumper::qquote { Line 32  sub Data::Dumper::qquote {
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                        ${test_dir_name}tokenizer-test-2.dat
52                          ${test_dir_name}tokenizer-test-3.dat
53                        ${dir_name}tests1.dat                        ${dir_name}tests1.dat
54                        ${dir_name}tests2.dat                        ${dir_name}tests2.dat
55                        ${dir_name}tests3.dat                        ${dir_name}tests3.dat
56                        ${dir_name}tests4.dat                        ${dir_name}tests4.dat
57                        ${dir_name}tests5.dat                        ${dir_name}tests5.dat
58                        ${dir_name}tests6.dat                        ${dir_name}tests6.dat
59                          ${dir_name}tests7.dat
60                        ${test_dir_name}tree-test-1.dat                        ${test_dir_name}tree-test-1.dat
61                        ${test_dir_name}tree-test-2.dat                        ${test_dir_name}tree-test-2.dat
62                          ${test_dir_name}tree-test-3.dat
63                       ]) {                       ]) {
64    open my $file, '<', $file_name    open my $file, '<', $file_name
65      or die "$0: $file_name: $!";      or die "$0: $file_name: $!";
# Line 65  for my $file_name (grep {$_} split /\s+/ Line 85  for my $file_name (grep {$_} split /\s+/
85        $mode = 'errors';        $mode = 'errors';
86        $test->{data} =~ s/\x0D?\x0A\z//;              $test->{data} =~ s/\x0D?\x0A\z//;      
87        $test->{data} =~ s/\\u([0-9A-Fa-f]{4})/chr hex $1/ge if $escaped;        $test->{data} =~ s/\\u([0-9A-Fa-f]{4})/chr hex $1/ge if $escaped;
88          $test->{data} =~ s/\\U([0-9A-Fa-f]{8})/chr hex $1/ge if $escaped;
89        undef $escaped;        undef $escaped;
90        } elsif (/^#shoulds$/) {
91          $test->{shoulds} = [];
92          $mode = 'shoulds';
93      } elsif (/^#document$/) {      } elsif (/^#document$/) {
94        $test->{document} = '';        $test->{document} = '';
95        $mode = 'document';        $mode = 'document';
# Line 74  for my $file_name (grep {$_} split /\s+/ Line 98  for my $file_name (grep {$_} split /\s+/
98        $test->{document} = '';        $test->{document} = '';
99        $mode = 'document';        $mode = 'document';
100        $escaped = 1;        $escaped = 1;
101        } elsif (/^#document-fragment$/) {
102          $test->{element} = '';
103          $mode = 'element';
104          undef $escaped;
105      } elsif (/^#document-fragment (\S+)$/) {      } elsif (/^#document-fragment (\S+)$/) {
106        $test->{document} = '';        $test->{document} = '';
107        $mode = 'document';        $mode = 'document';
# Line 86  for my $file_name (grep {$_} split /\s+/ Line 114  for my $file_name (grep {$_} split /\s+/
114        $escaped = 1;        $escaped = 1;
115      } elsif (defined $test->{document} and /^$/) {      } elsif (defined $test->{document} and /^$/) {
116        $test->{document} =~ s/\\u([0-9A-Fa-f]{4})/chr hex $1/ge if $escaped;        $test->{document} =~ s/\\u([0-9A-Fa-f]{4})/chr hex $1/ge if $escaped;
117          $test->{document} =~ s/\\U([0-9A-Fa-f]{8})/chr hex $1/ge if $escaped;
118        test ($test);        test ($test);
119        undef $test;        undef $test;
120      } else {      } else {
121        if ($mode eq 'data' or $mode eq 'document') {        if ($mode eq 'data' or $mode eq 'document') {
122          $test->{$mode} .= $_;          $test->{$mode} .= $_;
123          } elsif ($mode eq 'element') {
124            tr/\x0D\x0A//d;
125            $test->{$mode} .= $_;
126        } elsif ($mode eq 'errors') {        } elsif ($mode eq 'errors') {
127          tr/\x0D\x0A//d;          tr/\x0D\x0A//d;
128          push @{$test->{errors}}, $_;          push @{$test->{errors}}, $_;
129          } elsif ($mode eq 'shoulds') {
130            tr/\x0D\x0A//d;
131            push @{$test->{shoulds}}, $_;
132        }        }
133      }      }
134    }    }
# Line 108  sub test ($) { Line 143  sub test ($) {
143    
144    my $doc = Whatpm::NanoDOM::Document->new;    my $doc = Whatpm::NanoDOM::Document->new;
145    my @errors;    my @errors;
146      my @shoulds;
147        
148    $SIG{INT} = sub {    $SIG{INT} = sub {
149      print scalar serialize ($doc);      print scalar serialize ($doc);
# Line 116  sub test ($) { Line 152  sub test ($) {
152    
153    my $onerror = sub {    my $onerror = sub {
154      my %opt = @_;      my %opt = @_;
155      push @errors, join ':', $opt{line}, $opt{column}, $opt{type};      if ($opt{level} eq 's') {
156          push @shoulds, join ':', $opt{line}, $opt{column}, $opt{type};
157        } else {
158          push @errors, join ':', $opt{line}, $opt{column}, $opt{type};
159        }
160    };    };
161    my $result;    my $result;
162    unless (defined $test->{element}) {    unless (defined $test->{element}) {
# Line 130  sub test ($) { Line 170  sub test ($) {
170    }    }
171            
172    ok scalar @errors, scalar @{$test->{errors}},    ok scalar @errors, scalar @{$test->{errors}},
173      'Parse error: ' . $test->{data} . '; ' .      'Parse error: ' . Data::Dumper::qquote ($test->{data}) . '; ' .
174      join (', ', @errors) . ';' . join (', ', @{$test->{errors}});      join (', ', @errors) . ';' . join (', ', @{$test->{errors}});
175      ok scalar @shoulds, scalar @{$test->{shoulds} or []},
176        'SHOULD-level error: ' . Data::Dumper::qquote ($test->{data}) . '; ' .
177        join (', ', @shoulds) . ';' . join (', ', @{$test->{shoulds} or []});
178    
179    ok $result, $test->{document}, 'Document tree: ' . $test->{data};    ok $result, $test->{document},
180          'Document tree: ' . Data::Dumper::qquote ($test->{data});
181  } # test  } # test
182    
183  sub serialize ($) {  sub serialize ($) {
# Line 160  sub serialize ($) { Line 204  sub serialize ($) {
204      } elsif ($nt == $child->[0]->COMMENT_NODE) {      } elsif ($nt == $child->[0]->COMMENT_NODE) {
205        $r .= '| ' . $child->[1] . '<!-- ' . $child->[0]->data . " -->\x0A";        $r .= '| ' . $child->[1] . '<!-- ' . $child->[0]->data . " -->\x0A";
206      } elsif ($nt == $child->[0]->DOCUMENT_TYPE_NODE) {      } elsif ($nt == $child->[0]->DOCUMENT_TYPE_NODE) {
207        $r .= '| ' . $child->[1] . '<!DOCTYPE ' . $child->[0]->name . ">\x0A";        $r .= '| ' . $child->[1] . '<!DOCTYPE ' . $child->[0]->name;
208          my $pubid = $child->[0]->public_id;
209          $r .= ' PUBLIC "' . $pubid . '"' if length $pubid;
210          my $sysid = $child->[0]->system_id;
211          $r .= ' SYSTEM' if not length $pubid and length $sysid;
212          $r .= ' "' . $sysid . '"' if length $sysid;
213          $r .= ">\x0A";
214      } else {      } else {
215        $r .= '| ' . $child->[1] . $child->[0]->node_type . "\x0A"; # error        $r .= '| ' . $child->[1] . $child->[0]->node_type . "\x0A"; # error
216      }      }

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.31

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24