summaryrefslogtreecommitdiff
path: root/t/chomp.t
blob: e14319b23f93eb8eafacfa8c68c9fb0547c99e21 (plain)
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

use strict ;
use warnings ;

use lib qw(t) ;

use File::Slurp qw( read_file write_file ) ;
use Test::More ;

use TestDriver ;

my $file = 'edit_file_data' ;

my $existing_data = <<PRE ;
line 1
line 2
more
foo
bar
junk here and foo
last line
PRE

my $tests = [
	{
		name	=> 'read_file - chomp',
		sub	=> \&read_file,
		args	=> [
				$file,
				{
					'chomp'	=> 1,
					array_ref => 1
				},
		],
		pretest	=> sub {
			my( $test ) = @_ ;
			write_file( $file, $existing_data ) ;
		},
		posttest => sub {
			my( $test ) = @_ ;
			$test->{ok} = eq_array(
				$test->{result},
				[$existing_data =~ /^(.+)\n/gm]
			) ;
		},
	},
] ;

test_driver( $tests ) ;

unlink $file ;

exit ;