awaitLet test case. Close #71

This commit is contained in:
2023-02-18 13:05:16 -07:00
parent ac911e0567
commit cc0d05594c
2 changed files with 48 additions and 1 deletions

View File

@@ -7,6 +7,9 @@ import kiss.List;
import kiss.Stream;
import haxe.ds.Option;
import kiss.Kiss;
#if js
import js.lib.Promise;
#end
using StringTools;
@@ -413,6 +416,12 @@ class BasicTestCase extends Test {
}
#end
#if js
function testAwaitLet(async:utest.Async) {
_testAwaitLet(async);
}
#end
var aNullToPrint = null;
}

View File

@@ -771,3 +771,41 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
([:String a :Int five :Float fivePointFive :Bool tt]
(Assert.equals "a55.5true" "${a}${five}${fivePointFive}${tt}"))
(never otherwise)))
(function _testAwaitLet [:utest.Async async]
(localFunction :Promise<Bool> newPromise [:Bool succeed]
(new Promise
->:Void [
:Bool->Void resolve
:Dynamic->Void reject
] (if succeed (resolve true) (reject false))))
(awaitLet [result (newPromise true)]
(catch [:Dynamic e] (Assert.fail))
(Assert.isTrue result)
(awaitLet [res1 (newPromise false)
res2 (newPromise true)
res3 (newPromise true)]
(catch [:Dynamic e]
(Assert.isFalse e)
(awaitLet [res1 (newPromise true)
res2 (newPromise false)
res3 (newPromise true)]
(catch [:Dynamic e]
(Assert.isFalse e)
(awaitLet [res1 (newPromise true)
res2 (newPromise true)
res3 (newPromise false)]
(catch [:Dynamic e]
(Assert.isFalse e)
(awaitLet [res1 (newPromise true)
res2 (newPromise res1)
res3 (newPromise res2)]
(Assert.isTrue ?(and res1 res2 res3))
(async.done))
e)
(Assert.fail))
e)
(Assert.fail))
e)
(Assert.fail))))