File: filename.t

package info (click to toggle)
libperl6-slurp-perl 0.051005-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, trixie
  • size: 148 kB
  • sloc: perl: 148; makefile: 2
file content (68 lines) | stat: -rwxr-xr-x 1,489 bytes parent folder | download | duplicates (3)
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
67
68
use Test::More "no_plan";
BEGIN {use_ok(Perl6::Slurp)};

my $FILENAME = 'filename.t.data';

my $desc;
sub TEST { $desc = $_[0] };

open FH, '>'.$FILENAME or exit;
print FH map "data $_\n", 1..20;
close FH;

open FH, $FILENAME or exit;
my $pos = tell *FH;

my $data = do { local $/; <FH> };
seek *FH, 0, 0;
my @data = <FH>;
close FH;

TEST "scalar slurp from $FILENAME in main";
$str = slurp $FILENAME;
is $str, $data, $desc;

TEST "list slurp from $FILENAME in main";
@str = slurp $FILENAME;
is_deeply \@str, \@data, $desc;

for my $mode (qw( < +< )) {
	TEST "scalar slurp from '${mode}$FILENAME' in main";
	$str = slurp "${mode}$FILENAME";
	is $str, $data, $desc;

	TEST "scalar slurp from '$mode $FILENAME' in main";
	$str = slurp "$mode $FILENAME";
	is $str, $data, $desc;

	TEST "scalar slurp from '$mode', $FILENAME' in main";
	$str = slurp $mode, $FILENAME;
	is $str, $data, $desc;

	TEST "list slurp from '${mode}$FILENAME' in main";
	@str = slurp "${mode}$FILENAME";
	is_deeply \@str, \@data, $desc;

	TEST "list slurp from '$mode $FILENAME' in main";
	@str = slurp "$mode $FILENAME";
	is_deeply \@str, \@data, $desc;

	TEST "list slurp from '$mode', $FILENAME in main";
	@str = slurp $mode, $FILENAME;
	is_deeply \@str, \@data, $desc;
}

TEST "scalar slurp from \$_ in main";
for ($FILENAME) {
	$str = slurp;
	is $str, $data, $desc;
}

local $/;
@ARGV = ($FILENAME, $FILENAME);

TEST "scalar slurp from ARGV in main";
$str = slurp;
is $str, $data.$data, $desc;

unlink $FILENAME;