Skip to content

Commit 933a833

Browse files
authored
Merge pull request #2 from vim-fall/fix-types
Fix types
2 parents 2544364 + a7a0cbf commit 933a833

File tree

11 files changed

+326
-44
lines changed

11 files changed

+326
-44
lines changed

action_test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { assertType, type IsExact } from "@std/testing/types";
2+
import { DenopsStub } from "@denops/test/stub";
3+
import type { Promish } from "./_typeutil.ts";
4+
import type { Action, InvokeParams } from "./action.ts";
5+
6+
Deno.test("Action", async (t) => {
7+
const denops = new DenopsStub();
8+
const action: Action<{ a: string }> = {
9+
invoke: () => {},
10+
};
11+
await t.step("passed type is equal to the type restriction", () => {
12+
const items = action.invoke(
13+
denops,
14+
{} as InvokeParams<{ a: string }>,
15+
{},
16+
);
17+
assertType<
18+
IsExact<
19+
typeof items,
20+
Promish<void | true>
21+
>
22+
>(true);
23+
});
24+
25+
await t.step("passed type establishes the type restriction", () => {
26+
const items = action.invoke(
27+
denops,
28+
{} as InvokeParams<{ a: string; b: string }>,
29+
{},
30+
);
31+
assertType<
32+
IsExact<
33+
typeof items,
34+
Promish<void | true>
35+
>
36+
>(true);
37+
});
38+
39+
await t.step("passed type does not establish the type restriction", () => {
40+
const items = action.invoke(
41+
denops,
42+
// @ts-expect-error: 'a' is missing
43+
{} as InvokeParams<{ b: string }>,
44+
{},
45+
);
46+
assertType<
47+
IsExact<
48+
typeof items,
49+
Promish<void | true>
50+
>
51+
>(true);
52+
});
53+
});

curator_test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { assertType, type IsExact } from "@std/testing/types";
2+
import { DenopsStub } from "@denops/test/stub";
3+
import type { IdItem } from "./item.ts";
4+
import type { CurateParams, Curator } from "./curator.ts";
5+
6+
Deno.test("Curator", () => {
7+
const denops = new DenopsStub();
8+
const curator: Curator<{ a: string }> = {
9+
curate: async function* () {},
10+
};
11+
const items = curator.curate(
12+
denops,
13+
{} as CurateParams,
14+
{},
15+
);
16+
assertType<
17+
IsExact<
18+
typeof items,
19+
AsyncIterableIterator<IdItem<{ a: string }>>
20+
>
21+
>(true);
22+
});

deno.jsonc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"./item": "./item.ts",
1010
"./matcher": "./matcher.ts",
1111
"./previewer": "./previewer.ts",
12-
"./projector": "./projector.ts",
1312
"./renderer": "./renderer.ts",
1413
"./sorter": "./sorter.ts",
1514
"./source": "./source.ts",
@@ -29,11 +28,15 @@
2928
"tasks": {
3029
"check": "deno check ./**/*.ts",
3130
"test": "deno test -A --parallel --shuffle --doc",
31+
"test:coverage": "deno task test --coverage=.coverage",
32+
"coverage": "deno coverage .coverage --exclude=testdata/",
3233
"update": "deno run --allow-env --allow-read --allow-write=. --allow-run=git,deno --allow-net=deno.land,jsr.io,registry.npmjs.org jsr:@molt/cli ./**/*.ts",
3334
"update:write": "deno task -q update --write",
3435
"update:commit": "deno task -q update --commit --prefix :package: --pre-commit=fmt,lint"
3536
},
3637
"imports": {
37-
"@denops/std": "jsr:@denops/std@^7.3.0"
38+
"@denops/std": "jsr:@denops/std@^7.3.0",
39+
"@denops/test": "jsr:@denops/test@^3.0.4",
40+
"@std/testing": "jsr:@std/testing@^1.0.4"
3841
}
3942
}

matcher.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ export type Matcher<T> = {
2727
* @param options - Additional options, including an abort signal.
2828
* @returns An async iterator over matched `IdItem` elements.
2929
*/
30-
match(
30+
match<
31+
M extends MatchParams<T>,
32+
V extends M extends MatchParams<infer V> ? V : never,
33+
>(
3134
denops: Denops,
32-
params: MatchParams<T>,
35+
params: M,
3336
options: { signal?: AbortSignal },
34-
): AsyncIterableIterator<IdItem<T>>;
37+
): AsyncIterableIterator<IdItem<V>>;
3538
};

matcher_test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { assertType, type IsExact } from "@std/testing/types";
2+
import { DenopsStub } from "@denops/test/stub";
3+
import type { IdItem } from "./item.ts";
4+
import type { Matcher, MatchParams } from "./matcher.ts";
5+
6+
Deno.test("Matcher", async (t) => {
7+
const denops = new DenopsStub();
8+
const matcher: Matcher<{ a: string }> = {
9+
match: async function* () {},
10+
};
11+
12+
await t.step("passed type is equal to the type restriction", () => {
13+
const items = matcher.match(
14+
denops,
15+
{} as MatchParams<{ a: string }>,
16+
{},
17+
);
18+
assertType<
19+
IsExact<
20+
typeof items,
21+
AsyncIterableIterator<IdItem<{ a: string }>>
22+
>
23+
>(true);
24+
});
25+
26+
await t.step("passed type establishes the type restriction", () => {
27+
const items = matcher.match(
28+
denops,
29+
{} as MatchParams<{ a: string; b: string }>,
30+
{},
31+
);
32+
assertType<
33+
IsExact<
34+
typeof items,
35+
AsyncIterableIterator<IdItem<{ a: string; b: string }>>
36+
>
37+
>(true);
38+
});
39+
40+
await t.step("passed type does not establish the type restriction", () => {
41+
const items = matcher.match(
42+
denops,
43+
// @ts-expect-error: 'a' is missing
44+
{} as MatchParams<{ b: string }>,
45+
{},
46+
);
47+
assertType<
48+
IsExact<
49+
typeof items,
50+
AsyncIterableIterator<IdItem<{ a: string }>>
51+
>
52+
>(true);
53+
});
54+
});

