3 use Test::More tests => 38;
5 use warnings FATAL => 'all';
8 use Function::Parameters {
10 default_arguments => 1,
14 default_arguments => 0,
18 fun foo0($x, $y = 1, $z = 3) { $x * 5 + $y * 2 + $z }
22 is foo0(6, 10, 1), 51;
24 is fun ($answer = 42) { $answer }->(), 42;
26 fun sharingan($input, $x = [], $y = {}) {
33 is_deeply [sharingan 'e'], [['e'], {0 => 'e'}];
34 my $sneaky = ['ants'];
35 is_deeply [sharingan $sneaky], [[['ants']], {0 => ['ants']}];
36 unshift @$sneaky, 'thanks';
37 is_deeply [sharingan $sneaky], [[['thanks', 'ants']], {0 => ['thanks', 'ants']}];
39 is_deeply [sharingan $sneaky], [[['thants']], {0 => ['thants']}];
42 is eval('fun ($x, $y = $x) {}'), undef;
43 like $@, qr/^Global symbol.*explicit package name/;
50 fun guy($d = $d, $x = $d . '2') {
54 is_deeply guy('a', 'b'), ['a', 'b'];
55 is_deeply guy('c'), ['c', 'herp2'];
56 is_deeply guy, ['herp', 'herp2'];
59 is_deeply guy('a', 'b'), ['a', 'b'];
60 is_deeply guy('c'), ['c', 'ort2'];
61 is_deeply guy, ['ort', 'ort2'];
63 my $g = fun ($alarum = $d) { "[$alarum]" };
68 is_deeply guy('bloodstain'), ['bloodstain', 'flowerpot2'];
69 is $g->(), "[flowerpot]";
74 is $f->(), "[flowerpot]";
80 fun edelweiss($x = $c++) :(;$) { $x }
83 is edelweiss "AAAAA", "AAAAA";
84 is_deeply edelweiss [], [];
87 is_deeply edelweiss {}, {};
91 for my $f (fun ($wtf = return 'ohi') { "~$wtf" }) {
97 is eval('fun (@x = 42) {}'), undef;
98 like $@, qr/default value/;
100 is eval('fun ($x, %y = ()) {}'), undef;
101 like $@, qr/default value/;
103 is eval('nofun ($x = 42) {}'), undef;
104 like $@, qr/nofun.*unexpected.*=.*parameter/;