/[suikacvs]/markup/html/whatpm/t/ContentChecker.t
Suika

Contents of /markup/html/whatpm/t/ContentChecker.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.26 - (hide annotations) (download) (as text)
Sun Feb 24 01:38:36 2008 UTC (17 years, 4 months ago) by wakaba
Branch: MAIN
Changes since 1.25: +7 -3 lines
File MIME type: application/x-troff
++ whatpm/Whatpm/ChangeLog	24 Feb 2008 01:38:04 -0000
	* ContentChecker.pm (check_element): Element standardized
	status information is now dispatched.

2008-02-24  Wakaba  <wakaba@suika.fam.cx>

++ whatpm/Whatpm/ContentChecker/ChangeLog	24 Feb 2008 01:38:30 -0000
	* HTML.pm: Standardized status attributes are added.

2008-02-24  Wakaba  <wakaba@suika.fam.cx>

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3    
4     use Test;
5 wakaba 1.24 BEGIN { plan tests => 1502 }
6 wakaba 1.1
7 wakaba 1.5 my @FILES = qw[
8     t/content-model-1.dat
9     t/content-model-2.dat
10     t/content-model-3.dat
11 wakaba 1.13 t/content-model-4.dat
12 wakaba 1.24 t/content-model-5.dat
13 wakaba 1.15 t/table-1.dat
14 wakaba 1.19 t/content-model-atom-1.dat
15     t/content-model-atom-2.dat
16 wakaba 1.5 ];
17 wakaba 1.1
18     require Whatpm::ContentChecker;
19    
20     ## ISSUE: Currently we require manakai XML parser to test arbitrary XML tree.
21 wakaba 1.23 use lib qw[/home/wakaba/work/manakai2/lib];
22 wakaba 1.12 require Message::DOM::DOMImplementation;
23     require Message::DOM::XMLParserTemp;
24 wakaba 1.4 require Whatpm::HTML;
25     require Whatpm::NanoDOM;
26 wakaba 1.1
27 wakaba 1.20 my $dom = Message::DOM::DOMImplementation->new;
28 wakaba 1.1
29     for my $file_name (@FILES) {
30     open my $file, '<', $file_name or die "$0: $file_name: $!";
31 wakaba 1.19 print "# $file_name\n";
32 wakaba 1.1
33     my $test;
34     my $mode = 'data';
35     while (<$file>) {
36     s/\x0D\x0A/\x0A/;
37     if (/^#data$/) {
38     undef $test;
39     $test->{data} = '';
40     $mode = 'data';
41 wakaba 1.4 $test->{parse_as} = 'xml';
42     } elsif (/^#data html$/) {
43     undef $test;
44     $test->{data} = '';
45     $mode = 'data';
46     $test->{parse_as} = 'html';
47 wakaba 1.1 } elsif (/^#errors$/) {
48     $test->{errors} = [];
49     $mode = 'errors';
50     $test->{data} =~ s/\x0D?\x0A\z//;
51     } elsif (defined $test->{errors} and /^$/) {
52     test ($test);
53     undef $test;
54     } else {
55     if ($mode eq 'data') {
56     $test->{$mode} .= $_;
57     } elsif ($mode eq 'errors') {
58     tr/\x0D\x0A//d;
59     push @{$test->{errors}}, $_;
60     }
61     }
62     }
63     } # @FILES
64    
65     sub test ($) {
66     my $test = shift;
67    
68 wakaba 1.4 my $doc;
69     if ($test->{parse_as} eq 'xml') {
70 wakaba 1.12 open my $fh, '<', \($test->{data});
71     $doc = Message::DOM::XMLParserTemp->parse_byte_stream
72     ($fh => $dom, sub { }, charset => 'utf-8');
73 wakaba 1.23 $doc->input_encoding (undef);
74 wakaba 1.4 ## NOTE: There should be no well-formedness error; if there is,
75     ## then it is an error of the test case itself.
76     } else {
77     $doc = Whatpm::NanoDOM::Document->new;
78     Whatpm::HTML->parse_string ($test->{data} => $doc);
79     }
80 wakaba 1.1
81     my @error;
82 wakaba 1.10 Whatpm::ContentChecker->check_element
83 wakaba 1.1 ($doc->document_element, sub {
84     my %opt = @_;
85 wakaba 1.26 if ($opt{type} =~ /^status:/ and $opt{level} eq 'i') {
86     #
87     } else {
88     push @error, get_node_path ($opt{node}) . ';' . $opt{type} .
89     (defined $opt{level} ? ';'.$opt{level} : '');
90     }
91 wakaba 1.25 }, sub {
92     my $opt = shift;
93     push @error, get_node_path ($opt->{container_node}) .
94     ';style:text/css;unsupported';
95 wakaba 1.1 });
96    
97     ok join ("\n", sort {$a cmp $b} @error),
98     join ("\n", sort {$a cmp $b} @{$test->{errors}}), $test->{data};
99     } # test
100    
101     sub get_node_path ($) {
102     my $node = shift;
103     my @r;
104     while (defined $node) {
105     my $rs;
106     if ($node->node_type == 1) {
107     $rs = $node->manakai_local_name;
108 wakaba 1.4 $node = $node->parent_node;
109 wakaba 1.3 } elsif ($node->node_type == 2) {
110     $rs = '@' . $node->manakai_local_name;
111 wakaba 1.4 $node = $node->owner_element;
112 wakaba 1.1 } elsif ($node->node_type == 3) {
113     $rs = '"' . $node->data . '"';
114 wakaba 1.4 $node = $node->parent_node;
115 wakaba 1.1 } elsif ($node->node_type == 9) {
116     $rs = '';
117 wakaba 1.4 $node = $node->parent_node;
118 wakaba 1.1 } else {
119     $rs = '#' . $node->node_type;
120 wakaba 1.4 $node = $node->parent_node;
121 wakaba 1.1 }
122     unshift @r, $rs;
123     }
124     return join '/', @r;
125     } # get_node_path
126    
127     ## License: Public Domain.
128 wakaba 1.26 ## $Date: 2008/02/16 00:18:13 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24