File: EUCJPASCII.t

package info (click to toggle)
libencode-eucjpascii-perl 0.03-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 832 kB
  • sloc: perl: 199; makefile: 3
file content (43 lines) | stat: -rw-r--r-- 958 bytes parent folder | download
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
use strict;
# Adjust the number here!
use Test::More tests => 28;

use_ok('Encode');
use_ok('Encode::EUCJPASCII');
test('eucjp');
test('7bit');
# Add more test here!

sub test {
    my $in = shift;
    local($/) = '';
    open WORDS, "testin/$in.txt" or die "open: $!";
    while (<WORDS>) {
	next if /^#/;
	my @w = split /\n/, $_;
	my ($renc, $rdec) = split /,/, shift @w;
	my $cset = shift @w;
	my $byte = eval(shift @w);
	die $@ if $@ or !$byte;
	my $uni = eval(join "\n", @w);
	die $@ if $@ or !$uni;
	my $enc = encode($cset, $uni);
	my $dec = decode($cset, $byte);

	$enc = sprintf "\\x%*v02X", "\\x", $enc;
	$byte = sprintf "\\x%*v02X", "\\x", $byte;
	$dec = sprintf "\\x{%*v04X}", "}\\x{", $dec;
	$uni = sprintf "\\x{%*v04X}", "}\\x{", $uni;

	if ($renc eq 'GOOD') {
	    is($enc, $byte);
	} elsif ($renc eq 'BAD') {
	    isnt($enc, $byte);
	}
	if ($rdec eq 'GOOD') {
	    is($dec, $uni);
	} elsif ($rdec eq 'BAD') {
	    isnt($dec, $uni);
	}
    }
}