oops
[gitmo/MooseX-Types-Common.git] / t / 01-string.t
CommitLineData
ac73ab52 1#! /usr/bin/perl -w
2
3use strict;
4use warnings;
5use Test::More tests => 14;
6use Test::Exception;
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
22my $ins = FooTest->new;
23
24lives_ok { $ins->simplestr('') } 'SimpleStr';
25lives_ok { $ins->simplestr('good string') } 'SimpleStr 2';
26dies_ok { $ins->simplestr("bad\nstring") } 'SimpleStr 3';
27dies_ok { $ins->simplestr(join('', ("long string" x 25))) } 'SimpleStr 4';
28
29dies_ok { $ins->nestr('') } 'NonEmptyStr';
30lives_ok { $ins->nestr('good string') } 'NonEmptyStr 2';
31lives_ok { $ins->nestr("bad\nstring") } 'NonEmptyStr 3';
32lives_ok { $ins->nestr(join('', ("long string" x 25))) } 'NonEmptyStr 4';
33
34lives_ok { $ins->nesimplestr('good str') } 'NonEmptySimplrStr ';
35dies_ok { $ins->nesimplestr('') } 'NonEmptyStr 2';
36
37dies_ok { $ins->password('no') } 'Password';
38lives_ok { $ins->password('okay') } 'Password 2';
39
40dies_ok { $ins->strongpassword('notokay') } 'StrongPassword';
41lives_ok { $ins->strongpassword('83773r_ch01c3') } 'StrongPassword 2';