]> git.vpit.fr Git - perl/modules/with.git/blob - t/14-defer.t
Importing with-0.02.tar.gz
[perl/modules/with.git] / t / 14-defer.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 8;
7
8 use with \bless {}, 'with::Mock';
9
10 sub shift { }
11 sub with::Mock::pop { }
12 sub durrr () { 79 }
13 sub dongs () { 53 }
14 sub with::Mock::dongs { CORE::shift; $_[0] + $_[1] }
15 sub hlagh { 2 * $_[0] + $_[1] }
16 sub with::Mock::boner { CORE::shift; $_[0] + 2 * $_[1] }
17
18 my @a;
19 @a = 1;
20 push @a, 2;         # with::corewrap, defaulting to CORE
21 is $a[1], 2, 'CORE::push';
22 shift @a;           # with::corewrap, function in caller namespace
23 is $a[1], 2, 'main::shift';
24 pop @a;             # with::corewrap, method call
25 is $a[1], 2, 'with::Mock::pop';
26 my $x = durrr @a;   # with::subwrap, function in caller namespace
27 is $x, 79, 'main::durrr';
28 my $y = dongs @a;   # with::subwrap, method call
29 is $y, 3, 'with::Mock::dongs';
30 my $z = hlagh @a;   # with::defer, function in caller namespace
31 is $z, 4, 'main::hlagh';
32 my $t = boner @a;   # with::defer, method call
33 is $t, 5, 'with::Mock::boner';
34 eval { zogzog @a }; # with::defer, no such fonction
35 like $@, qr/Undefined\s+subroutine/, 'no zogzog';
36