Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #570 from dumarchie/master
Spectest for rakudo/rakudo#3137
- Loading branch information
Showing
2 changed files
with
52 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; | ||
plan 12; | ||
|
||
my $exception = ::('X::Promise::Resolved'); | ||
|
||
{ | ||
my $promise = Promise.new; | ||
my $vow = $promise.vow; | ||
|
||
$vow.keep(1); | ||
is $promise.status, Kept, 'Keeping a vow keeps the promise'; | ||
is $promise.result, 1, 'Keeping a vow assigns a result to the promise'; | ||
|
||
throws-like { $vow.keep(2) }, $exception, promise => $promise, | ||
message => 'Cannot keep/break a Promise more than once (status: Kept)', | ||
'Keeping a vow throws if the promise was Kept already'; | ||
|
||
is $promise.result, 1, | ||
'Keeping a vow does not change the result of an already Kept promise'; | ||
|
||
throws-like { $vow.break(3) }, $exception, promise => $promise, | ||
message => 'Cannot keep/break a Promise more than once (status: Kept)', | ||
'Breaking a vow throws if the promise was Kept already'; | ||
|
||
is $promise.status, Kept, | ||
'Breaking a vow does not change the status of an already Kept promise'; | ||
} | ||
|
||
{ | ||
my $promise = Promise.new; | ||
my $vow = $promise.vow; | ||
|
||
$vow.break(1); | ||
is $promise.status, Broken, 'Breaking a vow breaks the promise'; | ||
is $promise.cause, 1, 'Breaking a vow assigns a cause to the promise'; | ||
|
||
throws-like { $vow.break(2) }, $exception, promise => $promise, | ||
message => 'Cannot keep/break a Promise more than once (status: Broken)', | ||
'Breaking a vow throws if the promise was Broken already'; | ||
|
||
is $promise.cause, 1, | ||
'Breaking a vow does not change the cause of an already Broken promise'; | ||
|
||
throws-like { $vow.keep(3) }, $exception, promise => $promise, | ||
message => 'Cannot keep/break a Promise more than once (status: Broken)', | ||
'Keeping a vow throws if the promise was Broken already'; | ||
|
||
is $promise.status, Broken, | ||
'Keeping a vow does not change the status of an already Broken promise'; | ||
} |
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