X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=t%2FCharset.t;h=7de3414a85ba38f8c42cf3e086989f0bd12af5ce;hb=f846e9aa76d98ea357f89230d0f7317826605903;hp=167235a97f76dae929841cc83b02c5ca1e32c2b5;hpb=ea50c2acb68494b8a4dfd36d7dbf8c488ee8b4cf;p=koha.git diff --git a/t/Charset.t b/t/Charset.t old mode 100644 new mode 100755 index 167235a97f..7de3414a85 --- a/t/Charset.t +++ b/t/Charset.t @@ -1,147 +1,20 @@ -use strict; -use C4::Charset; +#!/usr/bin/perl -use vars qw( @tests ); -use vars qw( $loaded ); +use strict; +use warnings; +use Test::More tests => 6; BEGIN { - @tests = ( - [ - 'Normal HTML without meta tag', - sub { C4::Charset::guesscharset($_[0]) }, - undef, - <control case -EOF - ], [ - 'Result of guesscharset with normal HTML with irrelevant meta tag', - sub { C4::Charset::guesscharset($_[0]) }, - undef, - < -EOF - ], [ - 'Result of guesscharset with normal HTML with irrelevant meta tag', - sub { C4::Charset::guesstype($_[0]) }, - undef, - < -EOF - ], [ - 'Result of guesscharset with normal HTML with relevant meta tag', - sub { C4::Charset::guesscharset($_[0]) }, - 'big5', - < -EOF - ], [ - 'Result of guesstype with normal HTML with relevant meta tag', - sub { C4::Charset::guesstype($_[0]) }, - 'text/html; charset=big5', - < -EOF - ], [ - 'Variant 1 using single quotes', - sub { C4::Charset::guesstype($_[0]) }, - 'text/html; charset=iso-2022-jp', - < -EOF - ], [ - 'Variant 2 using single quotes', - sub { C4::Charset::guesstype($_[0]) }, - 'text/html; charset=utf-8', - < -EOF - ], [ - 'Unquoted Content-Type', - sub { C4::Charset::guesstype($_[0]) }, - 'text/html; charset=big5', - < -EOF - ], [ - 'XML syntax', - sub { C4::Charset::guesstype($_[0]) }, - 'text/html; charset=iso-8859-2', - < -EOF - ], [ - 'Expected attributes in reverse order', - sub { C4::Charset::guesstype($_[0]) }, - 'text/html; charset=big5', - < -EOF - ], [ - 'Extra whitespace at end', - sub { C4::Charset::guesstype($_[0]) }, - 'text/html; charset=big5', - < -EOF - ], [ - 'Multiple lines', - sub { C4::Charset::guesstype($_[0]) }, - 'text/html; charset=big5', - < -EOF - ], [ - 'With surrounding HTML', - sub { C4::Charset::guesstype($_[0]) }, - 'text/html; charset=us-ascii', - < - -Test case with surrounding HTML - - - -The return value should not be contaiminated with any surround HTML -FIXME: Auth.pm returns in code that can contaminate the charset -FIXME: if we do not explicitly disallow whitespace in the charset - - -EOF - ], -); + use_ok('C4::Charset'); } -BEGIN { $| = 1; printf "1..%d\n", scalar(@tests); } -END {print "not ok 1\n" unless $loaded;} -$loaded = 1; - - -# Run all tests in sequence -for (my $i = 1; $i <= scalar @tests; $i += 1) { - my $test = $tests[$i - 1]; - my($title, $f, $expected, $input) = @$test; - die "not ok $i (malformed test case)\n" - unless @$test == 4 && ref $f eq 'CODE'; - - my $output = &$f($input); - if ( - (!defined $output && !defined $expected) - || (defined $output && defined $expected && $output eq $expected) - ) { - print "ok $i ($title)\n"; - } else { - print "not ok $i ($title: got ", - (defined $output? "\"$output\"": 'undef'), - ', expected ', - (defined $expected? "\"$expected\"": 'undef'), - ")\n"; - } -} - - - +my $octets = "abc"; +ok(IsStringUTF8ish($octets), "verify octets are valid UTF-8 (ASCII)"); +$octets = "flamb\c3\a9"; +ok(!utf8::is_utf8($octets), "verify that string does not have Perl UTF-8 flag on"); +ok(IsStringUTF8ish($octets), "verify octets are valid UTF-8 (LATIN SMALL LETTER E WITH ACUTE)"); +ok(!utf8::is_utf8($octets), "verify that IsStringUTF8ish does not magically turn Perl UTF-8 flag on"); +$octets = "a\xc2" . "c"; +ok(!IsStringUTF8ish($octets), "verify octets are not valid UTF-8");