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