add begin.t from Method::Signatures
[p5sagit/Function-Parameters.git] / t / lexical.t
CommitLineData
f90b3c0b 1#!perl
2
3use Test::More tests => 16;
4
5use warnings FATAL => 'all';
6use strict;
7
8sub Burlap::fun (&) { $_[0]->() }
9
10{
11 use Function::Parameters;
12
13 is fun { 2 + 2 }->(), 4;
14
15 package Burlap;
16
17 ::ok fun { 0 };
18}
19
20{
21 package Burlap;
22
23 ::is fun { 'singing' }, 'singing';
24}
25
26{
27 sub proc (&) { &Burlap::fun }
28
29 use Function::Parameters { proc => 'function' };
30
31 proc add($x, $y) {
32 return $x + $y;
33 }
34
35 is add(@{[2, 3]}), 5;
36
37 {
38 use Function::Parameters;
39
40 is proc () { 'bla' }->(), 'bla';
41 is method () { $self }->('der'), 'der';
42
43 {
44 no Function::Parameters;
45
46 is proc { 'unk' }, 'unk';
47
48 is eval('fun foo($x) { $x; } 1'), undef;
49 like $@, qr/syntax error/;
50 }
51
52 is proc () { 'bla' }->(), 'bla';
53 is method () { $self }->('der'), 'der';
54
55 no Function::Parameters 'proc';
56 is proc { 'unk2' }, 'unk2';
57 is method () { $self }->('der2'), 'der2';
58 }
59 is proc () { 'bla3' }->(), 'bla3';
60 is eval('fun foo($x) { $x; } 1'), undef;
61 like $@, qr/syntax error/;
62}