-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathMain.purs
More file actions
70 lines (60 loc) · 2.49 KB
/
Main.purs
File metadata and controls
70 lines (60 loc) · 2.49 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module Test.Main where
import Prelude
import Effect (Effect)
import Record (delete, equal, get, insert, merge, modify, rename, set, (//))
import Record.Builder as Builder
import Record.Unsafe (unsafeHas)
import Test.Assert (assert')
import Type.Proxy (Proxy(..))
main :: Effect Unit
main = do
let x = Proxy :: Proxy "x"
y = Proxy :: Proxy "y"
z = Proxy :: Proxy "z"
assert' "insert, get" $
get x (insert x 42 {}) == 42
assert' "insert, modify, get" $
get x (modify x (_ + 1) (insert x 42 {})) == 43
assert' "set, get" $
get x (set x 0 { x: 42 }) == 0
assert' "set, modify, get" $
get x (modify x (_ + 1) (set x 0 { x: 42 })) == 1
assert' "delete, get" $
get x (delete y { x: 42, y: 1337 }) == 42
assert' "rename" $
get y (rename x y { x: 42 }) == 42
assert' "equal" $
equal { a: 1, b: "b", c: true } { a: 1, b: "b", c: true }
assert' "equal2" $
not $ equal { a: 1, b: "b", c: true } { a: 1, b: "b", c: false }
assert' "merge" $
equal { x: 1, y: "y" } (merge { y: "y" } { x: 1, y: 2 })
assert' "mergeFlipped" $
equal { x: 1, y: "y", z: true } ({ x: 1, y: 2 } // { y: "y" } // { z: true })
assert' "unsafeHas1" $
unsafeHas "a" { a: 42 }
assert' "unsafeHas2" $
not $ unsafeHas "b" { a: 42 }
let testBuilder = Builder.build (Builder.insert x 42
>>> Builder.merge { y: true, z: "testing" }
>>> Builder.delete y
>>> Builder.modify x show
>>> Builder.rename z y) {}
assert' "Record.Builder" $
testBuilder.x == "42" && testBuilder.y == "testing"
assert' "Record.Builder.merge" $
let { x, y, z } = Builder.build (Builder.merge { x: 1, y: "y" }) { y: 2, z: true }
:: { x :: Int, y :: String, z :: Boolean }
in x == 1 && y == "y" && z
assert' "Record.Builder.union" $
let { x, y, z } = Builder.build (Builder.union { x: 1, y: "y" }) { y: 2, z: true }
:: { x :: Int, y :: String, y :: Int, z :: Boolean }
in x == 1 && y == "y" && z
assert' "Record.Builder.flip merge" $
let { x, y, z } = Builder.build (Builder.flip Builder.merge { x: 1, y: "y" }) { y: 2, z: true }
:: { x :: Int, y :: Int, z :: Boolean }
in x == 1 && y == 2 && z
assert' "Record.Builder.flip union" $
let { x, y, z } = Builder.build (Builder.flip Builder.union { x: 1, y: "y" }) { y: 2, z: true }
:: { x :: Int, y :: Int, y :: String, z :: Boolean }
in x == 1 && y == 2 && z