5 use C4
::Interface
::CGI
::Output
; #
8 use vars qw( $loaded );
13 'Normal HTML without meta tag',
14 sub { guesscharset($_[0]) },
17 <title>control case</title>
20 'Result of guesscharset with normal HTML with irrelevant meta tag',
21 sub { guesscharset
($_[0]) },
24 <meta http-equiv="Content-Language" content="zh-TW">
27 'Result of guesstype with normal HTML with irrelevant meta tag',
28 sub { guesstype
($_[0]) },
31 <meta http-equiv="Content-Language" content="zh-TW">
34 'Result of guesscharset with normal HTML with relevant meta tag',
35 sub { guesscharset
($_[0]) },
38 <meta http-equiv="Content-Type" content="text/html; charset=big5">
41 'Result of guesstype with normal HTML with relevant meta tag',
42 sub { guesstype
($_[0]) },
43 'text/html; charset=big5',
45 <meta http-equiv="Content-Type" content="text/html; charset=big5">
48 'Variant 1 using single quotes',
49 sub { guesstype
($_[0]) },
50 'text/html; charset=iso-2022-jp',
52 <meta http-equiv="Content-Type" content='text/html; charset=iso-2022-jp'>
55 'Variant 2 using single quotes',
56 sub { guesstype
($_[0]) },
57 'text/html; charset=utf-8',
59 <meta http-equiv='Content-Type' content="text/html; charset=utf-8">
62 'Unquoted Content-Type',
63 sub { guesstype
($_[0]) },
64 'text/html; charset=big5',
66 <meta http-equiv=Content-Type content="text/html; charset=big5">
70 sub { guesstype
($_[0]) },
71 'text/html; charset=iso-8859-2',
73 <meta http-equiv=Content-Type content="text/html; charset=iso-8859-2" />
76 'Expected attributes in reverse order',
77 sub { guesstype
($_[0]) },
78 'text/html; charset=big5',
80 <meta content="text/html; charset=big5" http-equiv="Content-Type">
83 'Extra whitespace at end',
84 sub { guesstype
($_[0]) },
85 'text/html; charset=big5',
87 <meta http-equiv="Content-Type" content="text/html; charset=big5" >
91 sub { guesstype
($_[0]) },
92 'text/html; charset=big5',
95 http-equiv="Content-Type"
96 content="text/html; charset=big5"
100 # FIXME - THIS IS NOT A WELL-WRITTEN TEST CASE!!!
101 'With surrounding HTML',
102 sub { guesstype
($_[0]) },
103 'text/html; charset=us-ascii',
107 <title>Test case with surrounding HTML</title>
108 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
111 The return value should not be contaiminated with any surround HTML
112 FIXME: Auth.pm returns in code that can contaminate the charset
113 FIXME: if we do not explicitly disallow whitespace in the charset
121 BEGIN { $| = 1; printf "1..%d\n", scalar(@tests); }
122 END {print "not ok 1\n" unless $loaded;}
126 # Run all tests in sequence
127 for (my $i = 1; $i <= scalar @tests; $i += 1) {
128 my $test = $tests[$i - 1];
129 my($title, $f, $expected, $input) = @
$test;
130 die "not ok $i (malformed test case)\n"
131 unless @
$test == 4 && ref $f eq 'CODE';
133 my $output = &$f($input);
135 (!defined $output && !defined $expected)
136 || (defined $output && defined $expected && $output eq $expected)
138 print "ok $i - $title\n";
140 print "not ok $i - $title: got ",
141 (defined $output?
"\"$output\"": 'undef'),
143 (defined $expected?
"\"$expected\"": 'undef'),