File: basic.t

package info (click to toggle)
libtype-tiny-perl 1.000004-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,836 kB
  • ctags: 583
  • sloc: perl: 7,602; makefile: 26
file content (81 lines) | stat: -rw-r--r-- 1,761 bytes parent folder | download | duplicates (2)
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
=pod

=encoding utf-8

=head1 PURPOSE

Complex checks between Type::Tiny and L<MooseX::Types>.

=head1 DEPENDENCIES

MooseX::Types 0.35; skipped otherwise.

=head1 AUTHOR

Toby Inkster E<lt>tobyink@cpan.orgE<gt>.

=head1 COPYRIGHT AND LICENCE

This software is copyright (c) 2013-2014 by Toby Inkster.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut

use strict;
use warnings;

use Test::More;
use Test::Requires { "MooseX::Types::Moose" => "0.35" };
use Test::TypeTiny;

use MooseX::Types::Moose -all;
use Types::Standard -all => { -prefix => "My" };

my $union1 = Int | MyArrayRef;
my $union2 = MyArrayRef | Int;

isa_ok($union1, "Moose::Meta::TypeConstraint");
isa_ok($union2, "Moose::Meta::TypeConstraint");
isa_ok($union2, "Type::Tiny");

should_pass([], $union1);
should_pass(2, $union1);
should_fail({}, $union1);

should_pass([], $union2);
should_pass(2, $union2);
should_fail({}, $union2);

my $param1 = MyArrayRef[Int];
my $param2 = ArrayRef[MyInt];

should_pass([1,2,3], $param1);
should_pass([], $param1);
should_fail({}, $param1);
should_fail(["x"], $param1);

should_pass([1,2,3], $param2);
should_pass([], $param2);
should_fail({}, $param2);
should_fail(["x"], $param2);

my $param_union = MyArrayRef[Int | ArrayRef];

should_pass([], $param_union);
should_pass([1,2,3], $param_union);
should_pass([[],[]], $param_union);
should_pass([11,[]], $param_union);
should_pass([[],11], $param_union);
should_fail([1.111], $param_union);

use Types::TypeTiny 'to_TypeTiny';

my $moosey = ArrayRef[HashRef[Int]];
my $tt1    = to_TypeTiny($moosey);
my $tt2    = to_TypeTiny($moosey);

is($tt1->{uniq}, $tt2->{uniq}, "to_TypeTiny caches results");

done_testing;