Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Dec 17, 2023
1 parent 1432a0a commit 2834394
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
2 changes: 2 additions & 0 deletions denops/skkeleton/jisyo/skk_dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export class SkkDictionary implements Dictionary {
const file = await readFileWithEncoding(path, encoding);
this.loadString(file);
}

return this;
}

private loadJson(data: string) {
Expand Down
34 changes: 14 additions & 20 deletions denops/skkeleton/jisyo_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { assertEquals } from "./deps/std/assert.ts";
import { Library, load as loadJisyo, wrapDictionary } from "./jisyo.ts";
import { SkkDictionary } from "./jisyo/skk_dictionary.ts";
import { UserDictionary } from "./jisyo/user_dictionary.ts";
import { readFileWithEncoding } from "./util.ts";

const newJisyoJson = join(
dirname(fromFileUrl(import.meta.url)),
Expand Down Expand Up @@ -41,22 +40,11 @@ const numIncludingJisyo = join(
"numIncludingJisyo",
);

async function load(path: string, encoding: string): Promise<SkkDictionary> {
const dic = new SkkDictionary();
if (path.endsWith(".json")) {
dic.loadJson(await readFileWithEncoding(path, encoding));
} else if (path.endsWith(".yaml") || path.endsWith(".yml")) {
dic.loadYaml(await readFileWithEncoding(path, encoding));
} else {
dic.load(await readFileWithEncoding(path, encoding));
}
return dic;
}

Deno.test({
name: "load new JisyoJson",
async fn() {
const jisyo = await load(newJisyoJson, "utf-8");
const dic = new SkkDictionary();
const jisyo = await dic.load(newJisyoJson, "utf-8");
const manager = new Library([jisyo]);
const ari = await manager.getHenkanResult("okuriari", "わるs");
assertEquals(["悪"], ari);
Expand All @@ -68,7 +56,8 @@ Deno.test({
Deno.test({
name: "load new JisyoYaml",
async fn() {
const jisyo = await load(newJisyoYaml, "utf-8");
const dic = new SkkDictionary();
const jisyo = await dic.load(newJisyoYaml, "utf-8");
const manager = new Library([jisyo]);
const ari = await manager.getHenkanResult("okuriari", "わるs");
assertEquals(["悪"], ari);
Expand All @@ -80,7 +69,8 @@ Deno.test({
Deno.test({
name: "get candidates",
async fn() {
const jisyo = await load(globalJisyo, "euc-jp");
const dic = new SkkDictionary();
const jisyo = await dic.load(globalJisyo, "euc-jp");
const manager = new Library([jisyo]);
const ari = await manager.getHenkanResult("okuriari", "てすt");
assertEquals(["テスト"], ari);
Expand All @@ -92,7 +82,8 @@ Deno.test({
Deno.test({
name: "get num candidates",
async fn() {
const jisyo = wrapDictionary(await load(numJisyo, "euc-jp"));
const dic = new SkkDictionary();
const jisyo = wrapDictionary(await dic.load(numJisyo, "euc-jp"));
const manager = new Library([jisyo]);
const nasi = await manager.getHenkanResult("okurinasi", "101ばん");
assertEquals(nasi, [
Expand All @@ -111,7 +102,8 @@ Deno.test({
Deno.test({
name: "get num candidates (Kifu)",
async fn() {
const jisyo = wrapDictionary(await load(numJisyo, "euc-jp"));
const dic = new SkkDictionary();
const jisyo = wrapDictionary(await dic.load(numJisyo, "euc-jp"));
const manager = new Library([jisyo]);
const nasi1 = await manager.getHenkanResult("okurinasi", "11おうて");
assertEquals(nasi1, ["1一王手"]);
Expand All @@ -123,7 +115,8 @@ Deno.test({
Deno.test({
name: "get candidates from words that include numbers",
async fn() {
const jisyo = wrapDictionary(await load(numIncludingJisyo, "utf-8"));
const dic = new SkkDictionary();
const jisyo = wrapDictionary(await dic.load(numIncludingJisyo, "utf-8"));
const manager = new Library([jisyo]);
const nasi1 = await manager.getHenkanResult("okurinasi", "cat2");
assertEquals(nasi1, ["🐈"]);
Expand Down Expand Up @@ -156,7 +149,8 @@ Deno.test({
Deno.test({
name: "global/local jisyo interop",
async fn() {
const jisyo = await load(globalJisyo, "euc-jp");
const dic = new SkkDictionary();
const jisyo = await dic.load(globalJisyo, "euc-jp");
const library = new Library([jisyo]);
await library.registerHenkanResult("okurinasi", "てすと", "test");

Expand Down

0 comments on commit 2834394

Please sign in to comment.