File: anon.t

package info (click to toggle)
libspecio-perl 0.50-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 900 kB
  • sloc: perl: 5,165; sh: 23; makefile: 2
file content (38 lines) | stat: -rw-r--r-- 855 bytes parent folder | download | duplicates (6)
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
use strict;
use warnings;

use Test::More 0.96;

use Specio::Declare;
use Specio::Library::Builtins;

{
    my $anon = anon(
        parent => t('Str'),
        where  => sub { length $_[0] },
    );

    isa_ok( $anon, 'Specio::Constraint::Simple', 'return value from anon' );

    ok( $anon->value_is_valid('x'),  q{anon type allows "x"} );
    ok( !$anon->value_is_valid(q{}), 'anon type reject empty string' );
}

{
    my $anon = anon(
        parent => t('Str'),
        inline => sub {
            $_[0]->parent->inline_check( $_[1] ) . " && length $_[1]";
        },
    );

    isa_ok( $anon, 'Specio::Constraint::Simple', 'return value from anon' );

    ok( $anon->value_is_valid('x'), q{inlinable anon type allows "x"} );
    ok(
        !$anon->value_is_valid(q{}),
        'inlinable anon type reject empty string'
    );
}

done_testing();