Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 84 lines (61 sloc) 2.279 kb
875fe1c [t] move rvalue.t to spec/
moritz authored
1 use v6;
2
3 # Test control blocks (BEGIN/CHECK/INIT/END) used as rvalues
4 # [TODO] add tests for other control blocks
5
6 use Test;
7
55f8681 [t/spec] simpler tests for BEGIN blocks as expressions; tests RT #62188 ...
moritz authored
8 plan 16;
875fe1c [t] move rvalue.t to spec/
moritz authored
9
4e5f604 [t/spec] fix some smartlinks
moritz authored
10 # L<S04/Phasers/"marked with a *" "used within" expression>
875fe1c [t] move rvalue.t to spec/
moritz authored
11
55f8681 [t/spec] simpler tests for BEGIN blocks as expressions; tests RT #62188 ...
moritz authored
12 {
13 my $x = BEGIN { 8 };
14 is $x, 8, 'BEGIN block as expression';
875fe1c [t] move rvalue.t to spec/
moritz authored
15
55f8681 [t/spec] simpler tests for BEGIN blocks as expressions; tests RT #62188 ...
moritz authored
16 # test that built-ins are available within a BEGIN block:
ea3913c @moritz more rakudo fudging, move unrelated tests to use uc instead of tc
moritz authored
17 my $y = BEGIN { uc 'moin' };
18 is $y, 'MOIN', 'can access built-in functions in BEGIN blocks';
875fe1c [t] move rvalue.t to spec/
moritz authored
19
ea3913c @moritz more rakudo fudging, move unrelated tests to use uc instead of tc
moritz authored
20 my $z = BEGIN { 'moin'.uc };
21 is $z, 'MOIN', 'can access built-in methods in BEGIN blocks';
875fe1c [t] move rvalue.t to spec/
moritz authored
22 }
23
55f8681 [t/spec] simpler tests for BEGIN blocks as expressions; tests RT #62188 ...
moritz authored
24 {
25 my $x = BEGIN 8;
26 is $x, 8, 'BEGIN statement prefix as expression';
875fe1c [t] move rvalue.t to spec/
moritz authored
27
55f8681 [t/spec] simpler tests for BEGIN blocks as expressions; tests RT #62188 ...
moritz authored
28 # test that built-ins are available within a BEGIN block:
ea3913c @moritz more rakudo fudging, move unrelated tests to use uc instead of tc
moritz authored
29 my $y = BEGIN uc 'moin';
30 is $y, 'MOIN', 'can access built-in functions in BEGIN statement prefix';
875fe1c [t] move rvalue.t to spec/
moritz authored
31
ea3913c @moritz more rakudo fudging, move unrelated tests to use uc instead of tc
moritz authored
32 my $z = BEGIN 'moin'.uc;
33 is $z, 'MOIN', 'can access built-in methods in BEGIN statement prefix';
875fe1c [t] move rvalue.t to spec/
moritz authored
34 }
35
55f8681 [t/spec] simpler tests for BEGIN blocks as expressions; tests RT #62188 ...
moritz authored
36 {
39214ef @TimToady actually test what the test is supposed to
TimToady authored
37 my $hist; # DO NOT INITIALIZE HERE! (my runs after these blocks)
875fe1c [t] move rvalue.t to spec/
moritz authored
38
55f8681 [t/spec] simpler tests for BEGIN blocks as expressions; tests RT #62188 ...
moritz authored
39 # Test INIT {} as rval:
875fe1c [t] move rvalue.t to spec/
moritz authored
40
55f8681 [t/spec] simpler tests for BEGIN blocks as expressions; tests RT #62188 ...
moritz authored
41 my $init_val;
42 my $init = {
39214ef @TimToady actually test what the test is supposed to
TimToady authored
43 $init_val = INIT { '' ~ ($hist ~= 'I') };
55f8681 [t/spec] simpler tests for BEGIN blocks as expressions; tests RT #62188 ...
moritz authored
44 }
45
ba48d7b @coke niecza fudge
coke authored
46 #?niecza todo 'block returns no value'
55f8681 [t/spec] simpler tests for BEGIN blocks as expressions; tests RT #62188 ...
moritz authored
47 is $init(), 'BCI', 'INIT {} runs only once';
ba48d7b @coke niecza fudge
coke authored
48 #?niecza todo 'block returns no value'
55f8681 [t/spec] simpler tests for BEGIN blocks as expressions; tests RT #62188 ...
moritz authored
49 is $init_val, 'BCI', 'INIT {} as rval is its ret val';
ba48d7b @coke niecza fudge
coke authored
50 #?niecza todo 'block returns no value'
55f8681 [t/spec] simpler tests for BEGIN blocks as expressions; tests RT #62188 ...
moritz authored
51 is $init(), 'BCI', 'INIT {} runs only once';
52
53 # Test CHECK {} as rval:
54
55 my $check_val;
56 my $check = {
39214ef @TimToady actually test what the test is supposed to
TimToady authored
57 $check_val = CHECK { '' ~ ($hist ~= 'C') };
55f8681 [t/spec] simpler tests for BEGIN blocks as expressions; tests RT #62188 ...
moritz authored
58 }
875fe1c [t] move rvalue.t to spec/
moritz authored
59
ba48d7b @coke niecza fudge
coke authored
60 #?niecza todo 'block returns no value'
55f8681 [t/spec] simpler tests for BEGIN blocks as expressions; tests RT #62188 ...
moritz authored
61 is $check(), 'BC', 'CHECK {} runs only once';
ba48d7b @coke niecza fudge
coke authored
62 #?niecza todo 'block returns no value'
55f8681 [t/spec] simpler tests for BEGIN blocks as expressions; tests RT #62188 ...
moritz authored
63 is $check_val, 'BC', 'CHECK {} as rval is its ret val';
ba48d7b @coke niecza fudge
coke authored
64 #?niecza todo 'block returns no value'
55f8681 [t/spec] simpler tests for BEGIN blocks as expressions; tests RT #62188 ...
moritz authored
65 is $check(), 'BC', 'CHECK {} runs only once';
875fe1c [t] move rvalue.t to spec/
moritz authored
66
55f8681 [t/spec] simpler tests for BEGIN blocks as expressions; tests RT #62188 ...
moritz authored
67 # Test BEGIN {} as rval:
875fe1c [t] move rvalue.t to spec/
moritz authored
68
55f8681 [t/spec] simpler tests for BEGIN blocks as expressions; tests RT #62188 ...
moritz authored
69 my $begin_val;
70 my $begin = {
39214ef @TimToady actually test what the test is supposed to
TimToady authored
71 $begin_val = BEGIN { '' ~ ($hist ~= 'B') };
55f8681 [t/spec] simpler tests for BEGIN blocks as expressions; tests RT #62188 ...
moritz authored
72 }
73
74 is $begin(), 'B', 'BEGIN {} runs only once';
75 is $begin_val, 'B', 'BEGIN {} as rval is its ret val';
76 is $begin(), 'B', 'BEGIN {} runs only once';
77
78 # Test END {} as rval:
bb5077a @FROGGS eval => EVAL in S03 and S04
FROGGS authored
79 #?niecza skip 'Excess arguments to EVAL, used 1 of 2 positionals'
80 ok !EVAL('my $end_val = END { 3 }'), "END {} can't be used as a rvalue";
55f8681 [t/spec] simpler tests for BEGIN blocks as expressions; tests RT #62188 ...
moritz authored
81 }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
82
39214ef @TimToady actually test what the test is supposed to
TimToady authored
83 # vim: ft=perl6 expandtab sw=4
Something went wrong with that request. Please try again.