File: moose-meta-typeconstraint-parameterizable.t

package info (click to toggle)
libmoose-perl 2.4000-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,408 kB
  • sloc: perl: 21,275; ansic: 291; makefile: 10
file content (67 lines) | stat: -rw-r--r-- 1,660 bytes parent folder | download | duplicates (7)
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
use strict;
use warnings;

use Test::More;
use Test::Fatal;

use Moose::Util::TypeConstraints;

{
    my $t = find_type_constraint('ArrayRef');
    my $intType = find_type_constraint("Int");
    my $type = Moose::Meta::TypeConstraint::Parameterizable->new( name => 'xyz', parent => $t);

    my $exception = exception {
        $type->generate_inline_for( $intType, '$_[0]');
    };

    like(
        $exception,
        qr/Can't generate an inline constraint for Int, since none was defined/,
        "no inline constraint was defined for xyz");

    isa_ok(
        $exception,
        "Moose::Exception::CannotGenerateInlineConstraint",
        "no inline constraint was defined for xyz");

    is(
        $exception->type_name,
        "Int",
        "no inline constraint was defined for xyz");

    is(
        $exception->parameterizable_type_object_name,
        $type->name,
        "no inline constraint was defined for xyz");
}

{
    my $parameterizable = subtype 'parameterizable_arrayref', as 'ArrayRef[Float]';
    my $int = find_type_constraint('Int');
    my $exception = exception {
        my $from_parameterizable = $parameterizable->parameterize("Int");
    };

    like(
        $exception,
        qr/Int is not a subtype of Float/,
        "Int is not a subtype of Float");

    isa_ok(
        $exception,
        "Moose::Exception::ParameterIsNotSubtypeOfParent",
        "Int is not a subtype of Float");

    is(
        $exception->type_name,
        $parameterizable,
        "Int is not a subtype of Float");

    is(
        $exception->type_parameter,
        $int,
        "Int is not a subtype of Float");
}

done_testing;