File: 03-encode.t

package info (click to toggle)
libtext-kakasi-perl 2.04-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 164 kB
  • sloc: perl: 707; makefile: 3
file content (49 lines) | stat: -rw-r--r-- 1,190 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl
# $Id: 03-encode.t,v 2.0 2003/05/22 18:19:11 dankogai Exp $
# 
# by Dan Kogai <dankogai@dan.co.jp>
#
# This document is written in UTF-8
#


BEGIN{
    use strict;
    unshift @INC, 't';		# for MyTestUtils.pm
    require MyTestUtils;
    eval { require Text::Kakasi };
    unless ($Text::Kakasi::HAS_ENCODE){
	print "1..0 # Encode not supported.\n"; exit;
    } else {
	binmode STDOUT => ':utf8';
    }
	
}

$seq = 1; 
$test = 65;
$| = 1;

print "1..$test\n";
ok($Text::Kakasi::HAS_ENCODE, "encode support");


eval { Encode->import(qw/encode decode decode_utf8/) };

my $src_utf8 =
    decode_utf8("漢字カタカナひらがなの混じったtext.");
my $dst_utf8 = 
    decode_utf8("漢字[kanji]カタカナひらがなの混じ[maji]ったtext.");
my $k = Text::Kakasi->new;

my @enc = qw(utf8 shiftjis euc-jp 7bit-jis
	     UTF-16BE UTF-16LE UTF-32BE UTF-32LE );

for my $in (@enc) {
    my $in_src = $in eq 'utf8' ? $src_utf8 : encode($in, $src_utf8);
    for my $out (@enc) {
	my $out_dst = $out eq 'utf8' ? $dst_utf8 : encode($out, $dst_utf8);
	my $result = $k->set("-i$in", "-o$out", qw/-Ja -f/)->get($in_src);
	ok(($result eq $out_dst), "-i$in -o$out");
    }
}