Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test #153

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions denops/skkeleton/deps.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * as autocmd from "https://deno.land/x/[email protected].1/autocmd/mod.ts";
export * as fn from "https://deno.land/x/[email protected].1/function/mod.ts";
export { batch } from "https://deno.land/x/[email protected].1/batch/mod.ts";
export type { Denops } from "https://deno.land/x/[email protected].1/mod.ts";
export * as mapping from "https://deno.land/x/[email protected].1/mapping/mod.ts";
export * as vars from "https://deno.land/x/[email protected].1/variable/mod.ts";
export * as op from "https://deno.land/x/[email protected].1/option/mod.ts";
export * as autocmd from "https://deno.land/x/[email protected].2/autocmd/mod.ts";
export * as fn from "https://deno.land/x/[email protected].2/function/mod.ts";
export { batch } from "https://deno.land/x/[email protected].2/batch/mod.ts";
export type { Denops } from "https://deno.land/x/[email protected].2/mod.ts";
export * as mapping from "https://deno.land/x/[email protected].2/mapping/mod.ts";
export * as vars from "https://deno.land/x/[email protected].2/variable/mod.ts";
export * as op from "https://deno.land/x/[email protected].2/option/mod.ts";
1 change: 1 addition & 0 deletions denops/skkeleton/deps/denops_test.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export type { TestDefinition } from "https://deno.land/x/[email protected]/tester.ts";
export { test } from "https://deno.land/x/[email protected]/tester.ts";
2 changes: 1 addition & 1 deletion denops/skkeleton/deps/japanese_numeral.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * as JpNum from "https://esm.sh/@geolonia/[email protected].x";
export * as JpNum from "https://esm.sh/@geolonia/[email protected].16";
2 changes: 1 addition & 1 deletion denops/skkeleton/deps/jisyo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * as yaml from "https://deno.land/std@0.193.0/yaml/mod.ts";
export * as yaml from "https://deno.land/std@0.208.0/yaml/mod.ts";
export * as msgpack from "https://esm.sh/@msgpack/[email protected]";
export { default as jsonschema } from "https://esm.sh/[email protected]";
export { default as jisyoschema } from "https://cdn.jsdelivr.net/gh/skk-dict/jisyo/schema/jisyo.schema.v0.0.0.json" assert { type: "json" };
6 changes: 3 additions & 3 deletions denops/skkeleton/deps/std/collections.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { distinct } from "https://deno.land/std@0.198.0/collections/distinct.ts";
export { distinctBy } from "https://deno.land/std@0.198.0/collections/distinct_by.ts";
export { zip } from "https://deno.land/std@0.198.0/collections/zip.ts";
export { distinct } from "https://deno.land/std@0.208.0/collections/distinct.ts";
export { distinctBy } from "https://deno.land/std@0.208.0/collections/distinct_by.ts";
export { zip } from "https://deno.land/std@0.208.0/collections/zip.ts";
2 changes: 1 addition & 1 deletion denops/skkeleton/deps/std/path.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/std@0.198.0/path/mod.ts";
export * from "https://deno.land/std@0.208.0/path/mod.ts";
2 changes: 1 addition & 1 deletion denops/skkeleton/deps/std/streams.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { iterateReader } from "https://deno.land/std@0.198.0/streams/mod.ts";
export { iterateReader } from "https://deno.land/std@0.208.0/streams/mod.ts";
2 changes: 1 addition & 1 deletion denops/skkeleton/deps/unknownutil.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/x/unknownutil@v3.4.0/mod.ts";
export * from "https://deno.land/x/unknownutil@v3.11.0/mod.ts";
6 changes: 1 addition & 5 deletions denops/skkeleton/function/disable_test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Denops } from "../deps.ts";
import { test } from "../deps/denops_test.ts";
import { assertEquals } from "../deps/std/assert.ts";
import { currentContext } from "../store.ts";
import { initDenops } from "../testutil.ts";
import { test } from "../testutil.ts";
import { dispatch } from "./testutil.ts";

