/[suikacvs]/markup/html/whatpm/t/CSS-MediaQuery.t
Suika

Contents of /markup/html/whatpm/t/CSS-MediaQuery.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download) (as text)
Fri Feb 8 13:37:58 2008 UTC (17 years, 5 months ago) by wakaba
Branch: MAIN
CVS Tags: HEAD
File MIME type: application/x-troff
++ whatpm/t/ChangeLog	8 Feb 2008 13:37:13 -0000
2008-02-08  Wakaba  <wakaba@suika.fam.cx>

	* CSS-MediaQuery.t, mq-1.dat: New files.

++ whatpm/Whatpm/CSS/ChangeLog	8 Feb 2008 13:37:45 -0000
2008-02-08  Wakaba  <wakaba@suika.fam.cx>

	* MediaQueryParser.pm, MediaQuerySerializer.pm: New Perl modules.

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3    
4     ## Test for Whatpm::CSS::MediaQueryParser and Whatpm::CSS::MediaQuerySerializer
5    
6     use Test;
7    
8     BEGIN { plan tests => 28 }
9    
10     require Whatpm::CSS::MediaQueryParser;
11     require Whatpm::CSS::MediaQuerySerializer;
12    
13     for my $file_name (map {"t/$_"} qw(
14     mq-1.dat
15     )) {
16     print "# $file_name\n";
17     open my $file, '<:utf8', $file_name or die "$0: $file_name: $!";
18    
19     my $all_test = {test => []};
20     my $test;
21     my $mode = 'data';
22     my $doc_id;
23     my $selectors;
24     while (<$file>) {
25     s/\x0D\x0A/\x0A/;
26     if (/^#data$/) {
27     undef $test;
28     $test->{data} = '';
29     push @{$all_test->{test}}, $test;
30     $mode = 'data';
31     } elsif (/#mediatext$/) {
32     $test->{mediatext} = '';
33     $mode = 'mediatext';
34     } elsif (/^#errors$/) {
35     $test->{errors} = [];
36     $mode = 'errors';
37     $test->{data} =~ s/\x0D?\x0A\z//;
38     } elsif (defined $test->{data} and /^$/) {
39     undef $test;
40     } else {
41     if ({data => 1, mediatext => 1}->{$mode}) {
42     $test->{$mode} .= $_;
43     } elsif ($mode eq 'errors') {
44     tr/\x0D\x0A//d;
45     push @{$test->{errors}}, $_;
46     } else {
47     die "Line $.: $_";
48     }
49     }
50     }
51    
52     my $p = Whatpm::CSS::MediaQueryParser->new;
53     for my $test (@{$all_test->{test}}) {
54     my @actual_error;
55     $p->{onerror} = sub {
56     my (%opt) = @_;
57     my $uri = ${$opt{uri}};
58     $uri =~ s[^thismessage:/][];
59     push @actual_error, join ';',
60     $uri, $opt{token}->{line}, $opt{token}->{column},
61     $opt{level},
62     $opt{type} . (defined $opt{value} ? ';'.$opt{value} : '');
63     };
64    
65     my $mq = $p->parse_char_string ($test->{data});
66    
67     ok ((join "\n", @actual_error), (join "\n", @{$test->{errors} or []}),
68     "#result ($test->{data})");
69    
70     if (defined $test->{mediatext}) {
71     my $mt = Whatpm::CSS::MediaQuerySerializer->serialize_media_query ($mq);
72     ok $mt."\n", $test->{mediatext}, "#mediatext ($test->{data})";
73     }
74     }
75     }

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24