Perltidy new code
[gitmo/MooseX-Params-Validate.git] / t / 011_allow_extra.t
CommitLineData
df3c7e86 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
7use Test::Fatal;
8
9use MooseX::Params::Validate qw( validated_hash );
10
11{
12 sub foo {
13 my %params = validated_hash(
14 \@_,
15 x => { isa => 'Int' },
16 y => { isa => 'Int' },
17 );
18 \%params;
19 }
20
21 sub bar {
22 my %params = validated_hash(
23 \@_,
24 x => { isa => 'Int' },
25 y => { isa => 'Int' },
26 MX_PARAMS_VALIDATE_ALLOW_EXTRA => 1,
27 );
28 \%params;
29 }
30}
31
32is_deeply(
33 bar( x => 42, y => 1 ),
34 { x => 42, y => 1 },
35 'bar returns expected values with no extra params'
36);
37
38is_deeply(
39 bar( x => 42, y => 1, z => 'whatever' ),
40 { x => 42, y => 1, z => 'whatever' },
41 'bar returns expected values with extra params'
42);
43
44like(
45 exception { foo( x => 42, y => 1, z => 'whatever' ) },
46 qr/The following parameter .+ listed in the validation options: z/,
47 'foo rejects extra params'
48);
49
50done_testing();