62cbad7ed34e18b1d44b51bc3ee6faeee9c93441
[urisagit/Perl-Docs.git] / t / paragraph.t
1 #!/usr/local/bin/perl -w
2
3 use strict ;
4
5 use File::Slurp ;
6 use Test::More ;
7 use Carp ;
8
9
10 my $file = 'slurp.data' ;
11 unlink $file ;
12
13 my @text_data = (
14         [],
15         [ 'a' x 8 ],
16         [ "\n" x 5 ],
17         [ map( "aaaaaaaa\n\n", 1 .. 3 ) ],
18         [ map( "aaaaaaaa\n\n", 1 .. 3 ), 'aaaaaaaa' ],
19         [ map( "aaaaaaaa" . ( "\n"  x (2 + rand 3) ), 1 .. 100 ) ],
20         [ map( "aaaaaaaa" . ( "\n"  x (2 + rand 3) ), 1 .. 100 ), 'aaaaaaaa' ],
21         [],
22 ) ;
23
24 plan( tests => 3 * @text_data ) ;
25
26 #print "# text slurp\n" ;
27
28 foreach my $data ( @text_data ) {
29
30         test_text_slurp( $data ) ;
31 }
32
33
34 unlink $file ;
35
36 exit ;
37
38 sub test_text_slurp {
39
40         my( $data_ref ) = @_ ;
41
42         my @data_lines = @{$data_ref} ;
43         my $data_text = join( '', @data_lines ) ;
44
45         local( $/ ) = '' ;
46
47         my $err = write_file( $file, $data_text ) ;
48         ok( $err, 'write_file - ' . length $data_text ) ;
49
50
51         my @array = read_file( $file ) ;
52         ok( eq_array( \@array, \@data_lines ),
53                         'array read_file - ' . length $data_text ) ;
54
55         print "READ:\n", map( "[$_]\n", @array ),
56                  "EXP:\n", map( "[$_]\n", @data_lines )
57                         unless eq_array( \@array, \@data_lines ) ;
58
59         my $array_ref = read_file( $file, array_ref => 1 ) ;
60         ok( eq_array( $array_ref, \@data_lines ),
61                         'array ref read_file - ' . length $data_text ) ;
62
63         return ;
64 }