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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
use strict;
use warnings;
use File::Basename ();
use File::Spec ();
use lib File::Spec->catdir(File::Spec->rel2abs(File::Basename::dirname(__FILE__)), 'lib');
use FileSlurpTest qw(temp_file_path);
use File::Slurp qw(read_file write_file);
use Test::More;
my $file = temp_file_path();
my @text_data = (
[],
[ 'a' x 8 ],
[ "\n" x 5 ],
[ map( "aaaaaaaa\n\n", 1 .. 3 ) ],
[ map( "aaaaaaaa\n\n", 1 .. 3 ), 'aaaaaaaa' ],
[ map( "aaaaaaaa" . ( "\n" x (2 + rand 3) ), 1 .. 100 ) ],
[ map( "aaaaaaaa" . ( "\n" x (2 + rand 3) ), 1 .. 100 ), 'aaaaaaaa' ],
[],
) ;
plan( tests => 3 * @text_data ) ;
#print "# text slurp\n" ;
foreach my $data ( @text_data ) {
test_text_slurp( $data ) ;
}
unlink $file ;
exit ;
sub test_text_slurp {
my( $data_ref ) = @_ ;
my @data_lines = @{$data_ref} ;
my $data_text = join( '', @data_lines ) ;
local( $/ ) = '' ;
my $err = write_file( $file, $data_text ) ;
ok( $err, 'write_file - ' . length $data_text ) ;
my @array = read_file( $file ) ;
ok( eq_array( \@array, \@data_lines ),
'array read_file - ' . length $data_text ) ;
print "READ:\n", map( "[$_]\n", @array ),
"EXP:\n", map( "[$_]\n", @data_lines )
unless eq_array( \@array, \@data_lines ) ;
my $array_ref = read_file( $file, array_ref => 1 ) ;
ok( eq_array( $array_ref, \@data_lines ),
'array ref read_file - ' . length $data_text ) ;
return ;
}
|