File: new.t

package info (click to toggle)
libjcode-pm-perl 2.07-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,440 kB
  • sloc: perl: 14,814; ansic: 11,032; makefile: 3
file content (50 lines) | stat: -rw-r--r-- 1,042 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/perl

use strict;
use Jcode;
use Test;
BEGIN { plan tests => 41 }

my $seq = 0;
sub myok{ # overloads Test::ok;
    my ($a, $b, $comment) = @_;
    print "not " if $a ne $b;
    ++$seq;
    print "ok $seq # $comment\n";
}

my %code2str;
for my $enc (qw/euc sjis jis utf8 ucs2/){
    my $file = "t/table.$enc";
    open F, $file or die "$file:$!";
    binmode F;
    read F, $code2str{$enc}, -s $file;
    close F;
}
my @code2str = keys %code2str;
check("ascii|x0208");
%code2str = ();
for my $enc (qw/euc jis utf8 ucs2/){
    my $file = "t/x0212.$enc";
    open F, $file or die "$file:$!";
    binmode F;
    read F, $code2str{$enc}, -s $file;
    close F;
}
@code2str = keys %code2str;
check("x0212");

sub check{
    my $table = shift;
    for my $icode (@code2str){
	for my $ocode (@code2str){
	    my $str = $code2str{$icode};
	    my $obj = Jcode->new($str, $icode);
	    my $evo = eval qq{\$obj->$ocode}; # for perl 5.00x
	    myok($evo, $code2str{$ocode},
		 "$table:Jcode->new(\$str, $icode)->$ocode");
	}
    }
}

__END__