1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
#!perl
use strict;
use warnings FATAL => 'all';
use Test::More tests => 58;
use Test::Fatal;
{
use Function::Parameters {}; # ZERO BABIES
is eval('fun foo :() {}; 1'), undef;
like $@, qr/syntax error/;
}
{
use Function::Parameters { pound => 'function' };
is eval('fun foo :() {}; 1'), undef;
like $@, qr/syntax error/;
pound foo_1($x) { $x }
is foo_1(2 + 2), 4;
like exception { foo_1(5, 6) }, qr/Too many arguments/;
no Function::Parameters qw(pound);
is eval('pound foo() {}; 1'), undef;
like $@, qr/syntax error/;
}
{
use Function::Parameters { pound => 'method' };
is eval('fun foo () {}; 1'), undef;
like $@, qr/syntax error/;
pound foo_2() { $self }
is foo_2(2 + 2), 4;
like exception { foo_2(5, 6) }, qr/Too many arguments/;
no Function::Parameters qw(pound);
is eval('pound unfoo :() {}; 1'), undef;
like $@, qr/syntax error/;
}
{
is eval('pound unfoo( ){}; 1'), undef;
like $@, qr/syntax error/;
use Function::Parameters { pound => 'classmethod' };
is eval('fun foo () {}; 1'), undef;
like $@, qr/syntax error/;
pound foo_3() { $class }
is foo_3(2 + 2), 4;
like exception { foo_3(5, 6) }, qr/Too many arguments/;
no Function::Parameters;
is eval('pound unfoo :lvalue{}; 1'), undef;
like $@, qr/syntax error/;
}
{
use Function::Parameters { pound => 'function_strict' };
is eval('fun foo :() {}; 1'), undef;
like $@, qr/syntax error/;
pound foo_4($x) { $x }
is foo_4(2 + 2), 4;
like exception { foo_4(5, 6) }, qr/Too many arguments/;
no Function::Parameters qw(pound);
is eval('pound foo() {}; 1'), undef;
like $@, qr/syntax error/;
}
{
use Function::Parameters { pound => 'method_strict' };
is eval('fun foo () {}; 1'), undef;
like $@, qr/syntax error/;
pound foo_5() { $self }
is foo_5(2 + 2), 4;
like exception { foo_5(5, 6) }, qr/Too many arguments/;
no Function::Parameters qw(pound);
is eval('pound unfoo :() {}; 1'), undef;
like $@, qr/syntax error/;
}
{
is eval('pound unfoo( ){}; 1'), undef;
like $@, qr/syntax error/;
use Function::Parameters { pound => 'classmethod_strict' };
is eval('fun foo () {}; 1'), undef;
like $@, qr/syntax error/;
pound foo_6() { $class }
is foo_6(2 + 2), 4;
like exception { foo_6(5, 6) }, qr/Too many arguments/;
no Function::Parameters;
is eval('pound unfoo :lvalue{}; 1'), undef;
like $@, qr/syntax error/;
}
{
use Function::Parameters qw(method);
is method () { $self + 2 }->(2), 4;
is eval('fun () {}'), undef;
like $@, qr/syntax error/;
}
{
use Function::Parameters qw(method fun);
is method () { $self + 2 }->(2), 4;
is fun ($x) { $x + 2 }->(2), 4;
}
{
use Function::Parameters qw(:std), { def => 'function' };
is method () { $self + 2 }->(2), 4;
is fun ($x) { $x + 2 }->(2), 4;
is def ($x) { $x + 2 }->(2), 4;
}
like exception { Function::Parameters->import(":QQQQ") }, qr/not exported/;
like exception { Function::Parameters->import({":QQQQ" => "function"}) }, qr/valid identifier/;
like exception { Function::Parameters->import({"jetsam" => "QQQQ"}) }, qr/valid type/;
like exception { Function::Parameters->import("asdf") }, qr/not exported/;
for my $kw ('', '42', 'A::B', 'a b') {
like exception { Function::Parameters->import({ $kw => 'function' }) }, qr/valid identifier /;
}
|