add upper/lowercase for SimpleStr and Str
[gitmo/MooseX-Types-Common.git] / t / 01-string.t
CommitLineData
ac73ab52 1#! /usr/bin/perl -w
2
3use strict;
4use warnings;
a5c9a433 5use Test::More tests => 22;
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
20 UpperCaseStr),
ac73ab52 21 );
22
a5c9a433 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 );
ac73ab52 32}
33
34my $ins = FooTest->new;
35
3d272255 36is(exception { $ins->simplestr('') }, undef, 'SimpleStr');
37is(exception { $ins->simplestr('good string') }, undef, 'SimpleStr 2');
38isnt(exception { $ins->simplestr("bad\nstring") }, 'SimpleStr 3');
39isnt(exception { $ins->simplestr(join('', ("long string" x 25))) }, undef, 'SimpleStr 4');
ac73ab52 40
3d272255 41isnt(exception { $ins->nestr('') }, undef, 'NonEmptyStr');
42is(exception { $ins->nestr('good string') }, undef, 'NonEmptyStr 2');
43is(exception { $ins->nestr("bad\nstring") }, undef, 'NonEmptyStr 3');
44is(exception { $ins->nestr(join('', ("long string" x 25))) }, undef, 'NonEmptyStr 4');
ac73ab52 45
3d272255 46is(exception { $ins->nesimplestr('good str') }, undef, 'NonEmptySimplrStr');
47isnt(exception { $ins->nesimplestr('') }, undef, 'NonEmptyStr 2');
ac73ab52 48
3d272255 49isnt(exception { $ins->password('no') }, undef, 'Password');
50is(exception { $ins->password('okay') }, undef, 'Password 2');
ac73ab52 51
3d272255 52isnt(exception { $ins->strongpassword('notokay') }, undef, 'StrongPassword');
53is(exception { $ins->strongpassword('83773r_ch01c3') }, undef, 'StrongPassword 2');
a5c9a433 54
55isnt(exception { $ins->lcsimplestr('NOTOK') }, undef, 'LowerCaseSimpleStr');
56is(exception { $ins->lcsimplestr('ok') }, undef, 'LowerCaseSimpleStr 2');
57
58isnt(exception { $ins->ucsimplestr('notok') }, undef, 'UpperCaseSimpleStr');
59is(exception { $ins->ucsimplestr('OK') }, undef, 'UpperCaseSimpleStr 2');
60
61isnt(exception { $ins->lowercasestr('NOTOK') }, undef, 'LowerCaseStr');
62is(exception { $ins->lowercasestr('ok') }, undef, 'LowerCaseStr 2');
63
64isnt(exception { $ins->uppercasestr('notok') }, undef, 'UpperCaseStr');
65is(exception { $ins->uppercasestr('OK') }, undef, 'UpperCaseStr 2');