Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 74 lines (60 sloc) 2.003 kB
b254a8b [gsoc_spectest] Test reorganization.
Auzon authored
1 use v6;
2
3 use Test;
4
efc7dbc [STD] implement :P5
lwall authored
5 =begin comment
b254a8b [gsoc_spectest] Test reorganization.
Auzon authored
6
7 This tests the &?ROUTINE magical value
8
efc7dbc [STD] implement :P5
lwall authored
9 =end comment
b254a8b [gsoc_spectest] Test reorganization.
Auzon authored
10
933094d @jnthn Extra, missing, stress test for &?ROUTINE.
jnthn authored
11 plan 10;
b254a8b [gsoc_spectest] Test reorganization.
Auzon authored
12
13 # L<S06/The C<&?ROUTINE> object>
14 # L<S02/Names/Which routine am I in>
15 sub factorial { @_[0] < 2 ?? 1 !! @_[0] * &?ROUTINE(@_[0] - 1) }
16
17 my $result1 = factorial(3);
18 is($result1, 6, 'the &?ROUTINE magical works correctly');
19
20 my $factorial = sub { @_[0] < 2 ?? 1 !! @_[0] * &?ROUTINE(@_[0] - 1) };
21 my $result2 = $factorial(3);
22 is($result2, 6, 'the &?ROUTINE magical works correctly in anon-subs');
23
24 sub postfix:<!!!> (Int $n) { $n < 2 ?? 1 !! $n * &?ROUTINE($n - 1) }
25 my $result3 = 3!!!;
26 is($result3, 6, 'the &?ROUTINE magical works correctly in overloaded operators' );
27
ee9b043 @timo test that &?ROUTINE gets set in regex/token/rule.
timo authored
28 {
29 my $variable;
30 my regex foo { a { $variable = &?ROUTINE; } }
31 my token bar { b { $variable = &?ROUTINE; } }
32 my rule baz { c { $variable = &?ROUTINE; } }
33 "a" ~~ &foo;
34 is $variable, &foo, '&?ROUTINE is correct inside a regex';
35 "b" ~~ &bar;
36 is $variable, &bar, '&?ROUTINE is correct inside a token';
37 "c" ~~ &baz;
38 is $variable, &baz, '&?ROUTINE is correct inside a rule';
39 }
40
109bb8e @skids Refine JVM fudges/skips for relatively new tests
skids authored
41 #?rakudo.jvm skip 'java.lang.NullPointerException (openjdk)'
4331787 @jnthn Test closure semantics of &?ROUTINE.
jnthn authored
42 {
43 my @collected;
44 sub foo($a) {
45 sub bar($n) {
46 @collected.push($a);
47 $n == 1 ?? 1 !! $n * &?ROUTINE($n - 1)
48 }
49 }
50 my $r1 = foo('a');
51 my $r2 = foo('b');
52 is $r1(4), 24, 'Correct result from function generator returning function using &?ROUTINE';
53 is @collected.join(''), 'aaaa', 'Correct closure semantics with &?ROUTINE';
54 }
55
933094d @jnthn Extra, missing, stress test for &?ROUTINE.
jnthn authored
56 {
57 my @collected;
58 sub foo($a) {
59 sub bar($n) {
60 my $what-to-do = {
61 @collected.push($a);
62 $n == 1 ?? 1 !! $n * &?ROUTINE($n - 1)
63 }
64 $what-to-do();
65 }
66 }
67 my $r1 = foo('a');
68 my $r2 = foo('b');
69 is $r1(4), 24, 'Correct result using &?ROUTINE in nested closure';
70 is @collected.join(''), 'aaaa', 'Correct closure semantics with &?ROUTINE in nested closure';
71 }
72
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
73 # vim: ft=perl6
Something went wrong with that request. Please try again.