Upgrade to Encode 0.99, from Dan Kogai.
[p5sagit/p5-mst-13.2.git] / ext / PerlIO / PerlIO.t
CommitLineData
ec28694c 1BEGIN {
2 chdir 't' if -d 't';
3 @INC = '../lib';
4 require Config; import Config;
dc87d25e 5 unless ($Config{'useperlio'}) {
6 print "1..0 # Skip: PerlIO not used\n";
ec28694c 7 exit 0;
8 }
9}
10
72feb90e 11use Test::More tests => 35;
ec28694c 12
72feb90e 13use_ok('PerlIO');
ec28694c 14
15my $txt = "txt$$";
16my $bin = "bin$$";
17my $utf = "utf$$";
18
19my $txtfh;
20my $binfh;
21my $utffh;
22
72feb90e 23ok(open($txtfh, ">:crlf", $txt));
ec28694c 24
72feb90e 25ok(open($binfh, ">:raw", $bin));
ec28694c 26
72feb90e 27ok(open($utffh, ">:utf8", $utf));
ec28694c 28print "ok 4\n";
29
30print $txtfh "foo\n";
31print $txtfh "bar\n";
72feb90e 32
33ok(close($txtfh));
ec28694c 34
35print $binfh "foo\n";
36print $binfh "bar\n";
72feb90e 37
38ok(close($binfh));
ec28694c 39
40print $utffh "foo\x{ff}\n";
41print $utffh "bar\x{abcd}\n";
ec28694c 42
72feb90e 43ok(close($utffh));
44
45ok(open($txtfh, "<:crlf", $txt));
46
47ok(open($binfh, "<:raw", $bin));
48
49
50ok(open($utffh, "<:utf8", $utf));
ec28694c 51
72feb90e 52is(scalar <$txtfh>, "foo\n");
53is(scalar <$txtfh>, "bar\n");
ec28694c 54
72feb90e 55is(scalar <$binfh>, "foo\n");
56is(scalar <$binfh>, "bar\n");
ec28694c 57
72feb90e 58is(scalar <$utffh>, "foo\x{ff}\n");
59is(scalar <$utffh>, "bar\x{abcd}\n");
ec28694c 60
72feb90e 61ok(eof($txtfh));;
ec28694c 62
72feb90e 63ok(eof($binfh));
ec28694c 64
72feb90e 65ok(eof($utffh));
ec28694c 66
72feb90e 67ok(close($txtfh));
ec28694c 68
72feb90e 69ok(close($binfh));
ec28694c 70
72feb90e 71ok(close($utffh));
ec28694c 72
72feb90e 73# magic temporary file via 3 arg open with undef
74{
75 ok( open(my $x,"+<",undef), 'magic temp file via 3 arg open with undef');
76 ok( defined fileno($x), ' fileno' );
ec28694c 77
72feb90e 78 select $x;
79 ok( (print "ok\n"), ' print' );
80
81 select STDOUT;
82 ok( seek($x,0,0), ' seek' );
83 is( scalar <$x>, "ok\n", ' readline' );
84 ok( tell($x) >= 3, ' tell' );
85
86 # test magic temp file over STDOUT
87 open OLDOUT, ">&STDOUT" or die "cannot dup STDOUT: $!";
88 my $status = open(STDOUT,"+<",undef);
89 open STDOUT, ">&OLDOUT" or die "cannot dup OLDOUT: $!";
90 # report after STDOUT is restored
91 ok($status, ' re-open STDOUT');
2655a377 92 close OLDOUT;
72feb90e 93}
94
95# in-memory open
96{
97 my $var;
98 ok( open(my $x,"+<",\$var), 'magic in-memory file via 3 arg open with \\$var');
99 ok( defined fileno($x), ' fileno' );
100
101 select $x;
102 ok( (print "ok\n"), ' print' );
103
104 select STDOUT;
105 ok( seek($x,0,0), ' seek' );
106 is( scalar <$x>, "ok\n", ' readline' );
107 ok( tell($x) >= 3, ' tell' );
108}
ec28694c 109
110END {
111 1 while unlink $txt;
112 1 while unlink $bin;
113 1 while unlink $utf;
114}
115