Skip to content

Commit

Permalink
Add tests for result of conditional statements (10 tests, two rakudo …
Browse files Browse the repository at this point in the history
…todos)
  • Loading branch information
skids committed Apr 21, 2015
1 parent d625ea1 commit 13f03e8
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion S04-statements/if.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use v6;

use Test;

plan 29;
plan 39;

=begin kwid
Expand Down Expand Up @@ -161,6 +161,21 @@ if (Mu) { flunk('if (Mu) {} failed'); } else { pass('if (Mu) {} works'); }
}


# L<S04/"Conditional statements"/The result of a conditional statement is the result of the block chosen to execute.>

is (if 1 { 42 }), (42), "if evaluates to executed block";
is (if 0 { 42 } else { 43 }), (43), "if+else else evaluates to executed block";
is (if 0 { 42 } else { 43 }), (43), "if+else if evaluates to executed block";
is (if 0 { 42 } elsif 0 { 43 } else { 44 }), (44), "if+elsif+else else evaluates to executed block";
is (if 0 { 42 } elsif 1 { 43 } else { 44 }), (43), "if+elsif+else elsif evaluates to executed block";
is (if 1 { 42 } elsif 0 { 43 } else { 44 }), (42), "if+elsif+else if evaluates to executed block";
is (if 0 { 42 } elsif 1 { 43 }), (43), "if+elsif elsif evaluates to executed block";
is (if 1 { 42 } elsif 0 { 43 }), (42), "if+elsif if evaluates to executed block";
#?rakudo todo 'rakudo still uses Nil here'
is (if 0 { 42 } elsif 0 { 43 }), (), "if+elsif evaluates to () when no block chosen";
#?rakudo todo 'rakudo still uses Nil here'
is (if 0 { 42 }), (), "if evaluates to () when no block chosen";

# L<S04/Statement parsing/keywords require whitespace>
eval_dies_ok('if($x > 1) {}','keyword needs at least one whitespace after it');

Expand Down

0 comments on commit 13f03e8

Please sign in to comment.