Commit | Line | Data |
ac73ab52 |
1 | #! /usr/bin/perl -w |
2 | |
3 | use strict; |
4 | use warnings; |
5 | use Test::More tests => 14; |
3d272255 |
6 | use Test::Fatal; |
ac73ab52 |
7 | |
8 | { |
9 | package FooTest; |
10 | use Moose; |
5b561c82 |
11 | use MooseX::Types::Common::String ( |
ac73ab52 |
12 | qw(SimpleStr NonEmptySimpleStr Password StrongPassword NonEmptyStr), |
13 | ); |
14 | |
15 | has simplestr => ( is => 'rw', isa => SimpleStr); |
16 | has nestr => ( is => 'rw', isa => NonEmptyStr); |
17 | has nesimplestr => ( is => 'rw', isa => NonEmptySimpleStr); |
18 | has password => ( is => 'rw', isa => Password); |
19 | has strongpassword => ( is => 'rw', isa => StrongPassword); |
20 | } |
21 | |
22 | my $ins = FooTest->new; |
23 | |
3d272255 |
24 | is(exception { $ins->simplestr('') }, undef, 'SimpleStr'); |
25 | is(exception { $ins->simplestr('good string') }, undef, 'SimpleStr 2'); |
26 | isnt(exception { $ins->simplestr("bad\nstring") }, 'SimpleStr 3'); |
27 | isnt(exception { $ins->simplestr(join('', ("long string" x 25))) }, undef, 'SimpleStr 4'); |
ac73ab52 |
28 | |
3d272255 |
29 | isnt(exception { $ins->nestr('') }, undef, 'NonEmptyStr'); |
30 | is(exception { $ins->nestr('good string') }, undef, 'NonEmptyStr 2'); |
31 | is(exception { $ins->nestr("bad\nstring") }, undef, 'NonEmptyStr 3'); |
32 | is(exception { $ins->nestr(join('', ("long string" x 25))) }, undef, 'NonEmptyStr 4'); |
ac73ab52 |
33 | |
3d272255 |
34 | is(exception { $ins->nesimplestr('good str') }, undef, 'NonEmptySimplrStr'); |
35 | isnt(exception { $ins->nesimplestr('') }, undef, 'NonEmptyStr 2'); |
ac73ab52 |
36 | |
3d272255 |
37 | isnt(exception { $ins->password('no') }, undef, 'Password'); |
38 | is(exception { $ins->password('okay') }, undef, 'Password 2'); |
ac73ab52 |
39 | |
3d272255 |
40 | isnt(exception { $ins->strongpassword('notokay') }, undef, 'StrongPassword'); |
41 | is(exception { $ins->strongpassword('83773r_ch01c3') }, undef, 'StrongPassword 2'); |