xref: /openbsd/gnu/usr.bin/perl/cpan/Encode/t/enc_module.t (revision 4bdff4be)
1# $Id: enc_module.t,v 2.6 2022/04/07 03:06:40 dankogai Exp dankogai $
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 # Skip: encoding pragma does not support EBCDIC platforms\n";
19    exit(0);
20    }
21    if ($] >= 5.025 and !$Config{usecperl}) {
22    print "1..0 # Skip: encoding pragma not supported in Perl 5.25 or later\n";
23    exit(0);
24    }
25}
26use lib qw(t ext/Encode/t ../ext/Encode/t); # latter 2 for perl core
27use Mod_EUCJP;
28no warnings "deprecated";
29use encoding "euc-jp";
30use Test::More tests => 3;
31use File::Basename;
32use File::Spec;
33use File::Compare qw(compare_text);
34
35my $DEBUG = shift || 0;
36my $dir = dirname(__FILE__);
37my $file0 = File::Spec->catfile($dir,"enc_module.enc");
38my $file1 = File::Spec->catfile($dir,"$$.enc");
39
40my $obj = Mod_EUCJP->new;
41local $SIG{__WARN__} = sub{ $DEBUG and print STDERR @_ };
42# to silence reopening STD(IN|OUT) w/o closing unless $DEBUG
43
44open STDOUT, ">", $file1 or die "$file1:$!";
45print $obj->str, "\n";
46$obj->set("�ƥ���ʸ����");
47print $obj->str, "\n";
48
49# Please do not move this to a point after the comparison -- Craig Berry
50# and "unless $^O eq 'freebsd'" is needed for FreeBSD (toy-)?thread
51# -- dankogai
52close STDOUT unless $^O eq 'freebsd';
53
54my $cmp = compare_text($file0, $file1);
55is($cmp, 0, "encoding vs. STDOUT");
56
57my @cmp = qw/���ʸ���� �ƥ���ʸ����/;
58open STDIN, "<", $file0 or die "$file0:$!";
59$obj = Mod_EUCJP->new;
60my $i = 0;
61while(<STDIN>){
62    s/\r?\n\z//;
63    is ($cmp[$i++], $_, "encoding vs. STDIN - $i");
64}
65
66unlink $file1 unless $cmp;
67__END__
68
69