|
1 | | -import { defaults, filter, map, pick, tail } from "./common.js"; |
| 1 | +import { defaults, tail } from "./common.js"; |
2 | 2 | import { is, pattern, val } from "./hof.js"; |
3 | 3 | import { isInjectable } from "./predicates.js"; |
4 | 4 | import { Queue } from "./queue.js"; |
5 | 5 |
|
6 | 6 | describe("common", function () { |
7 | | - describe("filter", function () { |
8 | | - it("should filter arrays", function () { |
9 | | - const input = [1, 2, 3, 4, 5]; |
10 | | - const filtered = filter(input, function (int) { |
11 | | - return int > 2; |
12 | | - }); |
13 | | - expect(filtered.length).toBe(3); |
14 | | - expect(filtered).toEqual([3, 4, 5]); |
15 | | - }); |
16 | | - |
17 | | - it("should properly compact arrays", function () { |
18 | | - expect( |
19 | | - filter([0, 1, 0, 2, 0, 3, 4], function (v) { |
20 | | - return !!v; |
21 | | - }), |
22 | | - ).toEqual([1, 2, 3, 4]); |
23 | | - }); |
24 | | - |
25 | | - it("should filter objects", function () { |
26 | | - const input = { foo: 1, bar: 2, baz: 3, qux: 4 }; |
27 | | - const filtered = filter(input, function (value, _key) { |
28 | | - return value > 2; |
29 | | - }); |
30 | | - expect(Object.keys(filtered).length).toBe(2); |
31 | | - expect(filtered).toEqual({ baz: 3, qux: 4 }); |
32 | | - }); |
33 | | - }); |
34 | | - |
35 | 7 | describe("defaults", function () { |
36 | 8 | it("should do left-associative object merge", function () { |
37 | 9 | const options = { param1: "new val" }; |
@@ -109,55 +81,6 @@ describe("common", function () { |
109 | 81 | }); |
110 | 82 | }); |
111 | 83 |
|
112 | | - describe("pick", () => { |
113 | | - it("should pick inherited properties", () => { |
114 | | - const parent = { foo: "foo", bar: "bar" }; |
115 | | - const child = Object.create(parent); |
116 | | - expect(pick(child, ["foo"])).toEqual({ foo: "foo" }); |
117 | | - }); |
118 | | - |
119 | | - it("should not pick missing properties", () => { |
120 | | - const obj = { foo: "foo", bar: "bar" }; |
121 | | - expect(pick(obj, ["baz"])).toEqual({}); |
122 | | - }); |
123 | | - }); |
124 | | - |
125 | | - describe("map on arrays", () => { |
126 | | - it("should map arrays", () => { |
127 | | - const src = [1, 2, 3, 4]; |
128 | | - const dest = map(src, (x) => x * 2); |
129 | | - |
130 | | - expect(src).toEqual([1, 2, 3, 4]); |
131 | | - expect(dest).toEqual([2, 4, 6, 8]); |
132 | | - }); |
133 | | - |
134 | | - it("should map arrays in place when target === src", () => { |
135 | | - const src = [1, 2, 3, 4]; |
136 | | - const dest = map(src, (x) => x * 2, src); |
137 | | - |
138 | | - expect(src).toEqual([2, 4, 6, 8]); |
139 | | - expect(dest).toEqual([2, 4, 6, 8]); |
140 | | - }); |
141 | | - }); |
142 | | - |
143 | | - describe("map on objects", () => { |
144 | | - it("should map objects", () => { |
145 | | - const src = { foo: 1, bar: 2, baz: 3 }; |
146 | | - const dest = map(src, (x) => x * 2); |
147 | | - |
148 | | - expect(src).toEqual({ foo: 1, bar: 2, baz: 3 }); |
149 | | - expect(dest).toEqual({ foo: 2, bar: 4, baz: 6 }); |
150 | | - }); |
151 | | - |
152 | | - it("should map objects in place when target === src", () => { |
153 | | - const src = { foo: 1, bar: 2, baz: 3 }; |
154 | | - const dest = map(src, (x) => x * 2, src); |
155 | | - |
156 | | - expect(src).toEqual({ foo: 2, bar: 4, baz: 6 }); |
157 | | - expect(dest).toEqual({ foo: 2, bar: 4, baz: 6 }); |
158 | | - }); |
159 | | - }); |
160 | | - |
161 | 84 | describe("tail", () => { |
162 | 85 | it("should return the last element of a non-empty array", () => { |
163 | 86 | expect(tail([1, 2, 3])).toBe(3); |
|
0 commit comments