/[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.13 - (hide annotations) (download) (as text)
Sun Jun 24 14:24:22 2007 UTC (18 years ago) by wakaba
Branch: MAIN
Changes since 1.12: +2 -1 lines
File MIME type: application/x-troff
++ whatpm/t/ChangeLog	24 Jun 2007 14:19:51 -0000
	* content-model-1.dat: Tests for |footer|
	content model are added.

	* content-model-2.dat: Tests for |ping|
	and |tabindex| attributes are added.  Tests for |datetime|
	attribute of |ins| and |del| elements are added.

	* content-model-4.dat: New test data.

	* ContentChecker.t: |content-model-4.dat| is added.

2007-06-24  Wakaba  <wakaba@suika.fam.cx>

++ whatpm/Whatpm/ChangeLog	24 Jun 2007 14:20:06 -0000
	* URIChecker.pm (check_iri_reference): A |decode| method name was
	incorrect.

	* ContentChecker.pm: Support for the |footer| element.
	Check URI syntax for space-separated URI attributes.
	Support for the |tabindex| attribute.  Support
	for |datetime| attribute.

2007-06-24  Wakaba  <wakaba@suika.fam.cx>

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     push @error, get_node_path ($opt{node}) . ';' . $opt{type};
80     });
81    
82     ok join ("\n", sort {$a cmp $b} @error),
83     join ("\n", sort {$a cmp $b} @{$test->{errors}}), $test->{data};
84     } # test
85    
86     sub get_node_path ($) {
87     my $node = shift;
88     my @r;
89     while (defined $node) {
90     my $rs;
91     if ($node->node_type == 1) {
92     $rs = $node->manakai_local_name;
93 wakaba 1.4 $node = $node->parent_node;
94 wakaba 1.3 } elsif ($node->node_type == 2) {
95     $rs = '@' . $node->manakai_local_name;
96 wakaba 1.4 $node = $node->owner_element;
97 wakaba 1.1 } elsif ($node->node_type == 3) {
98     $rs = '"' . $node->data . '"';
99 wakaba 1.4 $node = $node->parent_node;
100 wakaba 1.1 } elsif ($node->node_type == 9) {
101     $rs = '';
102 wakaba 1.4 $node = $node->parent_node;
103 wakaba 1.1 } else {
104     $rs = '#' . $node->node_type;
105 wakaba 1.4 $node = $node->parent_node;
106 wakaba 1.1 }
107     unshift @r, $rs;
108     }
109     return join '/', @r;
110     } # get_node_path
111    
112     ## License: Public Domain.
113 wakaba 1.13 ## $Date: 2007/06/23 02:59:48 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24