1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
|
use strict;
use warnings;
use Test::More tests => 51;
use Test::Fatal;
use Dancer2::Core::Types;
ok( exception { Str->(undef) }, 'Str does not accept undef value', );
is( exception { Str->('something') }, undef, 'Str', );
like(
exception { Str->( { foo => 'something' } ) },
qr{Reference.+foo.+something.+did not pass type constraint.+Str}, 'Str',
);
is( exception { Num->(34) }, undef, 'Num', );
ok( exception { Num->(undef) }, 'Num does not accept undef value', );
like(
exception { Num->('not a number') },
qr{not a number.+did not pass type constraint.+Num},
'Num fail',
);
is( exception { Bool->(1) }, undef, 'Bool true value', );
is( exception { Bool->(0) }, undef, 'Bool false value', );
is( exception { Bool->(undef) }, undef, 'Bool does accepts undef value', );
like(
exception { Bool->('2') },
qr{2.+did not pass type constraint.+Bool},
'Bool fail',
);
is( exception { RegexpRef->(qr{.*}) }, undef, 'Regexp', );
like(
exception { RegexpRef->('/.*/') },
qr{\Q/.*/\E.+did not pass type constraint.+RegexpRef},
'Regexp fail',
);
ok( exception { RegexpRef->(undef) }, 'Regexp does not accept undef value', );
is( exception { HashRef->( { goo => 'le' } ) }, undef, 'HashRef', );
like(
exception { HashRef->('/.*/') },
qr{\Q/.*/\E.+did not pass type constraint.+HashRef},
'HashRef fail',
);
ok( exception { HashRef->(undef) }, 'HashRef does not accept undef value', );
is( exception { ArrayRef->( [ 1, 2, 3, 4 ] ) }, undef, 'ArrayRef', );
like(
exception { ArrayRef->('/.*/') },
qr{\Q/.*/\E.+did not pass type constraint.+ArrayRef},
'ArrayRef fail',
);
ok( exception { ArrayRef->(undef) }, 'ArrayRef does not accept undef value', );
is( exception {
CodeRef->( sub {44} );
},
undef,
'CodeRef',
);
like(
exception { CodeRef->('/.*/') },
qr{\Q/.*/\E.+did not pass type constraint.+CodeRef},
'CodeRef fail',
);
ok( exception { CodeRef->(undef) }, 'CodeRef does not accept undef value', );
{
package InstanceChecker::zad7;
use Moo;
use Dancer2::Core::Types;
has foo => ( is => 'ro', isa => InstanceOf ['Foo'] );
}
is( exception { InstanceChecker::zad7->new( foo => bless {}, 'Foo' ) },
undef, 'InstanceOf',
);
like(
exception { InstanceChecker::zad7->new( foo => bless {}, 'Bar' ) },
qr{Reference bless.+Bar.+not isa Foo},
'InstanceOf fail',
);
ok( exception { InstanceOf('Foo')->(undef) },
'InstanceOf does not accept undef value',
);
is( exception { Dancer2Prefix->('/foo') }, undef, 'Dancer2Prefix', );
like(
exception { Dancer2Prefix->('bar/something') },
qr{bar/something.+did not pass type constraint.+Dancer2Prefix},
'Dancer2Prefix fail',
);
# see Dancer2Prefix definition, undef is a valid value
like(
exception { Dancer2Prefix->(undef) },
qr/Undef.+did not pass type constraint.+Dancer2Prefix/,
'Dancer2Prefix does not accept undef value',
);
is( exception { Dancer2AppName->('Foo') }, undef, 'Dancer2AppName', );
is( exception { Dancer2AppName->('Foo::Bar') }, undef, 'Dancer2AppName', );
is( exception { Dancer2AppName->('Foo::Bar::Baz') }, undef, 'Dancer2AppName',
);
like(
exception { Dancer2AppName->('Foo:Bar') },
qr{Foo:Bar is not a Dancer2AppName},
'Dancer2AppName fails with single colons',
);
like(
exception { Dancer2AppName->('Foo:::Bar') },
qr{Foo:::Bar is not a Dancer2AppName},
'Dancer2AppName fails with tripe colons',
);
like(
exception { Dancer2AppName->('7Foo') },
qr{7Foo is not a Dancer2AppName},
'Dancer2AppName fails with beginning number',
);
like(
exception { Dancer2AppName->('Foo::45Bar') },
qr{Foo::45Bar is not a Dancer2AppName},
'Dancer2AppName fails with beginning number',
);
like(
exception { Dancer2AppName->('-F') },
qr{-F is not a Dancer2AppName},
'Dancer2AppName fails with special character',
);
like(
exception { Dancer2AppName->('Foo::-') },
qr{Foo::- is not a Dancer2AppName},
'Dancer2AppName fails with special character',
);
like(
exception { Dancer2AppName->('Foo^') },
qr{\QFoo^\E is not a Dancer2AppName},
'Dancer2AppName fails with special character',
);
ok( exception { Dancer2AppName->(undef) },
'Dancer2AppName does not accept undef value',
);
like(
exception { Dancer2AppName->('') },
qr{Empty string is not a Dancer2AppName},
'Dancer2AppName fails an empty string value',
);
is( exception { Dancer2Method->('post') }, undef, 'Dancer2Method', );
like(
exception { Dancer2Method->('POST') },
qr{POST.+did not pass type constraint.+Dancer2Method},
'Dancer2Method fail',
);
ok( exception { Dancer2Method->(undef) },
'Dancer2Method does not accept undef value',
);
is( exception { Dancer2HTTPMethod->('POST') }, undef, 'Dancer2HTTPMethod', );
like(
exception { Dancer2HTTPMethod->('post') },
qr{post.+did not pass type constraint.+Dancer2HTTPMethod},
'Dancer2HTTPMethod fail',
);
ok( exception { Dancer2HTTPMethod->(undef) },
'Dancer2Method does not accept undef value',
);
use Dancer2::Core::Error;
use Dancer2::Core::Hook;
ok( exception { Hook->(undef) }, 'Hook does not accept undef value' );
ok(exception { Hook->(Dancer2::Core::Error->new) },
'Hook does not Core::Error as value');
is( exception {
Hook->(Dancer2::Core::Hook->new(name => 'test', code => sub { }))
},
undef,
'Hook',
);
is(exception { ReadableFilePath->('t') }, undef, 'ReadableFilePath');
like(
exception { ReadableFilePath->('nosuchdirectory') },
qr/Value "nosuchdirectory" did not pass type constraint "ReadableFilePath"/,
'ReadableFilePath'
);
|