oops
[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::Exception;
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 lives_ok { $ins->simplestr('') } 'SimpleStr';
25 lives_ok { $ins->simplestr('good string') } 'SimpleStr 2';
26 dies_ok { $ins->simplestr("bad\nstring") } 'SimpleStr 3';
27 dies_ok { $ins->simplestr(join('', ("long string" x 25))) } 'SimpleStr 4';
28
29 dies_ok { $ins->nestr('') } 'NonEmptyStr';
30 lives_ok { $ins->nestr('good string') } 'NonEmptyStr 2';
31 lives_ok { $ins->nestr("bad\nstring") } 'NonEmptyStr 3';
32 lives_ok { $ins->nestr(join('', ("long string" x 25))) } 'NonEmptyStr 4';
33
34 lives_ok { $ins->nesimplestr('good str') } 'NonEmptySimplrStr ';
35 dies_ok { $ins->nesimplestr('') } 'NonEmptyStr 2';
36
37 dies_ok { $ins->password('no') } 'Password';
38 lives_ok { $ins->password('okay') } 'Password 2';
39
40 dies_ok { $ins->strongpassword('notokay') } 'StrongPassword';
41 lives_ok { $ins->strongpassword('83773r_ch01c3') } 'StrongPassword 2';