Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
a few tests for the orelse operator
a bit of sanity and then exception semantics.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| use v6; | ||
| use Test; | ||
|
|
||
| is (1 orelse 2), 1, 'orelse basics'; | ||
| is (1 orelse 2 orelse 3), 1, 'orelse chained'; | ||
| is (Any orelse Int orelse 3), 3, 'orelse chained'; | ||
| is (1 orelse 0), 1, 'definedness, not truthness'; | ||
| ok 1 === (1 orelse Any), 'first defined value (1)'; | ||
| ok 2 === (Any orelse 2), 'first defined value (2)'; | ||
| my $tracker = 0; | ||
| ok (1 orelse ($tracker = 1)), 'sanity'; | ||
| nok $tracker, 'orelse thunks'; | ||
|
|
||
| #?rakudo todo "orelse exception semantics" | ||
| { | ||
| my $result = 0; | ||
| try { | ||
| die "oh noes!" orelse $result = 1; | ||
| } | ||
| ok $result, "orelse continues after an exception"; | ||
| } | ||
|
|
||
| #?rakudo todo "orelse exception semantics" | ||
| { | ||
| my $result = 0; | ||
| try { | ||
| die "oh noes!" orelse $result = ~$! eq "oh noes!"; | ||
| } | ||
| ok $result, "orelse sets $! after an exception"; | ||
| } | ||
|
|
||
| #?rakudo todo "orelse exception semantics" | ||
| { | ||
| my $result = 0; | ||
| try { | ||
| die "oh noes!" orelse -> $foo { $result = ~$foo eq "oh noes!" }; | ||
| } | ||
| ok $result, "orelse passes $! to one argument after an exception"; | ||
| } | ||
|
|
||
| #?rakudo todo "orelse exception semantics" | ||
| { | ||
| my $result = 0; | ||
| try { | ||
| die "oh noes!" orelse -> $foo, $bar { $result = ~$foo eq "oh noes!" && ~$bar eq "oh noes!" }; | ||
| } | ||
| ok $result, "orelse passes $! to two arguments after an exception"; | ||
| } | ||
|
|
||
|
|
||
| done; |