File: classify.t

package info (click to toggle)
libparams-classify-perl 0.015-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 188 kB
  • sloc: perl: 195; makefile: 3
file content (47 lines) | stat: -r--r--r-- 1,754 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
use warnings;
use strict;

use Test::More tests => 1 + 2*8*11;

BEGIN {
	use_ok "Params::Classify", qw(
		scalar_class is_undef is_string
		is_number is_glob is_regexp is_ref is_blessed
	);
}

sub test_scalar_classification($$$$$$$$$) {
	my(undef, $class, $iu, $is, $in, $ig, $ix, $ir, $ib) = @_;
	is(scalar_class($_[0]), $class);
	is(&scalar_class($_[0]), $class);
	is(!!is_undef($_[0]), !!$iu);
	is(!!&is_undef($_[0]), !!$iu);
	is(!!is_string($_[0]), !!$is);
	is(!!&is_string($_[0]), !!$is);
	is(!!is_number($_[0]), !!$in);
	is(!!&is_number($_[0]), !!$in);
	is(!!is_glob($_[0]), !!$ig);
	is(!!&is_glob($_[0]), !!$ig);
	is(!!is_regexp($_[0]), !!$ix);
	is(!!&is_regexp($_[0]), !!$ix);
	is(!!is_ref($_[0]), !!$ir);
	is(!!&is_ref($_[0]), !!$ir);
	is(!!is_blessed($_[0]), !!$ib);
	is(!!&is_blessed($_[0]), !!$ib);
}

test_scalar_classification(undef,             "UNDEF",   1, 0, 0, 0, 0, 0, 0);
test_scalar_classification("",                "STRING",  0, 1, 0, 0, 0, 0, 0);
test_scalar_classification("abc",             "STRING",  0, 1, 0, 0, 0, 0, 0);
test_scalar_classification(123,               "STRING",  0, 1, 1, 0, 0, 0, 0);
test_scalar_classification(0,                 "STRING",  0, 1, 1, 0, 0, 0, 0);
test_scalar_classification("0 but true",      "STRING",  0, 1, 1, 0, 0, 0, 0);
test_scalar_classification("1ab",             "STRING",  0, 1, 0, 0, 0, 0, 0);
test_scalar_classification(*STDOUT,           "GLOB",    0, 0, 0, 1, 0, 0, 0);
SKIP: { skip "no first-class regexps", 2*8 unless "$]" >= 5.011;
test_scalar_classification(${qr/xyz/},        "REGEXP",  0, 0, 0, 0, 1, 0, 0);
}
test_scalar_classification({},                "REF",     0, 0, 0, 0, 0, 1, 0);
test_scalar_classification(bless({}, "main"), "BLESSED", 0, 0, 0, 0, 0, 0, 1);

1;