2 use warnings FATAL => 'all';
3 use Test::More tests => 33;
9 use MooseX::Types::Common::String (
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 );
32 has numericcode => ( is => 'rw', isa => NumericCode );
35 my $ins = FooTest->new;
37 # TODO: need to check both the inlined and non-inlined versions!
39 is(exception { $ins->simplestr('') }, undef, 'SimpleStr');
40 is(exception { $ins->simplestr('good string') }, undef, 'SimpleStr 2');
41 isnt(exception { $ins->simplestr("bad\nstring") }, 'SimpleStr 3');
42 isnt(exception { $ins->simplestr(join('', ("long string" x 25))) }, undef, 'SimpleStr 4');
44 isnt(exception { $ins->nestr('') }, undef, 'NonEmptyStr');
45 is(exception { $ins->nestr('good string') }, undef, 'NonEmptyStr 2');
46 is(exception { $ins->nestr("bad\nstring") }, undef, 'NonEmptyStr 3');
47 is(exception { $ins->nestr(join('', ("long string" x 25))) }, undef, 'NonEmptyStr 4');
49 is(exception { $ins->nesimplestr('good str') }, undef, 'NonEmptySimplrStr');
50 isnt(exception { $ins->nesimplestr('') }, undef, 'NonEmptyStr 2');
52 isnt(exception { $ins->password('no') }, undef, 'Password');
53 is(exception { $ins->password('okay') }, undef, 'Password 2');
55 isnt(exception { $ins->strongpassword('notokay') }, undef, 'StrongPassword');
56 is(exception { $ins->strongpassword('83773r_ch01c3') }, undef, 'StrongPassword 2');
58 isnt(exception { $ins->lcsimplestr('NOTOK') }, undef, 'LowerCaseSimpleStr');
59 is(exception { $ins->lcsimplestr('ok') }, undef, 'LowerCaseSimpleStr 2');
60 isnt(exception { $ins->lcsimplestr('NOTOK_123`"') }, undef, 'LowerCaseSimpleStr 3');
61 is(exception { $ins->lcsimplestr('ok_123`"') }, undef, 'LowerCaseSimpleStr 4');
63 isnt(exception { $ins->ucsimplestr('notok') }, undef, 'UpperCaseSimpleStr');
64 is(exception { $ins->ucsimplestr('OK') }, undef, 'UpperCaseSimpleStr 2');
65 isnt(exception { $ins->ucsimplestr('notok_123`"') }, undef, 'UpperCaseSimpleStr 3');
66 is(exception { $ins->ucsimplestr('OK_123`"') }, undef, 'UpperCaseSimpleStr 4');
68 isnt(exception { $ins->lowercasestr('NOTOK') }, undef, 'LowerCaseStr');
69 is(exception { $ins->lowercasestr("ok\nok") }, undef, 'LowerCaseStr 2');
70 isnt(exception { $ins->lowercasestr('NOTOK_123`"') }, undef, 'LowerCaseStr 3');
71 is(exception { $ins->lowercasestr("ok\n_123`'") }, undef, 'LowerCaseStr 4');
73 isnt(exception { $ins->uppercasestr('notok') }, undef, 'UpperCaseStr');
74 is(exception { $ins->uppercasestr("OK\nOK") }, undef, 'UpperCaseStr 2');
75 isnt(exception { $ins->uppercasestr('notok_123`"') }, undef, 'UpperCaseStr 3');
76 is(exception { $ins->uppercasestr("OK\n_123`'") }, undef, 'UpperCaseStr 4');
78 is( exception { $ins->numericcode('032') }, undef, 'NumericCode lives');
79 isnt( exception { $ins->numericcode('abc') }, undef, 'NumericCode dies' );
80 isnt( exception { $ins->numericcode('x18') }, undef, 'mixed NumericCode dies');