Parent Directory
|
Revision Log
++ whatpm/t/ChangeLog 29 Jan 2008 22:14:49 -0000 2008-01-30 Wakaba <wakaba@suika.fam.cx> * css-generated.dat: New test data for 'counter-increment', 'content', and 'counter-reset' are added. * CSS-Parser-1.t: 'counter-reset' and 'counter-increment' are added. ++ whatpm/Whatpm/CSS/ChangeLog 29 Jan 2008 22:13:54 -0000 2008-01-30 Wakaba <wakaba@suika.fam.cx> * Parser.pm ($default_serializer): New 'ADDCOUNTER' and 'SETCOUNTER' types supported. ('content'): 'counter()' and 'counters()' are supported iff the property 'counter-reset' is supported. ('counter-reset', 'counter-increment'): Implemented.
| 1 | wakaba | 1.1 | #!/usr/bin/perl |
| 2 | use strict; | ||
| 3 | |||
| 4 | use lib qw[/home/wakaba/work/manakai2/lib]; ## TODO: ... | ||
| 5 | |||
| 6 | use Test; | ||
| 7 | |||
| 8 | BEGIN { plan tests => 548 } | ||
| 9 | |||
| 10 | require Whatpm::CSS::Parser; | ||
| 11 | require Message::DOM::Window; | ||
| 12 | |||
| 13 | require Message::DOM::DOMImplementation; | ||
| 14 | my $dom = Message::DOM::DOMImplementation->new; | ||
| 15 | |||
| 16 | my $DefaultComputed; | ||
| 17 | my $DefaultComputedText; | ||
| 18 | |||
| 19 | for my $file_name (map {"t/$_"} qw( | ||
| 20 | css-1.dat | ||
| 21 | wakaba | 1.4 | css-visual.dat |
| 22 | wakaba | 1.6 | css-generated.dat |
| 23 | wakaba | 1.9 | css-paged.dat |
| 24 | css-text.dat | ||
| 25 | wakaba | 1.7 | css-font.dat |
| 26 | wakaba | 1.10 | css-table.dat |
| 27 | css-interactive.dat | ||
| 28 | wakaba | 1.1 | )) { |
| 29 | print "# $file_name\n"; | ||
| 30 | wakaba | 1.13 | open my $file, '<:utf8', $file_name or die "$0: $file_name: $!"; |
| 31 | wakaba | 1.1 | |
| 32 | my $all_test = {document => {}, test => []}; | ||
| 33 | my $test; | ||
| 34 | my $mode = 'data'; | ||
| 35 | my $doc_id; | ||
| 36 | my $selectors; | ||
| 37 | while (<$file>) { | ||
| 38 | s/\x0D\x0A/\x0A/; | ||
| 39 | if (/^#data$/) { | ||
| 40 | undef $test; | ||
| 41 | $test->{data} = ''; | ||
| 42 | push @{$all_test->{test}}, $test; | ||
| 43 | $mode = 'data'; | ||
| 44 | } elsif (/#(csstext|cssom)$/) { | ||
| 45 | $test->{$1} = ''; | ||
| 46 | $mode = $1; | ||
| 47 | } elsif (/#(computed(?>text)?) (\S+) (.+)$/) { | ||
| 48 | $test->{$1}->{$doc_id = $2}->{$selectors = $3} = ''; | ||
| 49 | $mode = $1; | ||
| 50 | } elsif (/^#html (\S+)$/) { | ||
| 51 | undef $test; | ||
| 52 | $test->{format} = 'html'; | ||
| 53 | $test->{data} = ''; | ||
| 54 | $all_test->{document}->{$1} = $test; | ||
| 55 | $mode = 'data'; | ||
| 56 | wakaba | 1.2 | } elsif (/^#errors$/) { |
| 57 | $test->{errors} = []; | ||
| 58 | $mode = 'errors'; | ||
| 59 | $test->{data} =~ s/\x0D?\x0A\z//; | ||
| 60 | wakaba | 1.4 | } elsif (/^#option q$/) { |
| 61 | $test->{option}->{parse_mode} = 'q'; | ||
| 62 | wakaba | 1.1 | } elsif (defined $test->{data} and /^$/) { |
| 63 | undef $test; | ||
| 64 | } else { | ||
| 65 | if ({data => 1, cssom => 1, csstext => 1}->{$mode}) { | ||
| 66 | $test->{$mode} .= $_; | ||
| 67 | } elsif ($mode eq 'computed' or $mode eq 'computedtext') { | ||
| 68 | $test->{$mode}->{$doc_id}->{$selectors} .= $_; | ||
| 69 | wakaba | 1.2 | } elsif ($mode eq 'errors') { |
| 70 | tr/\x0D\x0A//d; | ||
| 71 | push @{$test->{errors}}, $_; | ||
| 72 | wakaba | 1.1 | } else { |
| 73 | die "Line $.: $_"; | ||
| 74 | } | ||
| 75 | } | ||
| 76 | } | ||
| 77 | |||
| 78 | for my $data (values %{$all_test->{document}}) { | ||
| 79 | if ($data->{format} eq 'html') { | ||
| 80 | my $doc = $dom->create_document; | ||
| 81 | $doc->manakai_is_html (1); | ||
| 82 | $doc->inner_html ($data->{data}); | ||
| 83 | $data->{document} = $doc; | ||
| 84 | } else { | ||
| 85 | die "Test data format $data->{format} is not supported"; | ||
| 86 | } | ||