/[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.16 - (hide annotations) (download) (as text)
Mon Jul 16 07:48:19 2007 UTC (18 years ago) by wakaba
Branch: MAIN
Changes since 1.15: +2 -2 lines
File MIME type: application/x-troff
++ whatpm/t/ChangeLog	16 Jul 2007 07:48:16 -0000
	* content-model-1.dat, content-model-2.dat: Add "in XML:charset"
	error for test data that has |charset| in XML context.

	* content-model-2.dat: Test data for "in XML:charset", "in XML:lang",
	and "in HTML:xml:lang" are added.

2007-07-16  Wakaba  <wakaba@suika.fam.cx>

++ whatpm/Whatpm/ChangeLog	16 Jul 2007 07:33:46 -0000
	* ContentChecker.pm: Report error if |xml:lang|
	in HTML, |lang| in XML, |xmlns| in XML, and |meta| |charset|
	in XML.

	* NanoDOM.pm (Attr.owner_document): New attribute.

2007-07-16  Wakaba  <wakaba@suika.fam.cx>

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24