1# $Id: enc_module.t,v 2.2 2013/02/18 02:23:56 dankogai Exp $ 2# This file is in euc-jp 3BEGIN { 4 require Config; import Config; 5 if ($Config{'extensions'} !~ /\bEncode\b/) { 6 print "1..0 # Skip: Encode was not built\n"; 7 exit 0; 8 } 9 unless (find PerlIO::Layer 'perlio') { 10 print "1..0 # Skip: PerlIO was not built\n"; 11 exit 0; 12 } 13 if (defined ${^UNICODE} and ${^UNICODE} != 0){ 14 print "1..0 # Skip: \${^UNICODE} == ${^UNICODE}\n"; 15 exit 0; 16 } 17 if (ord("A") == 193) { 18 print "1..0 # encoding pragma does not support EBCDIC platforms\n"; 19 exit(0); 20 } 21} 22use lib qw(t ext/Encode/t ../ext/Encode/t); # latter 2 for perl core 23use Mod_EUCJP; 24no warnings "deprecated"; 25use encoding "euc-jp"; 26use Test::More tests => 3; 27use File::Basename; 28use File::Spec; 29use File::Compare qw(compare_text); 30 31my $DEBUG = shift || 0; 32my $dir = dirname(__FILE__); 33my $file0 = File::Spec->catfile($dir,"enc_module.enc"); 34my $file1 = File::Spec->catfile($dir,"$$.enc"); 35 36my $obj = Mod_EUCJP->new; 37local $SIG{__WARN__} = sub{ $DEBUG and print STDERR @_ }; 38# to silence reopening STD(IN|OUT) w/o closing unless $DEBUG 39 40open STDOUT, ">", $file1 or die "$file1:$!"; 41print $obj->str, "\n"; 42$obj->set("�ƥ���ʸ����"); 43print $obj->str, "\n"; 44 45# Please do not move this to a point after the comparison -- Craig Berry 46# and "unless $^O eq 'freebsd'" is needed for FreeBSD (toy-)?thread 47# -- dankogai 48close STDOUT unless $^O eq 'freebsd'; 49 50my $cmp = compare_text($file0, $file1); 51is($cmp, 0, "encoding vs. STDOUT"); 52 53my @cmp = qw/���ʸ���� �ƥ���ʸ����/; 54open STDIN, "<", $file0 or die "$file0:$!"; 55$obj = Mod_EUCJP->new; 56my $i = 0; 57while(<STDIN>){ 58 s/\r?\n\z//; 59 is ($cmp[$i++], $_, "encoding vs. STDIN - $i"); 60} 61 62unlink $file1 unless $cmp; 63__END__ 64 65