version bump
[p5sagit/Function-Parameters.git] / t / imports.t
CommitLineData
247cbd51 1#!perl
2
7817d698 3use Test::More tests => 48;
247cbd51 4
5use warnings FATAL => 'all';
6use strict;
7
8{
9 use Function::Parameters {}; # ZERO BABIES
10
11 is eval('fun foo :() {}; 1'), undef;
12 like $@, qr/syntax error/;
13}
14
15{
16 use Function::Parameters { pound => 'function' };
17
18 is eval('fun foo :() {}; 1'), undef;
19 like $@, qr/syntax error/;
20
7817d698 21 pound foo_1($x, $u) { $x }
247cbd51 22 is foo_1(2 + 2), 4;
23
24 no Function::Parameters qw(pound);
25
26 is eval('pound foo() {}; 1'), undef;
27 like $@, qr/syntax error/;
28}
29
30{
31 use Function::Parameters { pound => 'method' };
32
33 is eval('fun foo () {}; 1'), undef;
34 like $@, qr/syntax error/;
35
7817d698 36 pound foo_2($u) { $self }
247cbd51 37 is foo_2(2 + 2), 4;
38
39 no Function::Parameters qw(pound);
40
41 is eval('pound unfoo :() {}; 1'), undef;
42 like $@, qr/syntax error/;
43}
44
45{
46 is eval('pound unfoo( ){}; 1'), undef;
47 like $@, qr/syntax error/;
48
49 use Function::Parameters { pound => 'classmethod' };
50
51 is eval('fun foo () {}; 1'), undef;
52 like $@, qr/syntax error/;
53
7817d698 54 pound foo_3($u) { $class }
247cbd51 55 is foo_3(2 + 2), 4;
56
57 no Function::Parameters;
58
59 is eval('pound unfoo :lvalue{}; 1'), undef;
60 like $@, qr/syntax error/;
61}
62
7817d698 63{
64 use Function::Parameters { pound => 'function_strict' };
65
66 is eval('fun foo :() {}; 1'), undef;
67 like $@, qr/syntax error/;
68
69 pound foo_4($x) { $x }
70 is foo_4(2 + 2), 4;
71
72 is eval('foo_4(5, 6)'), undef;
73 like $@, qr/Too many arguments/;
74
75 no Function::Parameters qw(pound);
76
77 is eval('pound foo() {}; 1'), undef;
78 like $@, qr/syntax error/;
79}
80
81{
82 use Function::Parameters { pound => 'method_strict' };
83
84 is eval('fun foo () {}; 1'), undef;
85 like $@, qr/syntax error/;
86
87 pound foo_5() { $self }
88 is foo_5(2 + 2), 4;
89
90 is eval('foo_5(5, 6)'), undef;
91 like $@, qr/Too many arguments/;
92
93 no Function::Parameters qw(pound);
94
95 is eval('pound unfoo :() {}; 1'), undef;
96 like $@, qr/syntax error/;
97}
98
99{
100 is eval('pound unfoo( ){}; 1'), undef;
101 like $@, qr/syntax error/;
102
103 use Function::Parameters { pound => 'classmethod_strict' };
104
105 is eval('fun foo () {}; 1'), undef;
106 like $@, qr/syntax error/;
107
108 pound foo_6() { $class }
109 is foo_6(2 + 2), 4;
110
111 is eval('foo_6(5, 6)'), undef;
112 like $@, qr/Too many arguments/;
113
114 no Function::Parameters;
115
116 is eval('pound unfoo :lvalue{}; 1'), undef;
117 like $@, qr/syntax error/;
118}
119
247cbd51 120is eval('Function::Parameters->import(":QQQQ"); 1'), undef;
121like $@, qr/valid identifier/;
122
123is eval('Function::Parameters->import({":QQQQ" => "function"}); 1'), undef;
124like $@, qr/valid identifier/;
125
126is eval('Function::Parameters->import({"jetsam" => "QQQQ"}); 1'), undef;
127like $@, qr/valid type/;