/
01-functions.t
35 lines (26 loc) · 917 Bytes
/
01-functions.t
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
#!/usr/bin/env perl6
use v6;
use lib 'lib';
use Test;
use Method::Modifiers;
plan 10;
my $called-chars = False;
my $orig = before(Str, 'chars', { $called-chars = True; });
my $chars = "hello".chars;
is $chars, 5, 'chars returned properly';
ok $called-chars, 'wrapper was called';
ok $orig.restore, 'we restored the original';
$called-chars = False;
$orig = after(Str, 'chars', { $called-chars = True });
$chars = "test".chars;
is $chars, 4, 'chars returned properly';
ok $called-chars, 'wrapper was called';
ok $orig.restore, 'we restored the original';
$orig = around(Str, 'chars', { '<chars>'~callsame~'</chars>' });
$chars = "goodbye".chars;
is $chars, '<chars>7</chars>', 'overridden chars returned properly';
ok $orig.restore, 'we restored the original';
$called-chars = False;
$chars = "mu".chars;
is $chars, 2, 'original chars returns properly';
ok !$called-chars, 'no former modifiers being called';