Skip to content

Commit abda2ac

Browse files
committed
test: add type tests
1 parent f387d82 commit abda2ac

File tree

8 files changed

+320
-1
lines changed

8 files changed

+320
-1
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@
2828
"tasks": {
2929
"check": "deno check ./**/*.ts",
3030
"test": "deno test -A --parallel --shuffle --doc",
31+
"test:coverage": "deno task test --coverage=.coverage",
32+
"coverage": "deno coverage .coverage --exclude=testdata/",
3133
"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",
3234
"update:write": "deno task -q update --write",
3335
"update:commit": "deno task -q update --commit --prefix :package: --pre-commit=fmt,lint"
3436
},
3537
"imports": {
36-
"@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"
3741
}
3842
}

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+
});

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+
});

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+
});

source_test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 { CollectParams, Source } from "./source.ts";
5+
6+
Deno.test("Source", () => {
7+
const denops = new DenopsStub();
8+
const source: Source<{ a: string }> = {
9+
collect: async function* () {},
10+
};
11+
12+
const items = source.collect(
13+
denops,
14+
{} as CollectParams,
15+
{},
16+
);
17+
assertType<
18+
IsExact<
19+
typeof items,
20+
AsyncIterableIterator<IdItem<{ a: string }>>
21+
>
22+
>(true);
23+
});

0 commit comments

Comments
 (0)