/[suikacvs]/markup/html/whatpm/t/content-checker.pl
Suika

Contents of /markup/html/whatpm/t/content-checker.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Thu Sep 18 05:31:46 2008 UTC (16 years, 1 month ago) by wakaba
Branch: MAIN
File MIME type: text/plain
++ whatpm/t/ChangeLog	18 Sep 2008 05:31:37 -0000
2008-09-18  Wakaba  <wakaba@suika.fam.cx>

	* ContentChecker.t: Test engine moved to another script.

	* content-checker.pl: New script.

1 wakaba 1.1 use strict;
2    
3     ## ISSUE: Currently we require manakai XML parser to test arbitrary XML tree.
4     use lib qw[/home/wakaba/work/manakai2/lib];
5    
6     use Test;
7     require Whatpm::ContentChecker;
8     require Message::DOM::DOMImplementation;
9     require Message::DOM::XMLParserTemp;
10     require Whatpm::HTML;
11     require Whatpm::NanoDOM;
12    
13     sub test_files (@) {
14     my @FILES = @_;
15    
16     for my $file_name (@FILES) {
17     open my $file, '<', $file_name or die "$0: $file_name: $!";
18     print "# $file_name\n";
19    
20     my $test;
21     my $mode = 'data';
22     while (<$file>) {
23     s/\x0D\x0A/\x0A/;
24     if (/^#data$/) {
25     undef $test;
26     $test->{data} = '';
27     $mode = 'data';
28     $test->{parse_as} = 'xml';
29     } elsif (/^#data html$/) {
30     undef $test;
31     $test->{data} = '';
32     $mode = 'data';
33     $test->{parse_as} = 'html';
34     } elsif (/^#errors$/) {
35     $test->{errors} = [];
36     $mode = 'errors';
37     $test->{data} =~ s/\x0D?\x0A\z//;
38     } elsif (defined $test->{errors} and /^$/) {
39     test ($test);
40     undef $test;
41     } else {
42     if ($mode eq 'data') {
43     $test->{$mode} .= $_;
44     } elsif ($mode eq 'errors') {
45     tr/\x0D\x0A//d;
46     push @{$test->{errors}}, $_;
47     }
48     }
49     }
50     } # @FILES
51     } # test_files
52    
53     my $dom = Message::DOM::DOMImplementation->new;
54     sub test ($) {
55     my $test = shift;
56    
57     my $doc;
58     if ($test->{parse_as} eq 'xml') {
59     open my $fh, '<', \($test->{data});
60     $doc = Message::DOM::XMLParserTemp->parse_byte_stream
61     ($fh => $dom, sub { }, charset => 'utf-8');
62     $doc->input_encoding (undef);
63     ## NOTE: There should be no well-formedness error; if there is,
64     ## then it is an error of the test case itself.
65     } else {
66     $doc = Whatpm::NanoDOM::Document->new;
67     Whatpm::HTML->parse_string ($test->{data} => $doc);
68     }
69    
70     my @error;
71     Whatpm::ContentChecker->check_element
72     ($doc->document_element, sub {
73     my %opt = @_;
74     if ($opt{type} =~ /^status:/ and $opt{level} eq 'i') {
75     #
76     } else {
77     push @error, get_node_path ($opt{node}) . ';' . $opt{type} .
78     (defined $opt{text} ? ';' . $opt{text} : '') .
79     (defined $opt{level} ? ';'.$opt{level} : '');
80     }
81     }, sub {
82     my $opt = shift;
83     push @error, get_node_path ($opt->{container_node}) . ';SUBDOC';
84     });
85    
86     ok join ("\n", sort {$a cmp $b} @error),
87     join ("\n", sort {$a cmp $b} @{$test->{errors}}), $test->{data};
88     } # test
89    
90     sub get_node_path ($) {
91     my $node = shift;
92     my @r;
93     while (defined $node) {
94     my $rs;
95     if ($node->node_type == 1) {
96     $rs = $node->manakai_local_name;
97     $node = $node->parent_node;
98     } elsif ($node->node_type == 2) {
99     $rs = '@' . $node->manakai_local_name;
100     $node = $node->owner_element;
101     } elsif ($node->node_type == 3) {
102     $rs = '"' . $node->data . '"';
103     $node = $node->parent_node;
104     } elsif ($node->node_type == 9) {
105     $rs = '';
106     $node = $node->parent_node;
107     } else {
108     $rs = '#' . $node->node_type;
109     $node = $node->parent_node;
110     }
111     unshift @r, $rs;
112     }
113     return join '/', @r;
114     } # get_node_path
115    
116     =head1 NAME
117    
118     content-checker.pl - Test engine for document conformance checking
119    
120     =head1 DESCRIPTION
121    
122     The C<content-checker.pl> script implements a test engine for the
123     conformance checking modules, directly or indirectly referenced from
124     L<Whatpm::ContentChecker>.
125    
126     This script is C<require>d by various test scripts, including
127     C<ContentCheker.t>, C<ContentChecker-Atom.t>, C<HTML-tokenizer-2.t>,
128     and C<LangTag.t>.
129    
130     =head1 AUTHOR
131    
132     Wakaba <w@suika.fam.cx>.
133    
134     =head1 LICENSE
135    
136     Public Domain.
137    
138     =cut
139    
140     1; ## $Date: 2008/08/31 06:57:32 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24