d29ef2b69252b3c91e4225f1e6c4b1833c0cdc7a
[gitmo/MooseX-Types-Common.git] / t / 01-string.t
1 #! /usr/bin/perl -w
2
3 use strict;
4 use warnings;
5 use Test::More tests => 25;
6 use Test::Fatal;
7 use Test::Exception;
8
9 {
10   package FooTest;
11   use Moose;
12   use MooseX::Types::Common::String (
13     qw(SimpleStr
14        NonEmptySimpleStr
15        LowerCaseSimpleStr
16        UpperCaseSimpleStr
17        Password
18        StrongPassword
19        NonEmptyStr
20        LowerCaseStr
21        UpperCaseStr
22        NumericCode
23         ),
24   );
25
26   has simplestr => ( is => 'rw', isa => SimpleStr );
27   has nestr => ( is => 'rw', isa => NonEmptyStr );
28   has nesimplestr => ( is => 'rw', isa => NonEmptySimpleStr );
29   has lcsimplestr => ( is => 'rw', isa => LowerCaseSimpleStr );
30   has ucsimplestr => ( is => 'rw', isa => UpperCaseSimpleStr );
31   has password => ( is => 'rw', isa => Password );
32   has strongpassword => ( is => 'rw', isa => StrongPassword );
33   has lowercasestr => ( is => 'rw', isa => LowerCaseStr );
34   has uppercasestr => ( is => 'rw', isa => UpperCaseStr );
35   has numericcode => ( is => 'rw', isa => NumericCode );
36 }
37
38 my $ins = FooTest->new;
39
40 is(exception { $ins->simplestr('') }, undef, 'SimpleStr');
41 is(exception { $ins->simplestr('good string') }, undef, 'SimpleStr 2');
42 isnt(exception { $ins->simplestr("bad\nstring") }, 'SimpleStr 3');
43 isnt(exception { $ins->simplestr(join('', ("long string" x 25))) }, undef, 'SimpleStr 4');
44
45 isnt(exception { $ins->nestr('') }, undef, 'NonEmptyStr');
46 is(exception { $ins->nestr('good string') }, undef, 'NonEmptyStr 2');
47 is(exception { $ins->nestr("bad\nstring") }, undef, 'NonEmptyStr 3');
48 is(exception { $ins->nestr(join('', ("long string" x 25))) }, undef, 'NonEmptyStr 4');
49
50 is(exception { $ins->nesimplestr('good str') }, undef, 'NonEmptySimplrStr');
51 isnt(exception { $ins->nesimplestr('') }, undef, 'NonEmptyStr 2');
52
53 isnt(exception { $ins->password('no') }, undef, 'Password');
54 is(exception { $ins->password('okay') }, undef, 'Password 2');
55
56 isnt(exception { $ins->strongpassword('notokay') }, undef, 'StrongPassword');
57 is(exception { $ins->strongpassword('83773r_ch01c3') }, undef, 'StrongPassword 2');
58
59 isnt(exception { $ins->lcsimplestr('NOTOK') }, undef, 'LowerCaseSimpleStr');
60 is(exception { $ins->lcsimplestr('ok') }, undef, 'LowerCaseSimpleStr 2');
61
62 isnt(exception { $ins->ucsimplestr('notok') }, undef, 'UpperCaseSimpleStr');
63 is(exception { $ins->ucsimplestr('OK') }, undef, 'UpperCaseSimpleStr 2');
64
65 isnt(exception { $ins->lowercasestr('NOTOK') }, undef, 'LowerCaseStr');
66 is(exception { $ins->lowercasestr('ok') }, undef, 'LowerCaseStr 2');
67
68 isnt(exception { $ins->uppercasestr('notok') }, undef, 'UpperCaseStr');
69 is(exception { $ins->uppercasestr('OK') }, undef, 'UpperCaseStr 2');
70
71
72 is(   exception { $ins->numericcode('032') }, undef,  'NumericCode lives');
73 isnt( exception { $ins->numericcode('abc') }, undef,  'NumericCode dies' );
74 isnt( exception { $ins->numericcode('x18') }, undef,  'mixed NumericCode dies');