Added a test, updated Changes
[catagits/Catalyst-Devel.git] / t / check_types.t
1 # t0m++
2 package My::Types;
3 use MooseX::Types -declare [qw/ ValidAppName ValidAppComponent /];
4
5 my $appname_re = qr/[\w:]+/;
6 my $regex = qr/$appname_re::(M|V|C|Model|View|Controller)::.*/;
7
8 subtype ValidAppName, 
9    as Str,
10    where { /^$appname_re$/ && ! /$regex/ };
11
12 subtype ValidAppComponent,
13    as Str,
14    where { /^$regex$/ };
15
16 coerce ValidAppName,
17    from ValidAppComponent,
18    via { Catalyst::Utils::class2appclass($_); };
19
20 package main;
21 use Test::More 'no_plan';
22 use Moose::Util::TypeContraints;
23 use My::Types qw/ValidAppName ValidAppComponent/;
24
25 my $app_tc = find_type_constraint(ValidAppName);
26 ok $app_tc;
27 ok !$app_tc->check('');
28 ok $app_tc->check('MyApp');
29
30 my $comp_tc = find_type_constraint(ValidAppComponent);
31 ok $comp_tc;
32 ok !$comp_tc->check('');
33 ok !$comp_tc->check('MyApp');
34 ok $comp_tc->check('MyApp::Model::Foo');
35
36 is $app_tc->coerce('MyApp::Model::Foo'), 'MyApp';
37
38 done_testing;
39