Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 50 lines (36 sloc) 1.357 kb
2b21ee3 [t] move lazy.t to spec/
moritz authored
1 use v6;
2
3 use Test;
4
eda6db1 [t/spec] move smartlinks from POD to ordinary comments
moritz authored
5 # L<S04/Other C<do>-like forms/lazy>
2b21ee3 [t] move lazy.t to spec/
moritz authored
6
a2275c3 Moritz Lenz [lazy.t] make much more realisitic
moritz authored
7 plan 12;
2b21ee3 [t] move lazy.t to spec/
moritz authored
8
9 {
10 my $was_in_lazy;
11
8fb35f5 Moritz Lenz simplify subrule.t a bit
moritz authored
12 my $var := LAZY { $was_in_lazy++; 42 };
2b21ee3 [t] move lazy.t to spec/
moritz authored
13
14 ok !$was_in_lazy, 'our lazy block wasn\'t yet executed (1)';
15
16 is $var, 42, 'our lazy var has the correct value';
17 ok $was_in_lazy, 'our lazy block was executed';
18
19 is $var, 42, 'our lazy var still has the correct value';
20 is $was_in_lazy, 1, 'our lazy block was not executed again';
21 }
22
23 # dies_ok/lives_ok tests:
24 {
25 my $was_in_lazy;
8fb35f5 Moritz Lenz simplify subrule.t a bit
moritz authored
26 my $lazy := LAZY { $was_in_lazy++; 42 };
2b21ee3 [t] move lazy.t to spec/
moritz authored
27 lives_ok { $lazy = 23 }, "reassigning our var containing a lazy worked (1)";
28 is $lazy, 23, "reassigning our var containing a lazy worked (2)";
29 ok !$was_in_lazy, "reassigning our var containing a lazy worked (3)";
30 }
31
32 {
33 my $was_in_lazy;
8fb35f5 Moritz Lenz simplify subrule.t a bit
moritz authored
34 my $lazy := LAZY { $was_in_lazy++; 42 };
2b21ee3 [t] move lazy.t to spec/
moritz authored
35 lives_ok { $lazy := 23 }, "rebinding our var containing a lazy worked (1)";
36 is $lazy, 23, "rebinding our var containing a lazy worked (2)";
37 ok !$was_in_lazy, "rebinding our var containing a lazy worked (3)";
38 }
39
a2275c3 Moritz Lenz [lazy.t] make much more realisitic
moritz authored
40 #?rakudo todo 'why ever not?'
2b21ee3 [t] move lazy.t to spec/
moritz authored
41 {
8fb35f5 Moritz Lenz simplify subrule.t a bit
moritz authored
42 dies_ok { (LAZY { 42 }) = 23 },
2b21ee3 [t] move lazy.t to spec/
moritz authored
43 "directly assigning to a lazy var does not work";
44 }
45
46 # Arguably, we should remove the $was_in_lazy tests, as it doesn't really
47 # matter when the lazy {...} block is actually executed.
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
48
49 # vim: ft=perl6
Something went wrong with that request. Please try again.