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