5549130939573ecb09adef6cd88840401378984d
[urisagit/Perl-Docs.git] / t / binmode.t
1 #!/usr/local/bin/perl -w
2
3 use strict ;
4 use Test::More ;
5 use Carp ;
6 use File::Slurp ;
7
8 if ( $] < 5.008001 ) {
9         plan skip_all => 'Older Perl lacking unicode support' ;
10         exit ;
11 }
12
13 plan tests => 2 ;
14
15 my $mode = ':utf8' ;
16
17 my $orig_text = "\x{20ac}\n" ;
18 my $unicode_length = length $orig_text ;
19
20 my $control_file = "control.$mode" ;
21 my $slurp_file = "slurp.$mode" ;
22
23 open( my $fh, ">$mode", $control_file ) or
24         die "cannot create control unicode file '$control_file' $!" ;
25 print $fh $orig_text ;
26 close $fh ;
27
28 my $slurp_utf = read_file( $control_file, binmode => $mode ) ;
29 ok( $slurp_utf eq $orig_text, "read_file of $mode file" ) ;
30
31 # my $slurp_utf_length = length $slurp_utf ;
32 # my $slurp_text = read_file( $control_file ) ;
33 # my $slurp_text_length = length $slurp_text ;
34 # print "LEN UTF $slurp_utf_length TXT $slurp_text_length\n" ;
35
36 write_file( $slurp_file, {binmode => $mode}, $orig_text ) ;
37
38 open( $fh, "<$mode", $slurp_file ) or
39         die "cannot open slurp test file '$slurp_file' $!" ;
40 my $read_length = read( $fh, my $utf_text, $unicode_length ) ;
41 close $fh ;
42
43 ok( $utf_text eq $orig_text, "write_file of $mode file" ) ;
44
45 unlink( $control_file, $slurp_file ) ;