-
Notifications
You must be signed in to change notification settings - Fork 0
/
samplelib_test.ml
40 lines (34 loc) · 918 Bytes
/
samplelib_test.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module Promise = struct
type 'x t = 'x Js_promise.t
let return x : _ t = Js_promise.resolve x
let bind : 'x t -> ('x -> 'y t) -> 'y t = fun m af -> Js_promise.then_ af m
end
open struct
module Jest = struct
type t
external expect : 'a -> t = "expect" [@@bs.val]
external to_be : t -> 'a -> unit = "toBe" [@@bs.send]
end
end
open Jest
open struct
let flip f x y = f y x
end
module Test = struct
let test1 () =
let open Promise in
return 2
|> flip bind (fun x -> return (x + 40))
|> flip bind @@ fun x -> return (to_be (expect x) 42)
let test2 () =
let module M = Samplelib.MonadOps(Promise) in
let open M in
return 2
>>= fun x -> return (x + 40)
>>= fun x -> return (to_be (expect x) 42)
let test3 () =
let open Samplelib.MonadOps(Promise) in
return 2
>>= fun x -> return (x + 40)
>>= fun x -> return (to_be (expect x) 42)
end