Skip to content

Commit

Permalink
GH-142: Migrate test cases of Promise
Browse files Browse the repository at this point in the history
  • Loading branch information
zeptometer committed Mar 3, 2024
1 parent fda0b82 commit 328585f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
10 changes: 0 additions & 10 deletions __test__/satysrc/generic.saty
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,6 @@
@import: ../../src/tree-map
@import: ../../src/big-int

let () = Debug.log `==== Promise ====` in
let p = Promise.delay ~(!!(&(let () = Debug.log `foo` in 1))) in
let () = Debug.log `bar` in
let _ = Promise.force p in
let _ = Promise.force p in
let p = Promise.delay ~(!!(&(let () = Debug.log `foobar` in 3.14))) in
let () = Debug.log `barbaz` in
let _ = Promise.force p in
let _ = Promise.force p in

let () = Debug.log `==== Float ====` in
let p f = f |> String.of-float |> Debug.log in
let () = p Float.pi in
Expand Down
2 changes: 2 additions & 0 deletions test/main.test.saty
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@import: list.test
@import: map.test
@import: parser.test
@import: promise.test
@import: ref.test
@import: regex.test
@import: string.test
Expand All @@ -26,6 +27,7 @@ describe `base` [
list-test-cases;
map-test-cases;
parser-test-cases;
promise-test-cases;
ref-test-cases;
regex-test-cases;
string-test-cases;
Expand Down
20 changes: 20 additions & 0 deletions test/promise.test.satyg
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@require: test/test
@require: test/expect

@import: ../src/base0
@import: ../src/ref
@import: ../src/promise

let promise-test-cases = open Test in
describe `Promise module` [
it `evaluate lazily` (fun () -> (
let r = Ref.make 0 in
let p = Promise.delay ~(!!(&(let () = r |> Ref.inc in 1))) in
Ref.get r == 0
&& (let _ = Promise.force p in
Ref.get r == 1
&& (let _ = Promise.force p in
Ref.get r == 1))
|> Expect.is-true
));
]

0 comments on commit 328585f

Please sign in to comment.