Commit | Line | Data |
98e6239b |
1 | #!perl |
2 | use warnings FATAL => 'all'; |
3 | use strict; |
4 | |
5 | use Test::More; |
6 | |
7 | { |
8 | package Foo; |
9 | |
10 | use Test::More; |
11 | use Test::Fatal;; |
12 | use Function::Parameters qw(:strict); |
13 | |
14 | method formalize($text, :$justify = "left", :$case = undef) { |
15 | my %params; |
16 | $params{text} = $text; |
17 | $params{justify} = $justify; |
18 | $params{case} = $case if defined $case; |
19 | |
20 | return \%params; |
21 | } |
22 | |
23 | is_deeply( Foo->formalize( "stuff" ), { text => "stuff", justify => "left" } ); |
24 | |
25 | like exception { Foo->formalize( "stuff", wibble => 23 ) }, qr/\bnamed\b.+\bwibble\b/; |
26 | |
27 | method foo( :$arg ) { |
28 | return $arg; |
29 | } |
30 | |
31 | is( Foo->foo( arg => 42 ), 42 ); |
32 | like exception { foo() }, qr/Not enough arguments/; |
33 | |
34 | |
35 | # Compile time errors need internal refactoring before I can get file, line and method |
36 | # information. |
37 | eval q{ |
38 | method wrong( :$named, $pos ) {} |
39 | }; |
40 | like $@, qr/\bpositional\b.+\$pos\b.+\bnamed\b.+\$named\b/; |
41 | |
42 | eval q{ |
43 | method wrong( $foo, :$named, $bar ) {} |
44 | }; |
45 | like $@, qr/\bpositional\b.+\$bar\b.+\bnamed\b.+\$named\b/; |
46 | |
47 | eval q{ |
48 | method wrong( $foo, $bar = undef, :$named ) {} |
49 | }; |
50 | like $@, qr/\boptional positional\b.+\$bar\b.+\brequired named\b.+\$named\b/; |
51 | } |
52 | |
53 | |
54 | done_testing(); |