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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
{
id
Obj: {
values, keys,
pairs-to-obj, obj-to-pairs, lists-to-obj, obj-to-lists,
empty, each, map, filter, compact, reject, partition, find,
}
} = require '..'
{strict-equal: eq, deep-equal: deep-eq, ok} = require 'assert'
suite 'values' ->
test 'empty object as input' ->
deep-eq [], values {}
test 'object as input' ->
deep-eq [1 2 3], values sadf: 1, asdf: 2, fdas: 3
suite 'keys' ->
test 'empty object as input' ->
deep-eq [], keys {}
test 'object as input' ->
deep-eq <[ sadf asdf fdas ]>, keys sadf: 1, asdf: 2, fdas: 3
suite 'pairs-to-obj' ->
test 'empty list as input' ->
deep-eq {}, pairs-to-obj []
test 'pairs as input' ->
deep-eq {a: 'b', c: 'd', e: 1}, pairs-to-obj [['a' 'b'] ['c' 'd'] ['e' 1]]
suite 'obj-to-pairs' ->
test 'empty object as input' ->
deep-eq [], obj-to-pairs {}
test 'object as input' ->
deep-eq [['a' 'b'] ['c' 'd'] ['e' 1]], obj-to-pairs {a: 'b', c: 'd', e: 1}
suite 'lists-to-obj' ->
test 'empty lists as input' ->
deep-eq {}, lists-to-obj [] []
test 'two lists of the same length' ->
deep-eq {a: 1, b: 2, c: 3}, lists-to-obj <[ a b c ]> [1 2 3]
test 'first list is shorter' ->
deep-eq {a: 1, b: 2}, lists-to-obj <[ a b ]> [1 2 3]
test 'first list is longer' ->
deep-eq {a: 1, b: 2, c: void}, lists-to-obj <[ a b c ]> [1 2]
test 'curried' ->
f = lists-to-obj <[ a b c ]>
deep-eq {a: 1, b: 2, c: 3}, f [1 2 3]
suite 'obj-to-lists' ->
test 'empty object as input' ->
deep-eq [[], []], obj-to-lists {}
test 'two lists of the same length' ->
deep-eq [<[ a b c ]>, [1 2 3]], obj-to-lists {a: 1, b: 2, c: 3}
suite 'empty' ->
test 'empty object as input' ->
ok empty {}
test 'non-empty object as input' ->
ok not empty {x: 1}
suite 'each' ->
test 'empty object as input' ->
deep-eq {}, each id, {}
test 'iterate over object values' ->
count = 4
each (-> count += it), {a: 1, b: 2, c: 3}
eq 10 count
test 'curried' ->
count = 4
f = each (-> count += it)
f {a: 1, b: 2, c: 3}
eq 10 count
suite 'map' ->
test 'empty object as input' ->
deep-eq {}, map id, {}
test 'mapping over object' ->
deep-eq {a:2, b:4}, map (* 2), {a:1, b:2}
test 'curried' ->
f = map (* 2)
deep-eq {a:2, b:4}, f {a:1, b:2}
suite 'compact' ->
test 'empty object as input' ->
deep-eq {}, compact {}
test 'compacting object' ->
deep-eq {b: 1, e: 'ha'}, compact {a: 0, b: 1, c: false, d: '', e: 'ha'}
suite 'filter' ->
test 'empty object as input' ->
deep-eq {}, filter id, {}
test 'filtering object' ->
deep-eq {b: 2}, filter (== 2), {a:1, b:2}
test 'curried' ->
f = filter (== 2)
deep-eq {b: 2}, f {a:1, b:2}
suite 'reject' ->
test 'empty object as input' ->
deep-eq {}, reject id, {}
test 'reject object' ->
deep-eq {a: 1}, reject (==2), {a:1, b:2}
test 'curried' ->
f = reject (== 2)
deep-eq {a: 1}, f {a:1, b:2}
suite 'partition' ->
test 'empty object as input' ->
deep-eq [{}, {}], partition id, {}
test 'partition object' ->
deep-eq [{b: 2}, {a: 1, c: 3}], partition (==2), {a:1, b:2, c:3}
test 'curried' ->
f = partition (== 2)
deep-eq [{b: 2}, {a: 1, c: 3}], f {a:1, b:2, c:3}
suite 'find' ->
test 'empty object as input' ->
eq void, find id, {}
test 'find from object' ->
eq 2, find (==2), {a:1, b:2}
test 'curried' ->
f = find (== 2)
eq 2, f {a:1, b:2}
|