remove unneeded shebangs
[gitmo/MooseX-Types-Common.git] / t / 01-string.t
CommitLineData
ac73ab52 1use strict;
eae6c2c4 2use warnings FATAL => 'all';
19ef3f5a 3use Test::More tests => 33;
3d272255 4use Test::Fatal;
ac73ab52 5
6{
7 package FooTest;
8 use Moose;
5b561c82 9 use MooseX::Types::Common::String (
a5c9a433 10 qw(SimpleStr
11 NonEmptySimpleStr
12 LowerCaseSimpleStr
13 UpperCaseSimpleStr
14 Password
15 StrongPassword
16 NonEmptyStr
17 LowerCaseStr
559b5d74 18 UpperCaseStr
19 NumericCode
20 ),
ac73ab52 21 );
22
a5c9a433 23 has simplestr => ( is => 'rw', isa => SimpleStr );
24 has nestr => ( is => 'rw', isa => NonEmptyStr );
25 has nesimplestr => ( is => 'rw', isa => NonEmptySimpleStr );
26 has lcsimplestr => ( is => 'rw', isa => LowerCaseSimpleStr );
27 has ucsimplestr => ( is => 'rw', isa => UpperCaseSimpleStr );
28 has password => ( is => 'rw', isa => Password );
29 has strongpassword => ( is => 'rw', isa => StrongPassword );
30 has lowercasestr => ( is => 'rw', isa => LowerCaseStr );
31 has uppercasestr => ( is => 'rw', isa => UpperCaseStr );
559b5d74 32 has numericcode => ( is => 'rw', isa => NumericCode );
ac73ab52 33}
34
35my $ins = FooTest->new;
36
19ef3f5a 37# TODO: need to check both the inlined and non-inlined versions!
38
3d272255 39is(exception { $ins->simplestr('') }, undef, 'SimpleStr');
40is(exception { $ins->simplestr('good string') }, undef, 'SimpleStr 2');
41isnt(exception { $ins->simplestr("bad\nstring") }, 'SimpleStr 3');
42isnt(exception { $ins->simplestr(join('', ("long string" x 25))) }, undef, 'SimpleStr 4');
ac73ab52 43
3d272255 44isnt(exception { $ins->nestr('') }, undef, 'NonEmptyStr');
45is(exception { $ins->nestr('good string') }, undef, 'NonEmptyStr 2');
46is(exception { $ins->nestr("bad\nstring") }, undef, 'NonEmptyStr 3');
47is(exception { $ins->nestr(join('', ("long string" x 25))) }, undef, 'NonEmptyStr 4');
ac73ab52 48
3d272255 49is(exception { $ins->nesimplestr('good str') }, undef, 'NonEmptySimplrStr');
50isnt(exception { $ins->nesimplestr('') }, undef, 'NonEmptyStr 2');
ac73ab52 51
3d272255 52isnt(exception { $ins->password('no') }, undef, 'Password');
53is(exception { $ins->password('okay') }, undef, 'Password 2');
ac73ab52 54
3d272255 55isnt(exception { $ins->strongpassword('notokay') }, undef, 'StrongPassword');
56is(exception { $ins->strongpassword('83773r_ch01c3') }, undef, 'StrongPassword 2');
a5c9a433 57
58isnt(exception { $ins->lcsimplestr('NOTOK') }, undef, 'LowerCaseSimpleStr');
59is(exception { $ins->lcsimplestr('ok') }, undef, 'LowerCaseSimpleStr 2');
19ef3f5a 60isnt(exception { $ins->lcsimplestr('NOTOK_123`"') }, undef, 'LowerCaseSimpleStr 3');
61is(exception { $ins->lcsimplestr('ok_123`"') }, undef, 'LowerCaseSimpleStr 4');
a5c9a433 62
63isnt(exception { $ins->ucsimplestr('notok') }, undef, 'UpperCaseSimpleStr');
64is(exception { $ins->ucsimplestr('OK') }, undef, 'UpperCaseSimpleStr 2');
19ef3f5a 65isnt(exception { $ins->ucsimplestr('notok_123`"') }, undef, 'UpperCaseSimpleStr 3');
66is(exception { $ins->ucsimplestr('OK_123`"') }, undef, 'UpperCaseSimpleStr 4');
a5c9a433 67
68isnt(exception { $ins->lowercasestr('NOTOK') }, undef, 'LowerCaseStr');
4a305974 69is(exception { $ins->lowercasestr("ok\nok") }, undef, 'LowerCaseStr 2');
19ef3f5a 70isnt(exception { $ins->lowercasestr('NOTOK_123`"') }, undef, 'LowerCaseStr 3');
71is(exception { $ins->lowercasestr("ok\n_123`'") }, undef, 'LowerCaseStr 4');
a5c9a433 72
73isnt(exception { $ins->uppercasestr('notok') }, undef, 'UpperCaseStr');
4a305974 74is(exception { $ins->uppercasestr("OK\nOK") }, undef, 'UpperCaseStr 2');
19ef3f5a 75isnt(exception { $ins->uppercasestr('notok_123`"') }, undef, 'UpperCaseStr 3');
76is(exception { $ins->uppercasestr("OK\n_123`'") }, undef, 'UpperCaseStr 4');
559b5d74 77
78is( exception { $ins->numericcode('032') }, undef, 'NumericCode lives');
79isnt( exception { $ins->numericcode('abc') }, undef, 'NumericCode dies' );
80isnt( exception { $ins->numericcode('x18') }, undef, 'mixed NumericCode dies');