summaryrefslogtreecommitdiff
path: root/t/release-pp-26-isa.t
blob: f95fdd53f8083c49d413f4a5aaa2f1300480072a (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102


use Test::More;

BEGIN {
    unless ( $ENV{RELEASE_TESTING} ) {
        plan skip_all => 'these tests are for release testing';
    }

    $ENV{PV_TEST_PERL} = 1;
}

use strict;
use warnings;

use Params::Validate qw(validate);
use Test::More;

{
    my @p = ( foo => 'ClassISA' );

    eval { validate( @p, { foo => { isa => 'FooBar' } }, ); };

    is( $@, q{}, 'no error checking if ClassISA->isa(FooBar)' );

    eval { validate( @p, { foo => { isa => 'Thingy' } }, ); };

    like( $@, qr/was not a 'Thingy'/ );
}

{
    my @p = ( foo => undef );
    eval { validate( @p, { foo => { isa => 'FooBar' } }, ); };

    like( $@, qr/was not a 'FooBar'/ );
}

{
    my @p = ( foo => 'SubClass' );

    eval { validate( @p, { foo => { isa => 'ClassISA' } }, ); };

    is( $@, q{}, 'SubClass->isa(ClassISA)' );

    eval { validate( @p, { foo => { isa => 'FooBar' } }, ); };

    is( $@, q{}, 'SubClass->isa(FooBar)' );

    eval { validate( @p, { foo => { isa => 'Thingy' } }, ); };

    like( $@, qr/was not a 'Thingy'/ );
}

{
    my @p = ( foo => bless {}, 'SubClass' );

    eval { validate( @p, { foo => { isa => 'ClassISA' } }, ); };

    is( $@, q{}, 'SubClass->isa(ClassISA)' );

    eval { validate( @p, { foo => { isa => 'FooBar' } }, ); };

    is( $@, q{}, 'SubClass->isa(FooBar)' );

    eval { validate( @p, { foo => { isa => 'Thingy' } }, ); };

    like( $@, qr/was not a 'Thingy'/ );
}

{
    my @p = ( foo => {} );
    eval { validate( @p, { foo => { isa => 'Thingy' } }, ); };
    like( $@, qr/was not a 'Thingy'/, 'unblessed ref ->isa' );

    @p = ( foo => 27 );
    eval { validate( @p, { foo => { isa => 'Thingy' } }, ); };
    like( $@, qr/was not a 'Thingy'/, 'number isa' );

    @p = ( foo => 'A String' );
    eval { validate( @p, { foo => { isa => 'Thingy' } }, ); };
    like( $@, qr/was not a 'Thingy'/, 'string isa' );

    @p = ( foo => undef );
    eval { validate( @p, { foo => { isa => 'Thingy' } }, ); };
    like( $@, qr/was not a 'Thingy'/, 'undef isa' );
}

done_testing();

package ClassISA;

sub isa {
    return 1 if $_[1] eq 'FooBar';
    return $_[0]->SUPER::isa( $_[1] );
}

sub thingy {1}

package SubClass;

use base 'ClassISA';