/[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.14 - (hide annotations) (download) (as text)
Sat Jun 30 13:12:33 2007 UTC (18 years ago) by wakaba
Branch: MAIN
Changes since 1.13: +3 -2 lines
File MIME type: application/x-troff
++ whatpm/t/ChangeLog	30 Jun 2007 12:28:52 -0000
2007-06-30  Wakaba  <wakaba@suika.fam.cx>

	* URIChecker.t: Error level names in test results has
	been changed.

	* tokenizer-test-1.test: A test for bogus SYSTEM identifier
	is added.

	* content-model-1.dat, content-model-2.dat, content-model-3.dat,
	content-model-4.dat: Error messages has been changed.

	* ContentChecker.t: Appends error level to the error
	message if any.

++ whatpm/Whatpm/ChangeLog	30 Jun 2007 13:03:50 -0000
2007-06-30  Wakaba  <wakaba@suika.fam.cx>

	* IMTChecker.pm: Report warning for unregistered
	and private types/subtypes.

	* ContentChecker.pm, HTML.pm.src, IMTChecker.pm,
	URIChecker.pm, HTMLTable.pm: Error messages are now
	consistent; they are all listed in
	<http://suika.fam.cx/gate/2005/sw/Whatpm%20Error%20Types>.

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24