// deno-lint-ignore no-explicit-any
Expand All @@ -13,10 +12,7 @@ async function getResult(x: Promise<any>): Promise<string> {
test({
mode: "all",
name: "kakutei at disable",
pluginName: "skkeleton",
async fn(denops: Denops) {
await initDenops(denops);

await denops.dispatch("skkeleton", "enable");
await dispatch(currentContext.get(), " ");
assertEquals(
Expand Down
6 changes: 1 addition & 5 deletions denops/skkeleton/function/input_test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { config } from "../config.ts";
import { Context } from "../context.ts";
import { Denops, op } from "../deps.ts";
import { test } from "../deps/denops_test.ts";
import { assertEquals } from "../deps/std/assert.ts";
import { initDenops } from "../testutil.ts";
import { test } from "../testutil.ts";
import { kakutei } from "./common.ts";
import { deleteChar, henkanPoint } from "./input.ts";
import { hankatakana, katakana } from "./mode.ts";
Expand Down Expand Up @@ -132,10 +131,7 @@ config.userJisyo = "";
test({
mode: "nvim",
name: "new line",
pluginName: "skkeleton",
async fn(denops: Denops) {
await initDenops(denops);

await op.autoindent.setLocal(denops, true);
await denops.cmd("startinsert");
await denops.cmd(
Expand Down
6 changes: 2 additions & 4 deletions denops/skkeleton/function/jisyo_test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { Denops } from "../deps.ts";
import { test } from "../deps/denops_test.ts";
import { assertEquals } from "../deps/std/assert.ts";
import { currentKanaTable, getKanaTable } from "../kana.ts";
import { currentContext } from "../store.ts";
import { HenkanState } from "../state.ts";
import { initDenops } from "../testutil.ts";
import { currentContext } from "../store.ts";
import { test } from "../testutil.ts";
import { jisyoTouroku } from "./jisyo.ts";

test({
mode: "all",
name: "Don't put string when register dictionary was cancelled",
async fn(denops: Denops) {
await initDenops(denops);
currentKanaTable.get();
const state: HenkanState = {
type: "henkan",
Expand Down
11 changes: 2 additions & 9 deletions denops/skkeleton/function/mode_test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { autocmd, Denops, vars } from "../deps.ts";
import { test } from "../deps/denops_test.ts";
import { assertEquals } from "../deps/std/assert.ts";
import { currentLibrary } from "../store.ts";
import { currentKanaTable } from "../kana.ts";
import { currentLibrary } from "../store.ts";
import { currentContext } from "../store.ts";
import { initDenops } from "../testutil.ts";
import { test } from "../testutil.ts";
import { kakutei } from "./common.ts";
import { deleteChar, kanaInput } from "./input.ts";
import { abbrev, hankatakana, katakana, zenkaku } from "./mode.ts";
Expand All @@ -13,9 +12,7 @@ import { dispatch } from "./testutil.ts";
test({
mode: "all",
name: "Can get skkeleton mode",
pluginName: "skkeleton",
async fn(d: Denops) {
await initDenops(d);
assertEquals(await d.call("skkeleton#mode"), "");
await d.dispatch("skkeleton", "enable");
assertEquals(await d.call("skkeleton#mode"), "hira");
Expand All @@ -36,9 +33,7 @@ test({
test({
mode: "all",
name: "Fire autocmd for mode changed",
pluginName: "skkeleton",
async fn(d: Denops) {
await initDenops(d);
await autocmd.define(
d,
"User",
Expand Down Expand Up @@ -108,9 +103,7 @@ Deno.test({
test({
mode: "all",
name: "mode change at enable",
pluginName: "skkeleton",
async fn(d: Denops) {
await initDenops(d);
await autocmd.define(
d,
"User",
Expand Down
5 changes: 1 addition & 4 deletions denops/skkeleton/kana_test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { config } from "./config.ts";
import { Context } from "./context.ts";
import { test } from "./deps/denops_test.ts";
import { assertEquals } from "./deps/std/assert.ts";
import { dispatch } from "./function/testutil.ts";
import { registerKanaTable } from "./kana.ts";
import { currentContext } from "./store.ts";
import { initDenops } from "./testutil.ts";
import { test } from "./testutil.ts";

Deno.test({
name: "customize kanatable",
Expand All @@ -28,13 +27,11 @@ Deno.test({
test({
mode: "all",
name: "create kanatable",
pluginName: "skkeleton",
async fn(denops) {
registerKanaTable("test", {
a: ["hoge", ""],
}, true);
config.kanaTable = "test";
await initDenops(denops);
await denops.call("skkeleton#request", "enable", []);
const context = currentContext.get();
await dispatch(context, "a");
Expand Down
7 changes: 1 addition & 6 deletions denops/skkeleton/keymap_test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { test } from "./deps/denops_test.ts";
import { test } from "./testutil.ts";
import { assertEquals } from "./deps/std/assert.ts";
import { currentLibrary } from "./store.ts";
import { currentContext } from "./store.ts";
import { initDenops } from "./testutil.ts";

test({
mode: "nvim", // can input mode test only in nvim
name: "registerKeyMap",
pluginName: "skkeleton",
async fn(denops) {
await initDenops(denops);
const lib = await currentLibrary.get();
lib.registerHenkanResult("okurinasi", "あ", "亜");
await denops.cmd('call skkeleton#register_keymap("henkan", "x", "")');
Expand Down Expand Up @@ -59,9 +56,7 @@ test({
test({
mode: "all",
name: "send multiple keys into handleKey",
pluginName: "skkeleton",
async fn(denops) {
await initDenops(denops);
const lib = await currentLibrary.get();
lib.registerHenkanResult("okurinasi", "われ", "我");
lib.registerHenkanResult("okuriari", "おもu", "思");
Expand Down
36 changes: 26 additions & 10 deletions denops/skkeleton/testutil.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
import { fromFileUrl } from "./deps/std/path.ts";
import { autocmd, Denops } from "./deps.ts";
import * as DenopsTest from "./deps/denops_test.ts";
import * as path from "./deps/std/path.ts";
import { main } from "./main.ts";
import { currentContext } from "./store.ts";

export async function initDenops(denops: Denops): Promise<void> {
const cfile = fromFileUrl(new URL(import.meta.url));
const path = cfile.slice(0, cfile.lastIndexOf("denops"));
await denops.cmd(`set runtimepath^=${path.replaceAll("\\", "/")}`);
await denops.cmd("source " + path + "plugin/skkeleton.vim");
await main(denops);
await autocmd.emit(denops, "User", "DenopsSystemPluginPost:skkeleton", {
nomodeline: true,
const runtimepath = path.resolve(
path.fromFileUrl(new URL("../..", import.meta.url)),
);

// It is inspired from https://github.com/lambdalisue/gin.vim/blob/e737a4b59a9d391c49aaa07f7c4d91e4a29ae09c/denops/gin/util/testutil.ts
// Copyright 2021 Alisue <[email protected]>
export function test(def: DenopsTest.TestDefinition): void {
const fn = def.fn;
DenopsTest.test({
...def,
async fn(denops: Denops, t: Deno.TestContext) {
await main(denops);
await autocmd.emit(denops, "User", "DenopsSystemPluginPost:skkeleton", {
nomodeline: true,
});
currentContext.init().denops = denops;
await fn(denops, t);
},
pluginName: "skkeleton",
prelude: [
`set runtimepath^=${runtimepath}`,
"runtime! plugin/skkeleton.vim",
...(def.prelude ?? []),
],
});
currentContext.init().denops = denops;
}
Loading