Skip to content
Newer
Older
100644 87 lines (71 sloc) 1.79 KB
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored
1 use v6;
2
3 use Test;
4
c99e10b @moritz test interactions between fail() and let/UNDO/KEEP
moritz authored
5 plan 12;
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored
6
4e5f604 [t/spec] fix some smartlinks
moritz authored
7 # L<S04/Phasers/KEEP "at every successful block exit">
8 # L<S04/Phasers/UNDO "at every unsuccessful block exit">
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored
9
10 {
11 my $str;
12 my sub is_pos ($n) {
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
13 return (($n > 0) ?? 1 !! Mu);
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored
14 KEEP { $str ~= "$n > 0 " }
15 UNDO { $str ~= "$n <= 0 " }
16 }
17
18 ok is_pos(1), 'is_pos worked for 1';
19 is $str, '1 > 0 ', 'KEEP ran as expected';
20
21 ok !is_pos(0), 'is_pos worked for 0';
22 is $str, '1 > 0 0 <= 0 ', 'UNDO worked as expected';
23
24 ok !is_pos(-1), 'is_pos worked for 0';
25 is $str, '1 > 0 0 <= 0 -1 <= 0 ', 'UNDO worked as expected';
26 }
27
832f178 [t/spec] fix more smartlinks; down to 33 broken links
moritz authored
28 # L<S04/Phasers/This includes the LEAVE variants, KEEP and UNDO.>
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored
29 {
30 my $str;
31 my sub is_pos($n) {
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
32 return (($n > 0) ?? 1 !! Mu);
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored
33 LEAVE { $str ~= ")" }
34 KEEP { $str ~= "$n > 0" }
35 UNDO { $str ~= "$n <= 0" }
36 LEAVE { $str ~= "(" }
37 }
38
39 is_pos(1);
40 is $str, '(1 > 0)', 'KEEP triggered as part of LEAVE blocks';
41
42 is_pos(-5);
43 is $str, '(1 > 0)(-5 <= 0)', 'UNDO triggered as part of LEAVE blocks';
44 }
45
4e5f604 [t/spec] fix some smartlinks
moritz authored
46 # L<S04/Phasers/"can occur multiple times">
e7ca07b [t] move some tests to spec/, re-worked pre-post.t, some minor correc…
moritz authored
47
48 # multiple KEEP/UNDO
49 {
50 my $str;
51 {
52 KEEP { $str ~= 'K1 ' }
53 KEEP { $str ~= 'K2 ' }
54 UNDO { $str ~= 'U1 ' }
55 UNDO { $str ~= 'U2 ' }
56 1;
57 }
58 is $str, 'K2 K1 ', '2 KEEP blocks triggered';
59 }
60
61 {
62 my $str;
63 {
64 KEEP { $str ~= 'K1 ' }
65 KEEP { $str ~= 'K2 ' }
66 UNDO { $str ~= 'U1 ' }
67 UNDO { $str ~= 'U2 ' }
68 }
69 is $str, 'U2 U1 ', '2 UNDO blocks triggered';
70 }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
71
781dc1f @colomon Change niecza fudging.
colomon authored
72 #?niecza skip "fail NYI"
c99e10b @moritz test interactions between fail() and let/UNDO/KEEP
moritz authored
73 {
74 my $kept = 0;
75 my $undone = 0;
76 sub f() {
77 KEEP $kept = 1;
78 UNDO $undone = 1;
79 fail 'foo';
80 }
81 my $sink = f; #OK
82 nok $kept, 'fail() does not trigger KEEP';
83 ok $undone, 'fail() triggers UNDO';
84 }
85
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
86 # vim: ft=perl6
Something went wrong with that request. Please try again.