083f7830996f2497fcf791ed6be9c517d22d96fa
[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 => 14;
6 use Test::Fatal;
7
8 {
9   package FooTest;
10   use Moose;
11   use MooseX::Types::Common::String (
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
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');
28
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');
33
34 is(exception { $ins->nesimplestr('good str') }, undef, 'NonEmptySimplrStr');
35 isnt(exception { $ins->nesimplestr('') }, undef, 'NonEmptyStr 2');
36
37 isnt(exception { $ins->password('no') }, undef, 'Password');
38 is(exception { $ins->password('okay') }, undef, 'Password 2');
39
40 isnt(exception { $ins->strongpassword('notokay') }, undef, 'StrongPassword');
41 is(exception { $ins->strongpassword('83773r_ch01c3') }, undef, 'StrongPassword 2');