Fix Changes
[gitmo/MooseX-Params-Validate.git] / t / 012_ref_as_first_param.t
CommitLineData
954fa4ca 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
7use Test::Fatal;
8
9{
10 use MooseX::Params::Validate;
11
12 sub foo {
13 my ( $x, $y ) = validated_list(
14 \@_,
15 x => { isa => 'Any' },
16 y => { isa => 'Any' },
17 );
18
19 return { x => $x, y => $y };
20 }
21
22 sub bar {
23 my %p = validated_hash(
24 \@_,
25 x => { isa => 'Any' },
26 y => { isa => 'Any' },
27 );
28
29 return \%p;
30 }
31
32 sub baz {
33 my ( $x, $y ) = pos_validated_list(
34 \@_,
35 { isa => 'Any' },
36 { isa => 'Any' },
37 );
38
39 return { x => $x, y => $y };
40 }
41}
42
43is_deeply(
44 foo( x => 42, y => 84 ),
45 { x => 42, y => 84 },
46 'validated_list accepts a plain hash'
47);
48
49is_deeply(
50 foo( { x => 42, y => 84 } ),
51 { x => 42, y => 84 },
52 'validated_list accepts a hash reference'
53);
54
55is_deeply(
56 bar( x => 42, y => 84 ),
57 { x => 42, y => 84 },
58 'validated_hash accepts a plain hash'
59);
60
61is_deeply(
62 bar( { x => 42, y => 84 } ),
63 { x => 42, y => 84 },
64 'validated_hash accepts a hash reference'
65);
66
67is_deeply(
68 baz( 42, 84 ),
69 { x => 42, y => 84 },
70 'pos_validated_list accepts a plain array'
71);
72
73is_deeply(
74 baz( [42, 84] ),
75 { x => 42, y => 84 },
76 'pos_validated_list accepts a array reference'
77);
78
79done_testing();