File: 01utility.t

package info (click to toggle)
libbest-perl 0.15-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 276 kB
  • sloc: perl: 2,606; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 1,149 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
#!perl
use Test::More tests => 26;
use Best ();

# does_arrayref
for ( [], bless( [] ), bless( {}, 'Overloaded' ) ) {
    ok( Best::does_arrayref($_), "$_ does array" );
}
for ( {}, sub { }, 'String', '1.00' ) {
    ok( !Best::does_arrayref($_), "$_ doesn't do array" );
}

# does_hashref
for ( {}, bless( {} ), bless( [], 'Overloaded' ) ) {
    ok( Best::does_hashref($_), "$_ does hash" );
}
for ( [], sub { }, 'String', '1.00' ) {
    ok( !Best::does_hashref($_), "$_ doesn't do hash" );
}

# does_coderef
for ( sub { }, bless( sub { } ), bless( [], 'Overloaded' ) ) {
    ok( Best::does_coderef($_), "$_ does code" );
}

# looks_like_version
for ( 1, 1.0, '1.00_01', 'v6' ) {
    ok( Best::looks_like_version($_), "$_ looks like version" );
}

# Honest to god, this test actually protects against a real bug.
for (qw( A::Module AnAlternative LastChance Version::Ok Version::TooLow )) {
    ok( !Best::looks_like_version($_), "$_ doesn't look like version" );
}

package Overloaded;
use overload
    '""'  => sub { overload::StrVal( $_[0] ) },
    '&{}' => sub {
    sub { }
    },
    '@{}' => sub { return [] },
    '%{}' => sub { return {} };