From 357afc2ab2c7e5fda26d537c57f6a373c83584c5 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Sat, 18 Feb 2023 13:05:16 -0700 Subject: [PATCH] awaitLet test case. Close #71 --- kiss/src/test/cases/BasicTestCase.hx | 9 ++++++ kiss/src/test/cases/BasicTestCase.kiss | 40 +++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/kiss/src/test/cases/BasicTestCase.hx b/kiss/src/test/cases/BasicTestCase.hx index 55c9a083..019c161a 100644 --- a/kiss/src/test/cases/BasicTestCase.hx +++ b/kiss/src/test/cases/BasicTestCase.hx @@ -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; } diff --git a/kiss/src/test/cases/BasicTestCase.kiss b/kiss/src/test/cases/BasicTestCase.kiss index aaa40bf8..32aab524 100644 --- a/kiss/src/test/cases/BasicTestCase.kiss +++ b/kiss/src/test/cases/BasicTestCase.kiss @@ -770,4 +770,42 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m (typeCase ["a" 5 5.5 true] ([:String a :Int five :Float fivePointFive :Bool tt] (Assert.equals "a55.5true" "${a}${five}${fivePointFive}${tt}")) - (never otherwise))) \ No newline at end of file + (never otherwise))) + +(function _testAwaitLet [:utest.Async async] + (localFunction :Promise 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)))) \ No newline at end of file