Skip to content

Commit 764371c

Browse files
lambdalisueclaude
andcommitted
test: add tests for util/predicate module
Add tests for all predicate functions including: - isStringArray, isAbortSignal - isTheme, isCoordinator, isCurator - isSource, isMatcher, isSorter - isRenderer, isPreviewer, isAction - isSetting, isPickerParams, isOptions - isIncrementalMatcher 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c342988 commit 764371c

1 file changed

Lines changed: 324 additions & 0 deletions

File tree

denops/fall/util/predicate_test.ts

Lines changed: 324 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,324 @@
1+
import { assertEquals } from "jsr:@std/assert@^1.0.0";
2+
import { describe, it } from "jsr:@std/testing@^1.0.0/bdd";
3+
import type { Detail, Matcher, Theme } from "jsr:@vim-fall/core@^0.3.0";
4+
5+
import {
6+
isAbortSignal,
7+
isAction,
8+
isCoordinator,
9+
isCurator,
10+
isIncrementalMatcher,
11+
isMatcher,
12+
isOptions,
13+
isPickerParams,
14+
isPreviewer,
15+
isRenderer,
16+
isSetting,
17+
isSorter,
18+
isSource,
19+
isStringArray,
20+
isTheme,
21+
} from "./predicate.ts";
22+
23+
describe("isStringArray", () => {
24+
it("should return true for string arrays", () => {
25+
assertEquals(isStringArray([]), true);
26+
assertEquals(isStringArray(["a", "b", "c"]), true);
27+
assertEquals(isStringArray(["hello", "world"]), true);
28+
});
29+
30+
it("should return false for non-string arrays", () => {
31+
assertEquals(isStringArray([1, 2, 3]), false);
32+
assertEquals(isStringArray(["a", 1, "c"]), false);
33+
assertEquals(isStringArray(null), false);
34+
assertEquals(isStringArray(undefined), false);
35+
assertEquals(isStringArray("string"), false);
36+
assertEquals(isStringArray({}), false);
37+
});
38+
});
39+
40+
describe("isAbortSignal", () => {
41+
it("should return true for AbortSignal instances", () => {
42+
const controller = new AbortController();
43+
assertEquals(isAbortSignal(controller.signal), true);
44+
});
45+
46+
it("should return false for non-AbortSignal values", () => {
47+
assertEquals(isAbortSignal({}), false);
48+
assertEquals(isAbortSignal(null), false);
49+
assertEquals(isAbortSignal(undefined), false);
50+
assertEquals(isAbortSignal("signal"), false);
51+
});
52+
});
53+
54+
describe("isTheme", () => {
55+
it("should return true for valid theme objects", () => {
56+
const theme: Theme = {
57+
border: ["a", "b", "c", "d", "e", "f", "g", "h"],
58+
divider: ["a", "b", "c", "d", "e", "f"],
59+
};
60+
assertEquals(isTheme(theme), true);
61+
});
62+
63+
it("should return false for invalid theme objects", () => {
64+
assertEquals(isTheme({}), false);
65+
assertEquals(isTheme({ border: [], divider: [] }), false);
66+
assertEquals(isTheme({ border: ["a"], divider: ["a"] }), false);
67+
assertEquals(
68+
isTheme({
69+
border: ["a", "b", "c", "d", "e", "f", "g"],
70+
divider: ["a", "b", "c", "d", "e", "f"],
71+
}),
72+
false,
73+
);
74+
});
75+
});
76+
77+
describe("isCoordinator", () => {
78+
it("should return true for valid coordinator objects", () => {
79+
const coordinator = {
80+
style: () => {},
81+
layout: () => ({ width: 10, height: 10 }),
82+
};
83+
assertEquals(isCoordinator(coordinator), true);
84+
});
85+
86+
it("should return false for invalid coordinator objects", () => {
87+
assertEquals(isCoordinator({}), false);
88+
assertEquals(isCoordinator({ style: () => {} }), false);
89+
assertEquals(isCoordinator({ layout: () => {} }), false);
90+
assertEquals(
91+
isCoordinator({ style: "not a function", layout: () => {} }),
92+
false,
93+
);
94+
});
95+
});
96+
97+
describe("isCurator", () => {
98+
it("should return true for valid curator objects", () => {
99+
const curator = {
100+
curate: async function* () {
101+
yield { value: "test" };
102+
},
103+
};
104+
assertEquals(isCurator(curator), true);
105+
});
106+
107+
it("should return false for invalid curator objects", () => {
108+
assertEquals(isCurator({}), false);
109+
assertEquals(isCurator({ curate: "not a function" }), false);
110+
});
111+
});
112+
113+
describe("isSource", () => {
114+
it("should return true for valid source objects", () => {
115+
const source = {
116+
collect: async function* () {
117+
yield { value: "test" };
118+
},
119+
};
120+
assertEquals(isSource(source), true);
121+
});
122+
123+
it("should return false for invalid source objects", () => {
124+
assertEquals(isSource({}), false);
125+
assertEquals(isSource({ collect: "not a function" }), false);
126+
});
127+
});
128+
129+
describe("isMatcher", () => {
130+
it("should return true for valid matcher objects", () => {
131+
const matcher = {
132+
match: async function* () {
133+
yield { value: "test", score: 1 };
134+
},
135+
};
136+
assertEquals(isMatcher(matcher), true);
137+
});
138+
139+
it("should return false for invalid matcher objects", () => {
140+
assertEquals(isMatcher({}), false);
141+
assertEquals(isMatcher({ match: "not a function" }), false);
142+
});
143+
});
144+
145+
describe("isSorter", () => {
146+
it("should return true for valid sorter objects", () => {
147+
const sorter = {
148+
sort: async function* () {
149+
yield { value: "test", score: 1 };
150+
},
151+
};
152+
assertEquals(isSorter(sorter), true);
153+
});
154+
155+
it("should return false for invalid sorter objects", () => {
156+
assertEquals(isSorter({}), false);
157+
assertEquals(isSorter({ sort: "not a function" }), false);
158+
});
159+
});
160+
161+
describe("isRenderer", () => {
162+
it("should return true for valid renderer objects", () => {
163+
const renderer = {
164+
render: () => Promise.resolve([]),
165+
};
166+
assertEquals(isRenderer(renderer), true);
167+
});
168+
169+
it("should return false for invalid renderer objects", () => {
170+
assertEquals(isRenderer({}), false);
171+
assertEquals(isRenderer({ render: "not a function" }), false);
172+
});
173+
});
174+
175+
describe("isPreviewer", () => {
176+
it("should return true for valid previewer objects", () => {
177+
const previewer = {
178+
preview: () => Promise.resolve([]),
179+
};
180+
assertEquals(isPreviewer(previewer), true);
181+
});
182+
183+
it("should return false for invalid previewer objects", () => {
184+
assertEquals(isPreviewer({}), false);
185+
assertEquals(isPreviewer({ preview: "not a function" }), false);
186+
});
187+
});
188+
189+
describe("isAction", () => {
190+
it("should return true for valid action objects", () => {
191+
const action = {
192+
invoke: () => Promise.resolve(),
193+
};
194+
assertEquals(isAction(action), true);
195+
});
196+
197+
it("should return false for invalid action objects", () => {
198+
assertEquals(isAction({}), false);
199+
assertEquals(isAction({ invoke: "not a function" }), false);
200+
});
201+
});
202+
203+
describe("isSetting", () => {
204+
it("should return true for valid setting objects", () => {
205+
const setting = {
206+
coordinator: {
207+
style: () => {},
208+
layout: () => ({ width: 10, height: 10 }),
209+
},
210+
theme: {
211+
border: ["a", "b", "c", "d", "e", "f", "g", "h"],
212+
divider: ["a", "b", "c", "d", "e", "f"],
213+
},
214+
};
215+
assertEquals(isSetting(setting), true);
216+
});
217+
218+
it("should return false for invalid setting objects", () => {
219+
assertEquals(isSetting({}), false);
220+
assertEquals(isSetting({ coordinator: {} }), false);
221+
assertEquals(isSetting({ theme: {} }), false);
222+
});
223+
});
224+
225+
describe("isPickerParams", () => {
226+
it("should return true for valid picker params", () => {
227+
const params = {
228+
name: "test",
229+
source: {
230+
collect: async function* () {
231+
yield { value: "test" };
232+
},
233+
},
234+
actions: {
235+
default: { invoke: async () => {} },
236+
},
237+
defaultAction: "default",
238+
matchers: [{ match: async function* () {} }],
239+
};
240+
assertEquals(isPickerParams(params), true);
241+
});
242+
243+
it("should return true for params with optional fields", () => {
244+
const params = {
245+
name: "test",
246+
source: {
247+
collect: async function* () {
248+
yield { value: "test" };
249+
},
250+
},
251+
actions: {
252+
default: { invoke: async () => {} },
253+
},
254+
defaultAction: "default",
255+
matchers: [{ match: async function* () {} }],
256+
sorters: [{ sort: async function* () {} }],
257+
renderers: [{ render: () => Promise.resolve([]) }],
258+
previewers: [{ preview: () => Promise.resolve([]) }],
259+
coordinator: {
260+
style: () => {},
261+
layout: () => ({ width: 10, height: 10 }),
262+
},
263+
theme: {
264+
border: ["a", "b", "c", "d", "e", "f", "g", "h"],
265+
divider: ["a", "b", "c", "d", "e", "f"],
266+
},
267+
};
268+
assertEquals(isPickerParams(params), true);
269+
});
270+
271+
it("should return false for invalid picker params", () => {
272+
assertEquals(isPickerParams({}), false);
273+
assertEquals(isPickerParams({ name: "test" }), false);
274+
assertEquals(
275+
isPickerParams({
276+
name: "test",
277+
source: {
278+
collect: async function* () {
279+
yield { value: "test" };
280+
},
281+
},
282+
}),
283+
false,
284+
);
285+
});
286+
});
287+
288+
describe("isOptions", () => {
289+
it("should return true for valid options", () => {
290+
assertEquals(isOptions({}), true);
291+
assertEquals(isOptions({ signal: new AbortController().signal }), true);
292+
});
293+
294+
it("should return false for invalid options", () => {
295+
assertEquals(isOptions({ signal: "not a signal" }), false);
296+
assertEquals(isOptions(null), false);
297+
assertEquals(isOptions(undefined), false);
298+
});
299+
});
300+
301+
describe("isIncrementalMatcher", () => {
302+
it("should return true for incremental matchers", () => {
303+
const matcher = {
304+
match: async function* () {},
305+
incremental: true,
306+
};
307+
assertEquals(isIncrementalMatcher(matcher as Matcher<Detail>), true);
308+
});
309+
310+
it("should return false for non-incremental matchers", () => {
311+
const matcher = {
312+
match: async function* () {},
313+
incremental: false,
314+
};
315+
assertEquals(isIncrementalMatcher(matcher as Matcher<Detail>), false);
316+
});
317+
318+
it("should return false when incremental property is not set", () => {
319+
const matcher = {
320+
match: async function* () {},
321+
};
322+
assertEquals(isIncrementalMatcher(matcher as Matcher<Detail>), false);
323+
});
324+
});

0 commit comments

Comments
 (0)