/[suikacvs]/markup/html/whatpm/t/SWML-Parser.t
Suika

Contents of /markup/html/whatpm/t/SWML-Parser.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download) (as text)
Fri Nov 7 04:03:16 2008 UTC (16 years, 8 months ago) by wakaba
Branch: MAIN
File MIME type: application/x-troff
++ whatpm/t/ChangeLog	7 Nov 2008 04:02:56 -0000
2008-11-07  Wakaba  <wakaba@suika.fam.cx>

	* Makefile: A rule for SWML testing is added.

	* SWML-Parser.t: New file.

	* swml/: New directory.

++ whatpm/t/swml/ChangeLog	7 Nov 2008 04:01:29 -0000
2008-11-07  Wakaba  <wakaba@suika.fam.cx>

	* structs-1.dat: New file.

	* ChangeLog: New file.


++ whatpm/Whatpm/SWML/ChangeLog	7 Nov 2008 04:02:27 -0000
2008-11-07  Wakaba  <wakaba@suika.fam.cx>

	* Parser.pm (parse_char_string): Don't use attributes and methods
	not supported by NanoDOM.

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3    
4     my $test_dir_name = 't/swml/';
5    
6     use Test;
7     BEGIN { plan tests => 1573 }
8    
9     use Data::Dumper;
10     $Data::Dumper::Useqq = 1;
11     sub Data::Dumper::qquote {
12     my $s = shift;
13     $s =~ s/([^\x20\x21-\x26\x28-\x5B\x5D-\x7E])/sprintf '\x{%02X}', ord $1/ge;
14     return q<qq'> . $s . q<'>;
15     } # Data::Dumper::qquote
16    
17     use Whatpm::SWML::Parser;
18     use Whatpm::NanoDOM;
19     use Whatpm::HTML::Dumper qw/dumptree/;
20    
21     sub test ($) {
22     my $test = shift;
23    
24     my $doc = Whatpm::NanoDOM::Document->new;
25     my @errors;
26    
27     $SIG{INT} = sub {
28     print scalar dumptree ($doc);
29     exit;
30     };
31    
32     my $onerror = sub {
33     my %opt = @_;
34     push @errors, join ';',
35     $opt{token}->{line} || $opt{line},
36     $opt{token}->{column} || $opt{column},
37     $opt{type},
38     defined $opt{text} ? $opt{text} : '',
39     defined $opt{value} ? $opt{value} : '',
40     $opt{level};
41     };
42    
43     my $p = Whatpm::SWML::Parser->new;
44     $p->parse_char_string ($test->{data}->[0] => $doc, $onerror);
45     my $result = dumptree ($doc);
46    
47     warn "No #errors section ($test->{data}->[0])" unless $test->{errors};
48    
49     @errors = sort {$a cmp $b} @errors;
50     @{$test->{errors}->[0]} = sort {$a cmp $b} @{$test->{errors}->[0] ||= []};
51    
52     ok join ("\n", @errors), join ("\n", @{$test->{errors}->[0] or []}),
53     'Parse error: ' . Data::Dumper::qquote ($test->{data}->[0]);
54    
55     $test->{document}->[0] .= "\x0A" if length $test->{document}->[0];
56     ok $result, $test->{document}->[0],
57     'Document tree: ' . Data::Dumper::qquote ($test->{data}->[0]);
58     } # test
59    
60     my @FILES = grep {$_} split /\s+/, qq[
61     ${test_dir_name}structs-1.dat
62     ];
63    
64     require 't/testfiles.pl';
65     execute_test ($_, {
66     data => {is_prefixed => 1},
67     errors => {is_list => 1},
68     document => {is_prefixed => 1},
69     }, \&test) for @FILES;
70    
71     ## License: Public Domain.
72     ## $Date: 2008/10/20 04:21:19 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24