File: ref.t

package info (click to toggle)
libparams-classify-perl 0.015-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 188 kB
  • sloc: perl: 195; makefile: 3
file content (57 lines) | stat: -r--r--r-- 1,686 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use warnings;
use strict;

use Test::More tests => 1 + 2*14*12;

BEGIN { use_ok "Params::Classify", qw(is_ref ref_type); }

format foo =
.

my $foo = "";

sub test_ref_type($$) {
	my($scalar, $reftype) = @_;
	is(ref_type($scalar), $reftype);
	is(&ref_type($scalar), $reftype);
	is(!!is_ref($scalar), !!$reftype);
	is(!!&is_ref($scalar), !!$reftype);
	$reftype = "" if !defined($reftype);
	is(!!is_ref($scalar, "SCALAR"), "SCALAR" eq $reftype);
	is(!!&is_ref($scalar, "SCALAR"), "SCALAR" eq $reftype);
	is(!!is_ref($scalar, "ARRAY"), "ARRAY" eq $reftype);
	is(!!&is_ref($scalar, "ARRAY"), "ARRAY" eq $reftype);
	is(!!is_ref($scalar, "HASH"), "HASH" eq $reftype);
	is(!!&is_ref($scalar, "HASH"), "HASH" eq $reftype);
	is(!!is_ref($scalar, "CODE"), "CODE" eq $reftype);
	is(!!&is_ref($scalar, "CODE"), "CODE" eq $reftype);
	is(!!is_ref($scalar, "FORMAT"), "FORMAT" eq $reftype);
	is(!!&is_ref($scalar, "FORMAT"), "FORMAT" eq $reftype);
	is(!!is_ref($scalar, "IO"), "IO" eq $reftype);
	is(!!&is_ref($scalar, "IO"), "IO" eq $reftype);
	foreach my $type (qw(SCALAR ARRAY HASH CODE FORMAT IO)) {
		is(!!is_ref($scalar, $type), $type eq $reftype);
		is(!!&is_ref($scalar, $type), $type eq $reftype);
	}
}

test_ref_type(undef, undef);
test_ref_type("foo", undef);
test_ref_type(123, undef);
test_ref_type(*STDOUT, undef);
test_ref_type(bless({}, "main"), undef);

test_ref_type(\1, "SCALAR");
test_ref_type(\\1, "SCALAR");
test_ref_type(\pos($foo), "SCALAR");
test_ref_type([], "ARRAY");
test_ref_type({}, "HASH");
test_ref_type(\&is, "CODE");

SKIP: {
	my $format = *foo{FORMAT};
	skip "this Perl doesn't do *foo{FORMAT}", 2*14 unless defined $format;
	test_ref_type($format, "FORMAT");
}

1;