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