mod.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export * from "./curator.ts";
1515
export * from "./item.ts";
1616
export * from "./matcher.ts";
1717
export * from "./previewer.ts";
18-
export * from "./projector.ts";
1918
export * from "./renderer.ts";
2019
export * from "./sorter.ts";
2120
export * from "./source.ts";

previewer_test.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { assertType, type IsExact } from "@std/testing/types";
2+
import { DenopsStub } from "@denops/test/stub";
3+
import type { Promish } from "./_typeutil.ts";
4+
import type { PreviewItem } from "./item.ts";
5+
import type { Previewer, PreviewParams } from "./previewer.ts";
6+
7+
Deno.test("Previewer", async (t) => {
8+
const denops = new DenopsStub();
9+
const previewer: Previewer<{ a: string }> = {
10+
preview: () => {},
11+
};
12+
13+
await t.step("passed type is equal to the type restriction", () => {
14+
const items = previewer.preview(
15+
denops,
16+
{} as PreviewParams<{ a: string }>,
17+
{},
18+
);
19+
assertType<
20+
IsExact<
21+
typeof items,
22+
Promish<void | PreviewItem>
23+
>
24+
>(true);
25+
});
26+
27+
await t.step("passed type establishes the type restriction", () => {
28+
const items = previewer.preview(
29+
denops,
30+
{} as PreviewParams<{ a: string; b: string }>,
31+
{},
32+
);
33+
assertType<
34+
IsExact<
35+
typeof items,
36+
Promish<void | PreviewItem>
37+
>
38+
>(true);
39+
});
40+
41+
await t.step("passed type does not establish the type restriction", () => {
42+
const items = previewer.preview(
43+
denops,
44+
// @ts-expect-error: 'a' is missing
45+
{} as PreviewParams<{ b: string }>,
46+
{},
47+
);
48+
assertType<
49+
IsExact<
50+
typeof items,
51+
Promish<void | PreviewItem>
52+
>
53+
>(true);
54+
});
55+
});

projector.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

renderer_test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { assertType, type IsExact } from "@std/testing/types";
2+
import { DenopsStub } from "@denops/test/stub";
3+
import type { Promish } from "./_typeutil.ts";
4+
import type { Renderer, RenderParams } from "./renderer.ts";
5+
6+
Deno.test("Renderer", async (t) => {
7+
const denops = new DenopsStub();
8+
const renderer: Renderer<{ a: string }> = {
9+
render: () => {},
10+
};
11+
12+
await t.step("passed type is equal to the type restriction", () => {
13+
const items = renderer.render(
14+
denops,
15+
{} as RenderParams<{ a: string }>,
16+
{},
17+
);
18+
assertType<
19+
IsExact<
20+
typeof items,
21+
Promish<void>
22+
>
23+
>(true);
24+
});
25+
26+
await t.step("passed type establishes the type restriction", () => {
27+
const items = renderer.render(
28+
denops,
29+
{} as RenderParams<{ a: string; b: string }>,
30+
{},
31+
);
32+
assertType<
33+
IsExact<
34+
typeof items,
35+
Promish<void>
36+
>
37+
>(true);
38+
});
39+
40+
await t.step("passed type does not establish the type restriction", () => {
41+
const items = renderer.render(
42+
denops,
43+
// @ts-expect-error: 'a' is missing
44+
{} as RenderParams<{ b: string }>,
45+
{},
46+
);
47+
assertType<
48+
IsExact<
49+
typeof items,
50+
Promish<void>
51+
>
52+
>(true);
53+
});
54+
});

sorter_test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { assertType, type IsExact } from "@std/testing/types";
2+
import { DenopsStub } from "@denops/test/stub";
3+
import type { Promish } from "./_typeutil.ts";
4+
import type { Sorter, SortParams } from "./sorter.ts";
5+
6+
Deno.test("Sorter", async (t) => {
7+
const denops = new DenopsStub();
8+
const sorter: Sorter<{ a: string }> = {
9+
sort: () => {},
10+
};
11+
12+
await t.step("passed type is equal to the type restriction", () => {
13+
const items = sorter.sort(
14+
denops,
15+
{} as SortParams<{ a: string }>,
16+
{},
17+
);
18+
assertType<
19+
IsExact<
20+
typeof items,
21+
Promish<void>
22+
>
23+
>(true);
24+
});
25+
26+
await t.step("passed type establishes the type restriction", () => {
27+
const items = sorter.sort(
28+
denops,
29+
{} as SortParams<{ a: string; b: string }>,
30+
{},
31+
);
32+
assertType<
33+
IsExact<
34+
typeof items,
35+
Promish<void>
36+
>
37+
>(true);
38+
});
39+
40+
await t.step("passed type does not establish the type restriction", () => {
41+
const items = sorter.sort(
42+
denops,
43+
// @ts-expect-error: 'a' is missing
44+
{} as SortParams<{ b: string }>,
45+
{},
46+
);
47+
assertType<
48+
IsExact<
49+
typeof items,
50+
Promish<void>
51+
>
52+
>(true);
53+
});
54+
});

0 commit comments

Comments
 (0)