/[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.10 - (hide annotations) (download) (as text)
Wed May 30 12:24:50 2007 UTC (18 years, 1 month ago) by wakaba
Branch: MAIN
Changes since 1.9: +2 -3 lines
File MIME type: application/x-troff
++ whatpm/t/ChangeLog	30 May 2007 12:23:55 -0000
2007-05-30  Wakaba  <wakaba@suika.fam.cx>

	* ContentChecker.t: Don't use obsolete |new| method.

	* tree-test-1.dat: Nested form test added.

++ whatpm/Whatpm/ChangeLog	30 May 2007 12:24:39 -0000
2007-05-30  Wakaba  <wakaba@suika.fam.cx>

	* HTML.pm.src: |<form><form>| went to inifinite loop.

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3    
4     use Test;
5 wakaba 1.9 BEGIN { plan tests => 864 }
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     ];
12 wakaba 1.1
13     require Whatpm::ContentChecker;
14    
15     ## ISSUE: Currently we require manakai XML parser to test arbitrary XML tree.
16     use lib qw[/home/wakaba/work/manakai/lib];
17     require Message::DOM::DOMCore;
18     require Message::DOM::XMLParser;
19 wakaba 1.4 require Whatpm::HTML;
20     require Whatpm::NanoDOM;
21 wakaba 1.1
22     my $dom = $Message::DOM::DOMImplementationRegistry->get_dom_implementation;
23     my $parser = $dom->create_ls_parser (1);
24    
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     $doc = $parser->parse ({string_data => $test->{data}});
66     ## NOTE: There should be no well-formedness error; if there is,
67     ## then it is an error of the test case itself.
68     } else {
69     $doc = Whatpm::NanoDOM::Document->new;
70     Whatpm::HTML->parse_string ($test->{data} => $doc);
71     }
72 wakaba 1.1
73     my @error;
74 wakaba 1.10 Whatpm::ContentChecker->check_element
75 wakaba 1.1 ($doc->document_element, sub {
76     my %opt = @_;
77     push @error, get_node_path ($opt{node}) . ';' . $opt{type};
78     });
79    
80     ok join ("\n", sort {$a cmp $b} @error),
81     join ("\n", sort {$a cmp $b} @{$test->{errors}}), $test->{data};
82     } # test
83    
84     sub get_node_path ($) {
85     my $node = shift;
86     my @r;
87     while (defined $node) {
88     my $rs;
89     if ($node->node_type == 1) {
90     $rs = $node->manakai_local_name;
91 wakaba 1.4 $node = $node->parent_node;
92 wakaba 1.3 } elsif ($node->node_type == 2) {
93     $rs = '@' . $node->manakai_local_name;
94 wakaba 1.4 $node = $node->owner_element;
95 wakaba 1.1 } elsif ($node->node_type == 3) {
96     $rs = '"' . $node->data . '"';
97 wakaba 1.4 $node = $node->parent_node;
98 wakaba 1.1 } elsif ($node->node_type == 9) {
99     $rs = '';
100 wakaba 1.4 $node = $node->parent_node;
101 wakaba 1.1 } else {
102     $rs = '#' . $node->node_type;
103 wakaba 1.4 $node = $node->parent_node;
104 wakaba 1.1 }
105     unshift @r, $rs;
106     }
107     return join '/', @r;
108     } # get_node_path
109    
110     ## License: Public Domain.
111 wakaba 1.10 ## $Date: 2007/05/27 10:28:01 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24