File: 04-map.t

package info (click to toggle)
libmoosex-types-structured-perl 0.36-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 492 kB
  • sloc: perl: 757; makefile: 11
file content (22 lines) | stat: -rw-r--r-- 606 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use strict;
use warnings;
use Test::More 0.88;
use Test::Fatal;

use MooseX::Types::Moose qw(Int Num);
use MooseX::Types::Structured qw(Map);

my $type = Map[ Int, Num ];

ok($type->assert_valid({ 10 => 10.5 }), "simple Int -> Num mapping");

like( exception { $type->assert_valid({ 10.5 => 10.5 }) },
    qr{value .*10\.5.*}, "non-Int causes rejection on key");

like( exception { $type->assert_valid({ 10 => "ten and a half" }) },
    qr{value .*ten and a half.*}, "non-Num value causes rejection on value");

ok($type->assert_valid({ }), "empty hashref is a valid mapping of any sort");

done_testing;