File: 01_deref.t

package info (click to toggle)
libdata-alias-perl 1.28-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 368 kB
  • sloc: perl: 1,976; makefile: 3
file content (52 lines) | stat: -rw-r--r-- 1,149 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/perl -w

use strict;
use warnings qw(FATAL all);
use lib 'lib';
use Test::More tests => 12;

use Data::Alias 'deref';

sub refs { [map "".\$_, @_] }

our $x = \1;
our $y = [2, 3, 4];
our $z = {5 => 6, 7 => 8};

is_deeply [deref $x, $y, $z], [$$x, @$y, %$z];
is_deeply refs((deref $x, $y, $z)[0,1,2,3,5,7]), refs($$x, @$y, (%$z)[1,3]);

our @r = \(($x, $y, $z) = (1, 2, 3));
$_++ for deref @r;
is_deeply [$x, $y, $z], [2, 3, 4];

(deref @r) = (42, 43, 44);
is_deeply [$x, $y, $z], [42, 43, 44];

eval { deref undef };
like $@, qr/^Use of uninitialized value in deref /;

is_deeply [do { no warnings 'uninitialized'; deref undef }], [];

eval { no warnings; deref "" };
like $@, qr/^Can't deref string /;

our @n;
our %n;

is_deeply refs(deref \$x, \@n, \$y, \$z), refs($x, $y, $z);
is_deeply refs(deref \$x, \%n, \$y, \$z), refs($x, $y, $z);

format foo =
.

eval { no warnings; deref \&refs };
like $@, qr/^Can't deref subroutine reference /;

eval { no warnings; deref *foo{FORMAT} };
like $@, qr/^Can't deref format reference /;

eval { no warnings; deref *STDOUT{IO} };
like $@, qr/^Can't deref filehandle reference /;

# vim: ft=perl