/[suikacvs]/markup/html/whatpm/t/WebIDL.t
Suika

Contents of /markup/html/whatpm/t/WebIDL.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download) (as text)
Sat Aug 2 06:03:26 2008 UTC (16 years, 3 months ago) by wakaba
Branch: MAIN
File MIME type: application/x-troff
++ whatpm/t/ChangeLog	2 Aug 2008 05:57:51 -0000
2008-08-02  Wakaba  <wakaba@suika.fam.cx>

	* WebIDL.t: New test script.

	* webidl/: New directory.

++ whatpm/Whatpm/ChangeLog	2 Aug 2008 06:02:55 -0000
2008-08-02  Wakaba  <wakaba@suika.fam.cx>

	* WebIDL.pm (parse_char_string): Set line/column numbers
	to interface object experimentally.  s/shift/pop/g, shift
	would make things wrong.  Support for interface forward
	declarations was missing.  Broken interface declarations
	with no block were not ignored entirely.
	(Whatpm::WebIDL::Node): New abstract class.  This class
	makes things easier.
	(child_nodes): New attribute.  Unlike DOM's attribute with
	same name, this attribute returns a dead list of nodes for
	simplicity.
	(get_user_data, set_user_data): New methods.
	(Module idl_text): A SPACE character should be inserted
	before the |{| character.
	(Interface idl_text): Support for interface forward declarations.
	(is_forward_declaration): New attribute.

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3    
4     my $DEBUG = $ENV{DEBUG};
5    
6     my $dir_name;
7     my $test_dir_name;
8     BEGIN {
9     $test_dir_name = 't/';
10     $dir_name = 't/webidl/';
11     }
12    
13     use Test;
14     BEGIN { plan tests => 1920 }
15    
16     require Whatpm::WebIDL;
17    
18     for my $file_name (grep {$_} split /\s+/, qq[
19     ${dir_name}webidl-defs.dat
20     ${dir_name}webidl-interface.dat
21     ]) {
22     open my $file, '<', $file_name
23     or die "$0: $file_name: $!";
24     print "# $file_name\n";
25    
26     my $test;
27     my $mode = 'data';
28     my $escaped;
29     while (<$file>) {
30     s/\x0D\x0A/\x0A/;
31     if (/^#data$/) {
32     undef $test;
33     $test->{data} = '';
34     $mode = 'data';
35     undef $escaped;
36     } elsif (/^#data escaped$/) {
37     undef $test;
38     $test->{data} = '';
39     $mode = 'data';
40     $escaped = 1;
41     } elsif (/^#errors$/) {
42     $test->{errors} = [];
43     $mode = 'errors';
44     $test->{data} =~ s/\x0D?\x0A\z//;
45     $test->{data} =~ s/\\u([0-9A-Fa-f]{4})/chr hex $1/ge if $escaped;
46     $test->{data} =~ s/\\U([0-9A-Fa-f]{8})/chr hex $1/ge if $escaped;
47     undef $escaped;
48     } elsif (/^#document$/) {
49     $test->{document} = '';
50     $mode = 'document';
51     undef $escaped;
52     } elsif (/^#document escaped$/) {
53     $test->{document} = '';
54     $mode = 'document';
55     $escaped = 1;
56     } elsif (defined $test->{document} and /^$/) {
57     $test->{document} =~ s/\\u([0-9A-Fa-f]{4})/chr hex $1/ge if $escaped;
58     $test->{document} =~ s/\\U([0-9A-Fa-f]{8})/chr hex $1/ge if $escaped;
59     test ($test);
60     undef $test;
61     } elsif (defined $test->{data} and /^$/) {
62     test ($test);
63     undef $test;
64     } else {
65     if ($mode eq 'data' or $mode eq 'document') {
66     $test->{$mode} .= $_;
67     } elsif ($mode eq 'errors') {
68     tr/\x0D\x0A//d;
69     push @{$test->{errors}}, $_;
70     }
71     }
72     }
73     test ($test);
74     }
75    
76     sub test ($) {
77     my $test = shift;
78    
79     $test->{document} =~ s/^\| //;
80     $test->{document} =~ s/[\x0D\x0A]\| /\x0A/g;
81    
82     my @errors;
83    
84     my $onerror = sub {
85     my %opt = @_;
86     push @errors, join ';',
87     ($opt{node} ? $opt{node}->get_user_data ('manakai_source_line') || $opt{line} : $opt{line} . '.' . $opt{column}),
88     $opt{type}, $opt{level};
89     };
90    
91     my $p = Whatpm::WebIDL::Parser->new;
92     my $idl = $p->parse_char_string ($test->{data}, $onerror);
93    
94     if (defined $test->{errors}) {
95     $idl->check ($onerror);
96    
97     ok join ("\n", sort {$a cmp $b} @errors),
98     join ("\n", sort {$a cmp $b} @{$test->{errors}}), $test->{data};
99     }
100    
101     if (defined $test->{document}) {
102     ok $idl->idl_text, $test->{document}, $test->{data};
103     }
104     } # test
105    
106     ## License: Public Domain.
107     ## $Date: 2008/04/13 10:36:41 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24