Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

280 lines (230 sloc) 5.397 kb
use strict;
use warnings;
use Test::More skip_all => "skipped, waiting for these to be merged : https://github.com/mateu/MooX-Types-MooseLike/issues/14 && https://github.com/mateu/MooX-Types-MooseLike/issues/13"; # tests => 46
use Test::Fatal;
use Dancer::Core::Types;
ok(
exception { Str->(undef) },
'Str does not accept undef value',
);
is(
exception { Str->('something') },
undef,
'Str',
);
like(
exception { Str->({foo => 'something'}) },
qr{HASH\(\w+\) is not a string},
'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 is not a Number},
'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 is not a Boolean},
'Bool fail',
);
is(
exception { RegexpRef->(qr{.*}) },
undef,
'Regexp',
);
like(
exception { RegexpRef->('/.*/') },
qr{\Q/.*/\E is not a 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 is not a 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 is not an 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 is not a CodeRef},
'CodeRef fail',
);
ok(
exception { CodeRef->(undef) },
'CodeRef does not accept undef value',
);
{
package InstanceChecker::zad7;
use Moo;
use Dancer::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{Bar=HASH\(\w+\) is not an instance of the class: Foo},
'InstanceOf fail',
);
ok(
exception { InstanceOf('Foo')->(undef) },
'InstanceOf does not accept undef value',
);
is(
exception { DancerPrefix->('/foo') },
undef,
'DancerPrefix',
);
like(
exception { DancerPrefix->('bar/something') },
qr{does not pass the type constraint for type `DancerPrefix'},
'DancerPrefix fail',
);
ok(
exception { DancerPrefix->(undef) },
'DancerPrefix does not accept undef value',
);
is(
exception { DancerAppName->('Foo') },
undef,
'DancerAppName',
);
is(
exception { DancerAppName->('Foo::Bar') },
undef,
'DancerAppName',
);
is(
exception { DancerAppName->('Foo::Bar::Baz') },
undef,
'DancerAppName',
);
like(
exception { DancerAppName->('Foo:Bar') },
qr{does not pass the type constraint for type `DancerAppName'},
'DancerAppName fails with single colons',
);
like(
exception { DancerAppName->('Foo:::Bar') },
qr{does not pass the type constraint for type `DancerAppName'},
'DancerAppName fails with tripe colons',
);
like(
exception { DancerAppName->('7Foo') },
qr{does not pass the type constraint for type `DancerAppName'},
'DancerAppName fails with beginning number',
);
like(
exception { DancerAppName->('Foo::45Bar') },
qr{does not pass the type constraint for type `DancerAppName'},
'DancerAppName fails with beginning number',
);
like(
exception { DancerAppName->('-F') },
qr{does not pass the type constraint for type `DancerAppName'},
'DancerAppName fails with special character',
);
like(
exception { DancerAppName->('Foo::-') },
qr{does not pass the type constraint for type `DancerAppName'},
'DancerAppName fails with special character',
);
like(
exception { DancerAppName->('Foo^') },
qr{does not pass the type constraint for type `DancerAppName'},
'DancerAppName fails with special character',
);
ok(
exception { DancerAppName->(undef) },
'DancerAppName does not accept undef value',
);
like(
exception { DancerAppName->('') },
qr{does not pass the type constraint for type `DancerAppName'},
'DancerAppName fails an empty string value',
);
is(
exception { DancerMethod->('post') },
undef,
'DancerMethod',
);
like(
exception { DancerMethod->('POST') },
qr{does not pass the type constraint for type `DancerMethod'},
'DancerMethod fail',
);
ok(
exception { DancerMethod->(undef) },
'DancerMethod does not accept undef value',
);
is(
exception { DancerHTTPMethod->('POST') },
undef,
'DancerHTTPMethod',
);
like(
exception { DancerHTTPMethod->('post') },
qr{does not pass the type constraint for type `DancerHTTPMethod'},
'DancerHTTPMethod fail',
);
ok(
exception { DancerHTTPMethod->(undef) },
'DancerMethod does not accept undef value',
);
Jump to Line
Something went wrong with that request. Please try again.