/[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.27 - (hide annotations) (download) (as text)
Thu Mar 20 08:54:00 2008 UTC (17 years, 4 months ago) by wakaba
Branch: MAIN
Changes since 1.26: +2 -3 lines
File MIME type: application/x-troff
++ whatpm/t/ChangeLog	20 Mar 2008 08:53:32 -0000
	* ContentCheker.t: Replace dummy error type for subdoc
	checking invocations to ";SUBDOC".

	* content-model-1.dat, content-model-2.dat: Test
	results revised to support the aforementioned change.

	* content-model-atom-1.dat: Test results revised
	so that |type=html| in Text construct is now
	tested whether the subdoc code is invoked.

2008-03-20  Wakaba  <wakaba@suika.fam.cx>

	* content-model-atom-1.dat: Test data on cases of
	missing |atom:summary| in |atom:entry| are added.

2008-03-20  Wakaba  <wakaba@suika.fam.cx>

++ whatpm/Whatpm/ContentChecker/ChangeLog	20 Mar 2008 08:38:25 -0000
	* Atom.pm: Raise an error if required |atom:summary|
	element is missing from an |atom:entry| element.

2008-03-20  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 wakaba 1.27 push @error, get_node_path ($opt->{container_node}) . ';SUBDOC';
94 wakaba 1.1 });
95    
96     ok join ("\n", sort {$a cmp $b} @error),
97     join ("\n", sort {$a cmp $b} @{$test->{errors}}), $test->{data};
98     } # test
99    
100     sub get_node_path ($) {
101     my $node = shift;
102     my @r;
103     while (defined $node) {
104     my $rs;
105     if ($node->node_type == 1) {
106     $rs = $node->manakai_local_name;
107 wakaba 1.4 $node = $node->parent_node;
108 wakaba 1.3 } elsif ($node->node_type == 2) {
109     $rs = '@' . $node->manakai_local_name;
110 wakaba 1.4 $node = $node->owner_element;
111 wakaba 1.1 } elsif ($node->node_type == 3) {
112     $rs = '"' . $node->data . '"';
113 wakaba 1.4 $node = $node->parent_node;
114 wakaba 1.1 } elsif ($node->node_type == 9) {
115     $rs = '';
116 wakaba 1.4 $node = $node->parent_node;
117 wakaba 1.1 } else {
118     $rs = '#' . $node->node_type;
119 wakaba 1.4 $node = $node->parent_node;
120 wakaba 1.1 }
121     unshift @r, $rs;
122     }
123     return join '/', @r;
124     } # get_node_path
125    
126     ## License: Public Domain.
127 wakaba 1.27 ## $Date: 2008/02/24 01:38:36 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24