File: 10_read_file.t

package info (click to toggle)
libfile-slurp-unicode-perl 0.7.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 84 kB
  • sloc: perl: 142; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 762 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl

# This just tests that I mimic the File::Slurp APIs correctly.

use strict;
use warnings;

use Test::More;

plan tests => 5;

use File::Slurp::Unicode;
use File::Temp qw(tempfile);

my ($fh, $name) = tempfile();
$fh->autoflush(1);
my @expect = map { "$_\n" } qw(line1 line2 line3);
my $expect = join '', @expect;
print $fh $expect;

my @lines = read_file $name;
is_deeply(\@lines, \@expect, "list context");

my $data = read_file $name;
is($data, $expect, "scalar context");

my $data_ref;
read_file $name, buf_ref => \$data_ref;
is($data_ref, $expect, "buf_ref");

$data_ref = read_file $name, scalar_ref => 1;
is(${$data_ref}, $expect, "scalar_ref");

$data_ref = read_file $name, array_ref => 1;
is_deeply($data_ref, \@expect, "array_ref");