Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 89 lines (72 sloc) 1.558 kB
fde97fb [spec] moved all tests from t/statemens/modifiers into t/spec/S04-sta…
dr_df0 authored
1 use v6;
2
3 use Test;
4
8ab25b4 @jnthn Tests for block s.m. given/if/unless.
jnthn authored
5 plan 13;
fde97fb [spec] moved all tests from t/statemens/modifiers into t/spec/S04-sta…
dr_df0 authored
6
7 # L<S04/"Conditional statements"/Conditional statement modifiers work as in Perl 5>
8
9 # test the if statement modifier
10 {
11 my $a = 1;
12 $a = 2 if 'a' eq 'a';
13 is($a, 2, "post if");
14 }
15
16 {
17 my $a = 1;
18 $a = 3 if 'a' eq 'b';
19 is($a, 1, "post if");
20 }
085546c [spec] t/spec/S04-statemet-modifiers/if.t merged from few files and f…
dr_df0 authored
21
22 {
23 my $answer = 1;
4aabc62 [t/spec]: Unfudge + clean up tests of ($value if answer) statement m…
pmichaud authored
24 my @x = 41, (42 if $answer), 43;
25 my @y = 41, ($answer ?? 42 !! ()), 43;
085546c [spec] t/spec/S04-statemet-modifiers/if.t merged from few files and f…
dr_df0 authored
26 my @z = 41, 42, 43;
27 is @y, @z, "sanity check";
28 is @x, @y, "if expr on true cond";
29 }
30
a06ec47 [spec] tests added to 'S04-statement-modifiers/if.t' showing that 'if…
dr_df0 authored
31 {
32 my $answer = 0;
4aabc62 [t/spec]: Unfudge + clean up tests of ($value if answer) statement m…
pmichaud authored
33 my @x = 41, (42 if $answer), 43;
34 my @y = 41, ($answer ?? 42 !! ()), 43;
35 my @z = 41, 43;
a06ec47 [spec] tests added to 'S04-statement-modifiers/if.t' showing that 'if…
dr_df0 authored
36 is @y, @z, "sanity check";
6ef1b5d @coke niecza fudge
coke authored
37 #?niecza todo "empty list as element not flattened - https://github.com/sorear/niecza/issues/180"
4aabc62 [t/spec]: Unfudge + clean up tests of ($value if answer) statement m…
pmichaud authored
38 is @x, @y, "if expr on false cond";
a06ec47 [spec] tests added to 'S04-statement-modifiers/if.t' showing that 'if…
dr_df0 authored
39 }
40
41
085546c [spec] t/spec/S04-statemet-modifiers/if.t merged from few files and f…
dr_df0 authored
42 #testing else part of the operator
43 {
44 my $answer = 0;
45 my $x = $answer ?? 42 !! 43;
46 is $x, 43, "?? || sanity check";
47 }
48
49 {
50 sub foo() {
831838f @TimToady tweaks for Nil/Empty distinction
TimToady authored
51 return () if 1;
085546c [spec] t/spec/S04-statemet-modifiers/if.t merged from few files and f…
dr_df0 authored
52 123;
53 }
54
55 my $ok = 1;
56 for foo() -> @foo {
57 $ok = 0;
58 }
59 ok $ok, "condition in statement level respects context"
60 }
cd5ba38 [t/spec] test ($expresion if $condition) in scalar context
moritz authored
61
62 {
63 my $x = (3 if 1);
64 my $y = (3 if 0);
65 is $x, 3, '(3 if 1) worked in scalar context';
66 ok !$y, 'my $y = (3 if 0) leaves $y false';
67 }
336df4a RT
moritz authored
68
831838f @TimToady tweaks for Nil/Empty distinction
TimToady authored
69 # return value of false 'if' should be Empty
81ce684 @coke standardize on RT #, not URL
coke authored
70 # RT #66544
336df4a RT
moritz authored
71 {
831838f @TimToady tweaks for Nil/Empty distinction
TimToady authored
72 is (42 if 0), Empty, '"$something if 0" is Empty';
336df4a RT
moritz authored
73 }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
74
8ab25b4 @jnthn Tests for block s.m. given/if/unless.
jnthn authored
75 {
76 my $a = 'oops';
77 { $a = 'ok' } if 1;
78 is $a, 'ok', 'Statement-modifier if runs bare block';
79 }
80
81 # RT #78142
82 {
83 my $a = 'oops';
84 { $a = $^x } if 100;
85 is $a, 100, 'Statement-modifier if runs block with placeholder';
86 }
87
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
88 # vim: ft=perl6
Something went wrong with that request. Please try again.