File: filehandle.t

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

my $FILENAME = 'filehandle.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;

open FH, $FILENAME or exit;

TEST "scalar slurp from filehandle ";
$str = slurp \*FH;
is $str, $data, $desc;

open FH, $FILENAME or exit;

TEST "list slurp from filehandle ";
@str = slurp \*FH;
is_deeply \@str, \@data, $desc;

for my $mode (qw( < +< )) {
	open FH, $FILENAME or exit;

	TEST "scalar slurp from '$mode', filehandle  ";
	$str = slurp $mode, \*FH;
	is $str, $data, $desc;

	TEST "scalar slurp from empty filehandle";
	$str = slurp $mode, \*FH;
	is $str, "", $desc;

	open FH, $FILENAME or exit;

	TEST "list slurp from '$mode', filehandle ";
	@str = slurp $mode, \*FH;
	is_deeply \@str, \@data, $desc;

	TEST "list slurp from empty filehandle";
	@str = slurp $mode, \*FH;
	is_deeply \@str, [], $desc;
}

unlink $FILENAME;