/[suikacvs]/markup/html/whatpm/t/testfiles.pl
Suika

Contents of /markup/html/whatpm/t/testfiles.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Thu Sep 18 07:42:58 2008 UTC (16 years, 1 month ago) by wakaba
Branch: MAIN
File MIME type: text/plain
++ whatpm/t/ChangeLog	18 Sep 2008 07:42:52 -0000
	* LangTag.t: Completely rewritten using |testfiles.pl|.

	* testfiles.pl: New script.

	* langtag-1.dat: Tests for case are added.

2008-09-18  Wakaba  <wakaba@suika.fam.cx>


	* langtag-1.dat: New test data file.
++ whatpm/Whatpm/ChangeLog	18 Sep 2008 07:41:35 -0000
	* LangTag.pm (check_rfc4646_langtag): Check if a tag is in the
	recommended case as per RFC 4646.

2008-09-18  Wakaba  <wakaba@suika.fam.cx>

1 wakaba 1.1 use strict;
2    
3     sub execute_test ($$$) {
4     my $file_name = shift;
5     my $field_props = shift; # {$field_name => {is_prefixed, is_list}}
6     my $test_code = shift;
7    
8     print STDERR "# $file_name\n";
9    
10     my @tests;
11     {
12     open my $file, '<:utf8', $file_name or die "$0: $file_name: $!";
13     local $/ = undef;
14     my $content = <$file>;
15     $content =~ s/\x0D\x0A/\x0A/g;
16     $content =~ tr/\x0D/\x0A/;
17     $content =~ s/^\x0A*#//;
18     $content =~ s/\x0A+\z//;
19     @tests = split /\x0A\x0A#/, $content;
20     }
21    
22     for (@tests) {
23     my %test;
24     for my $v (split /\x0A#/, $_) {
25     my $field_name = '';
26     my @field_opt;
27     if ($v =~ s/^([A-Za-z0-9-]+)//) {
28     $field_name = $1;
29     }
30     if ($v =~ s/^([^\x0A]*)\x0A//) {
31     push @field_opt, grep {length $_} split /[\x09\x20]+/, $1;
32     }
33    
34     if ($field_props->{$field_name}->{is_prefixed}) {
35     $v =~ s/^\| //;
36     $v =~ s/\x0A\| /\x0A/g;
37     }
38     if ($field_props->{$field_name}->{is_list}) {
39     my @v = split /\x0A/, $v;
40     my $field_escaped = (@field_opt and $field_opt[-1] eq 'escaped');
41     if ($field_escaped) {
42     pop @field_opt;
43     for (@v) {
44     s/\\u([0-9A-Fa-f]{4})/chr hex $1/ge;
45     s/\\U([0-9A-Fa-f]{8})/chr hex $1/ge;
46     }
47     }
48    
49     if (defined $test{$field_name}) {
50     warn qq[Duplicate #$field_name field (value "$v")];
51     } else {
52     $test{$field_name} = [\@v, \@field_opt];
53     }
54     } else {
55     my $field_escaped = (@field_opt and $field_opt[-1] eq 'escaped');
56     if ($field_escaped) {
57     pop @field_opt;
58     $v =~ s/\\u([0-9A-Fa-f]{4})/chr hex $1/ge;
59     $v =~ s/\\U([0-9A-Fa-f]{8})/chr hex $1/ge;
60     }
61    
62     if (defined $test{$field_name}) {
63     warn qq[Duplicate #$field_name field (value "$v")];
64     } else {
65     $test{$field_name} = [$v, \@field_opt];
66     }
67     }
68     }
69    
70     $test_code->(\%test);
71     }
72     } # execute_test
73    
74     1;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24