initial checkin
[gitmo/MooseX-Types-Common.git] / t / 01-common.t
CommitLineData
3379cc45 1#! /usr/bin/perl -w
2
3use strict;
4use warnings;
5use Test::More tests => 26;
6use Test::Exception;
7
8{
9 package FooTest;
10 use Moose;
11 use MooseX::Types::Common (
12 qw(SimpleStr NonEmptySimpleStr Password StrongPassword NonEmptyStr),
13 qw(PositiveNum PositiveInt NegativeInt NegativeNum SingleDigit)
14 );
15
16 has simplestr => ( is => 'rw', isa => SimpleStr);
17 has nestr => ( is => 'rw', isa => NonEmptyStr);
18 has nesimplestr => ( is => 'rw', isa => NonEmptySimpleStr);
19 has password => ( is => 'rw', isa => Password);
20 has strongpassword => ( is => 'rw', isa => StrongPassword);
21
22 has digit => ( is => 'rw', isa => SingleDigit);
23 has posnum => ( is => 'rw', isa => PositiveNum);
24 has posint => ( is => 'rw', isa => PositiveInt);
25 has negnum => ( is => 'rw', isa => NegativeNum);
26 has negint => ( is => 'rw', isa => NegativeInt);
27}
28
29my $ins = FooTest->new;
30
31lives_ok { $ins->simplestr('') } 'SimpleStr';
32lives_ok { $ins->simplestr('good string') } 'SimpleStr 2';
33dies_ok { $ins->simplestr("bad\nstring") } 'SimpleStr 3';
34dies_ok { $ins->simplestr(join('', ("long string" x 25))) } 'SimpleStr 4';
35
36dies_ok { $ins->nestr('') } 'NonEmptyStr';
37lives_ok { $ins->nestr('good string') } 'NonEmptyStr 2';
38lives_ok { $ins->nestr("bad\nstring") } 'NonEmptyStr 3';
39lives_ok { $ins->nestr(join('', ("long string" x 25))) } 'NonEmptyStr 4';
40
41lives_ok { $ins->nesimplestr('good str') } 'NonEmptySimplrStr ';
42dies_ok { $ins->nesimplestr('') } 'NonEmptyStr 2';
43
44dies_ok { $ins->password('no') } 'Password';
45lives_ok { $ins->password('okay') } 'Password 2';
46
47dies_ok { $ins->strongpassword('notokay') } 'StrongPassword';
48lives_ok { $ins->strongpassword('83773r_ch01c3') } 'StrongPassword 2';
49
50dies_ok { $ins->digit(100); } 'SingleDigit';
51lives_ok { $ins->digit(1); } 'SingleDigit 2';
52
53dies_ok { $ins->posint(-100); } 'PositiveInt';
54dies_ok { $ins->posint(100.885); } 'PositiveInt 2';
55lives_ok { $ins->posint(100); } 'PositiveInt 3';
56lives_ok { $ins->posnum(100.885); } 'PositiveNum';
57dies_ok { $ins->posnum(-100.885); } 'PositiveNum 2';
58
59dies_ok { $ins->negint(100); } 'NegativeInt';
60dies_ok { $ins->negint(-100.885); } 'NegativeInt 2';
61lives_ok { $ins->negint(-100); } 'NegativeInt 3';
62lives_ok { $ins->negnum(-100.885); } 'NegativeNum';
63dies_ok { $ins->negnum(100.885); } 'NegativeNum 2';