/[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.31 - (hide annotations) (download) (as text)
Sat Aug 30 10:26:39 2008 UTC (16 years, 10 months ago) by wakaba
Branch: MAIN
Changes since 1.30: +3 -2 lines
File MIME type: application/x-troff
++ whatpm/t/ChangeLog	30 Aug 2008 10:22:30 -0000
	* ContentChecker.t: Updated for latest version of the
	Whatpm::ContentChecker module.

	* content-model-1.dat, content-model-2.dat, content-model-3.dat,
	content-model-4.dat, content-model-6.dat, content-model-atom-1.dat,
	content-model-atom-2.dat, content-model-atom-threading-1.dat,
	table-1.dat: Results updated.

2008-08-30  Wakaba  <wakaba@suika.fam.cx>

++ whatpm/Whatpm/ChangeLog	30 Aug 2008 10:24:24 -0000
	* ContentChecker.pm: Error level definition for |xml_id_error|
	was missing.

	* URIChecker.pm: The end of the URL should be marked as the
	error location for an empty path error.  The position
	between the userinfo and the port components should be
	marked as the error location for an empty host error.

2008-08-30  Wakaba  <wakaba@suika.fam.cx>

++ whatpm/Whatpm/ContentChecker/ChangeLog	30 Aug 2008 10:26:28 -0000
2008-08-30  Wakaba  <wakaba@suika.fam.cx>

	* Atom.pm: s/element missing/child element missing/ for
	consistency.

	* HTML.pm: Typos fixed.
	(pre): "No significant content" error was unintentionally
	disabled.  s/element missing/child element missing/ for
	consistency.

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24