mirror of
https://github.com/TextPlace/CoreTextPlace.git
synced 2025-12-18 05:02:36 +00:00
refactor: Migrate project from Deno to pnpm/Node
Replace Deno configs and workflows with pnpm/Node tooling Add package.json, jsr.json, build.config.ts and pnpm-lock.yaml Remove deno.json, deno.lock, Deno build scripts and workflow Move source files into src/ and update imports and tests to vitest Add Test CI workflow and adapt publish jobs for pnpm/node Update editor settings, tasks, .gitignore and bump LICENSE year
This commit is contained in:
parent
7923680e80
commit
32534084df
26 changed files with 2132 additions and 430 deletions
|
|
@ -1,22 +1,19 @@
|
|||
import {
|
||||
assert,
|
||||
assertEquals,
|
||||
} from "https://deno.land/std@0.224.0/assert/mod.ts";
|
||||
import { describe, it, expect } from "vitest";
|
||||
|
||||
import {
|
||||
createBoard,
|
||||
getSectionOnBoard,
|
||||
renderFullBoard,
|
||||
} from "../logic/board.ts";
|
||||
import type { BoardData } from "../types/board.ts";
|
||||
import type { BoardData } from "../src/types/board.ts";
|
||||
import { checkFullBoard } from "./checkFullBoard.ts";
|
||||
import { locateSection } from "../logic/board.ts";
|
||||
import { applyChangeOnBoard } from "../logic/board.ts";
|
||||
import { locateSection } from "../src/logic/board.ts";
|
||||
import { applyChangeOnBoard } from "../src/logic/board.ts";
|
||||
|
||||
Deno.test("board", async (t) => {
|
||||
describe("board", () => {
|
||||
let board: BoardData | undefined;
|
||||
|
||||
await t.step("createBoard", () => {
|
||||
it("createBoard", () => {
|
||||
board = createBoard({
|
||||
xSections: 3,
|
||||
ySections: 3,
|
||||
|
|
@ -29,96 +26,96 @@ Deno.test("board", async (t) => {
|
|||
});
|
||||
|
||||
// Sections are created on demand.
|
||||
assertEquals(board.sections.length, 0);
|
||||
expect(board.sections.length).toBe(0);
|
||||
});
|
||||
|
||||
await t.step("locateSection", () => {
|
||||
assert(board);
|
||||
it("locateSection", () => {
|
||||
expect(board).toBeDefined();
|
||||
|
||||
const { sx, sy } = locateSection({ x: 0, y: 0 }, board.config);
|
||||
assertEquals(sx, 0);
|
||||
assertEquals(sy, 0);
|
||||
const { sx, sy } = locateSection({ x: 0, y: 0 }, board!.config);
|
||||
expect(sx).toBe(0);
|
||||
expect(sy).toBe(0);
|
||||
|
||||
const { sx: sx2, sy: sy2 } = locateSection({ x: 4, y: 0 }, board.config);
|
||||
assertEquals(sx2, 1);
|
||||
assertEquals(sy2, 0);
|
||||
const { sx: sx2, sy: sy2 } = locateSection({ x: 4, y: 0 }, board!.config);
|
||||
expect(sx2).toBe(1);
|
||||
expect(sy2).toBe(0);
|
||||
});
|
||||
|
||||
await t.step("applyChangeOnBoard", () => {
|
||||
assert(board);
|
||||
it("applyChangeOnBoard", () => {
|
||||
expect(board).toBeDefined();
|
||||
|
||||
applyChangeOnBoard({ x: 0, y: 0, ch: "A" }, board);
|
||||
applyChangeOnBoard({ x: 4, y: 0, ch: "B" }, board);
|
||||
applyChangeOnBoard({ x: 0, y: 3, ch: "C" }, board);
|
||||
applyChangeOnBoard({ x: 4, y: 3, ch: "D" }, board);
|
||||
applyChangeOnBoard({ x: 5, y: 3, ch: "E" }, board);
|
||||
applyChangeOnBoard({ x: 0, y: 0, ch: "A" }, board!);
|
||||
applyChangeOnBoard({ x: 4, y: 0, ch: "B" }, board!);
|
||||
applyChangeOnBoard({ x: 0, y: 3, ch: "C" }, board!);
|
||||
applyChangeOnBoard({ x: 4, y: 3, ch: "D" }, board!);
|
||||
applyChangeOnBoard({ x: 5, y: 3, ch: "E" }, board!);
|
||||
|
||||
assertEquals(board.sections[0][0].ch[0][0], "A");
|
||||
assertEquals(board.sections[0][1].ch[0][0], "B");
|
||||
assertEquals(board.sections[1][0].ch[0][0], "C");
|
||||
assertEquals(board.sections[1][1].ch[0], ["D", "E", " ", " "]);
|
||||
expect(board!.sections[0][0].ch[0][0]).toBe("A");
|
||||
expect(board!.sections[0][1].ch[0][0]).toBe("B");
|
||||
expect(board!.sections[1][0].ch[0][0]).toBe("C");
|
||||
expect(board!.sections[1][1].ch[0]).toEqual(["D", "E", " ", " "]);
|
||||
|
||||
applyChangeOnBoard({ x: 0, y: 1, ch: "你" }, board);
|
||||
applyChangeOnBoard({ x: 4, y: 2, ch: "好" }, board);
|
||||
applyChangeOnBoard({ x: 0, y: 4, ch: "嗎" }, board);
|
||||
applyChangeOnBoard({ x: 4, y: 4, ch: "嘛" }, board);
|
||||
applyChangeOnBoard({ x: 0, y: 1, ch: "你" }, board!);
|
||||
applyChangeOnBoard({ x: 4, y: 2, ch: "好" }, board!);
|
||||
applyChangeOnBoard({ x: 0, y: 4, ch: "嗎" }, board!);
|
||||
applyChangeOnBoard({ x: 4, y: 4, ch: "嘛" }, board!);
|
||||
|
||||
assertEquals(board.sections[0][0].ch[1][0], "你");
|
||||
assertEquals(board.sections[0][1].ch[2][0], "好");
|
||||
assertEquals(board.sections[1][0].ch[1][0], "嗎");
|
||||
assertEquals(board.sections[1][1].ch[1], ["嘛", " ", " ", " "]);
|
||||
expect(board!.sections[0][0].ch[1][0]).toBe("你");
|
||||
expect(board!.sections[0][1].ch[2][0]).toBe("好");
|
||||
expect(board!.sections[1][0].ch[1][0]).toBe("嗎");
|
||||
expect(board!.sections[1][1].ch[1]).toEqual(["嘛", " ", " ", " "]);
|
||||
|
||||
applyChangeOnBoard({ x: 5, y: 4, ch: "啊" }, board);
|
||||
assertEquals(board.sections[1][1].ch[1], ["啊", " ", " ", " "]);
|
||||
applyChangeOnBoard({ x: 5, y: 4, ch: "啊" }, board!);
|
||||
expect(board!.sections[1][1].ch[1]).toEqual(["啊", " ", " ", " "]);
|
||||
});
|
||||
|
||||
await t.step("getSectionOnBoard: existing section", () => {
|
||||
assert(board);
|
||||
it("getSectionOnBoard: existing section", () => {
|
||||
expect(board).toBeDefined();
|
||||
|
||||
const section = getSectionOnBoard({ sx: 1, sy: 1 }, board, {
|
||||
const section = getSectionOnBoard({ sx: 1, sy: 1 }, board!, {
|
||||
readOnly: true,
|
||||
});
|
||||
assertEquals(section.ch[0], ["D", "E", " ", " "]);
|
||||
assertEquals(section.color[0][0], "F");
|
||||
assertEquals(section.bgColor[0][0], "0");
|
||||
assertEquals(section.width[0], [1, 1, 1, 1]);
|
||||
expect(section.ch[0]).toEqual(["D", "E", " ", " "]);
|
||||
expect(section.color[0][0]).toBe("F");
|
||||
expect(section.bgColor[0][0]).toBe("0");
|
||||
expect(section.width[0]).toEqual([1, 1, 1, 1]);
|
||||
});
|
||||
|
||||
await t.step("getSectionOnBoard: non-existing row", () => {
|
||||
assert(board);
|
||||
it("getSectionOnBoard: non-existing row", () => {
|
||||
expect(board).toBeDefined();
|
||||
|
||||
const section = getSectionOnBoard({ sx: 1, sy: 2 }, board, {
|
||||
const section = getSectionOnBoard({ sx: 1, sy: 2 }, board!, {
|
||||
readOnly: true,
|
||||
});
|
||||
assertEquals(section.ch[0][0], " ");
|
||||
assertEquals(section.color[0][0], "F");
|
||||
assertEquals(section.bgColor[0][0], "0");
|
||||
assertEquals(section.width[0][0], 1);
|
||||
expect(section.ch[0][0]).toBe(" ");
|
||||
expect(section.color[0][0]).toBe("F");
|
||||
expect(section.bgColor[0][0]).toBe("0");
|
||||
expect(section.width[0][0]).toBe(1);
|
||||
});
|
||||
|
||||
await t.step("getSectionOnBoard: non-existing section", () => {
|
||||
assert(board);
|
||||
it("getSectionOnBoard: non-existing section", () => {
|
||||
expect(board).toBeDefined();
|
||||
|
||||
const section = getSectionOnBoard({ sx: 2, sy: 1 }, board, {
|
||||
const section = getSectionOnBoard({ sx: 2, sy: 1 }, board!, {
|
||||
readOnly: true,
|
||||
});
|
||||
assertEquals(section.ch[0][0], " ");
|
||||
assertEquals(section.color[0][0], "F");
|
||||
assertEquals(section.bgColor[0][0], "0");
|
||||
assertEquals(section.width[0][0], 1);
|
||||
expect(section.ch[0][0]).toBe(" ");
|
||||
expect(section.color[0][0]).toBe("F");
|
||||
expect(section.bgColor[0][0]).toBe("0");
|
||||
expect(section.width[0][0]).toBe(1);
|
||||
});
|
||||
|
||||
await t.step("renderFullBoard", () => {
|
||||
assert(board);
|
||||
it("renderFullBoard", () => {
|
||||
expect(board).toBeDefined();
|
||||
|
||||
const rendered = renderFullBoard(board);
|
||||
const rendered = renderFullBoard(board!);
|
||||
checkFullBoard(rendered);
|
||||
});
|
||||
|
||||
await t.step("on-demand creation: only changed sections are saved", () => {
|
||||
assert(board);
|
||||
it("on-demand creation: only changed sections are saved", () => {
|
||||
expect(board).toBeDefined();
|
||||
|
||||
assertEquals(board.sections[2], undefined);
|
||||
assertEquals(board.sections[0][2], undefined);
|
||||
expect(board!.sections[2]).toBeUndefined();
|
||||
expect(board!.sections[0][2]).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,43 +1,40 @@
|
|||
import {
|
||||
assertEquals,
|
||||
assertThrows,
|
||||
} from "https://deno.land/std@0.224.0/assert/mod.ts";
|
||||
import { it, expect } from "vitest";
|
||||
|
||||
import { getCharacterWidth } from "../mod.ts";
|
||||
import { getCharacterWidth } from "../src/mod.ts";
|
||||
|
||||
Deno.test("getCharacterWidth ASCII", () => {
|
||||
assertEquals(getCharacterWidth("a"), 1);
|
||||
assertEquals(getCharacterWidth("A"), 1);
|
||||
assertEquals(getCharacterWidth("1"), 1);
|
||||
assertEquals(getCharacterWidth("@"), 1);
|
||||
assertEquals(getCharacterWidth(" "), 1);
|
||||
it("getCharacterWidth ASCII", () => {
|
||||
expect(getCharacterWidth("a")).toBe(1);
|
||||
expect(getCharacterWidth("A")).toBe(1);
|
||||
expect(getCharacterWidth("1")).toBe(1);
|
||||
expect(getCharacterWidth("@")).toBe(1);
|
||||
expect(getCharacterWidth(" ")).toBe(1);
|
||||
|
||||
assertThrows(() => getCharacterWidth(""));
|
||||
assertThrows(() => getCharacterWidth("ab"));
|
||||
expect(() => getCharacterWidth("")).toThrow();
|
||||
expect(() => getCharacterWidth("ab")).toThrow();
|
||||
});
|
||||
|
||||
Deno.test("getCharacterWidth CJK", () => {
|
||||
assertEquals(getCharacterWidth("你"), 2);
|
||||
assertEquals(getCharacterWidth("好"), 2);
|
||||
assertEquals(getCharacterWidth("吗"), 2);
|
||||
it("getCharacterWidth CJK", () => {
|
||||
expect(getCharacterWidth("你")).toBe(2);
|
||||
expect(getCharacterWidth("好")).toBe(2);
|
||||
expect(getCharacterWidth("吗")).toBe(2);
|
||||
|
||||
assertEquals(getCharacterWidth("ガ"), 2);
|
||||
assertEquals(getCharacterWidth("ギ"), 2);
|
||||
assertEquals(getCharacterWidth("グ"), 2);
|
||||
assertEquals(getCharacterWidth("ソ"), 2);
|
||||
expect(getCharacterWidth("ガ")).toBe(2);
|
||||
expect(getCharacterWidth("ギ")).toBe(2);
|
||||
expect(getCharacterWidth("グ")).toBe(2);
|
||||
expect(getCharacterWidth("ソ")).toBe(2);
|
||||
|
||||
assertEquals(getCharacterWidth("?"), 2);
|
||||
assertEquals(getCharacterWidth("!"), 2);
|
||||
assertThrows(() => getCharacterWidth("你好"));
|
||||
assertThrows(() => getCharacterWidth("ヨスガノ"));
|
||||
expect(getCharacterWidth("?")).toBe(2);
|
||||
expect(getCharacterWidth("!")).toBe(2);
|
||||
expect(() => getCharacterWidth("你好")).toThrow();
|
||||
expect(() => getCharacterWidth("ヨスガノ")).toThrow();
|
||||
});
|
||||
|
||||
Deno.test("getCharacterWidth Emoji", () => {
|
||||
assertEquals(getCharacterWidth("👋"), 2);
|
||||
assertEquals(getCharacterWidth("🌲️"), 2);
|
||||
assertEquals(getCharacterWidth("👨👩👧👦"), 2);
|
||||
it("getCharacterWidth Emoji", () => {
|
||||
expect(getCharacterWidth("👋")).toBe(2);
|
||||
expect(getCharacterWidth("🌲️")).toBe(2);
|
||||
expect(getCharacterWidth("👨👩👧👦")).toBe(2);
|
||||
});
|
||||
|
||||
Deno.test("getCharacterWidth previously faulty cases", () => {
|
||||
assertEquals(getCharacterWidth("𤲶"), 2);
|
||||
it("getCharacterWidth previously faulty cases", () => {
|
||||
expect(getCharacterWidth("𤲶")).toBe(2);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { getCharacterWidth } from "../logic/character.ts";
|
||||
import type { FullBoard } from "../types/board.ts";
|
||||
import { getCharacterWidth } from "../src/logic/character.ts";
|
||||
import type { FullBoard } from "../src/types/board.ts";
|
||||
|
||||
function isCorrectWidth(cWd: number, cCh: string): boolean {
|
||||
return getCharacterWidth(cCh) === cWd;
|
||||
|
|
|
|||
|
|
@ -1,17 +1,13 @@
|
|||
import {
|
||||
assert,
|
||||
assertEquals,
|
||||
assertThrows,
|
||||
} from "https://deno.land/std@0.224.0/assert/mod.ts";
|
||||
import { describe, it, expect } from "vitest";
|
||||
|
||||
import { applyChange, createSection } from "../logic/section.ts";
|
||||
import type { SectionData } from "../types/section.ts";
|
||||
import { applyChange, createSection } from "../src/logic/section.ts";
|
||||
import type { SectionData } from "../src/types/section.ts";
|
||||
|
||||
Deno.test("section", async (t) => {
|
||||
describe("section", () => {
|
||||
let section: SectionData | undefined;
|
||||
|
||||
await t.step("createSection non-lcm", () => {
|
||||
assertThrows(() => {
|
||||
it("createSection non-lcm", () => {
|
||||
expect(() => {
|
||||
createSection(
|
||||
{ sx: 0, sy: 0 },
|
||||
{
|
||||
|
|
@ -25,10 +21,10 @@ Deno.test("section", async (t) => {
|
|||
defaultWidth: 1,
|
||||
},
|
||||
);
|
||||
});
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
await t.step("createSection non-origin section", () => {
|
||||
it("createSection non-origin section", () => {
|
||||
section = createSection(
|
||||
{ sx: 1, sy: 1 },
|
||||
{
|
||||
|
|
@ -43,11 +39,11 @@ Deno.test("section", async (t) => {
|
|||
},
|
||||
);
|
||||
|
||||
assertEquals(section.offsetX, 4);
|
||||
assertEquals(section.offsetY, 3);
|
||||
expect(section.offsetX).toBe(4);
|
||||
expect(section.offsetY).toBe(3);
|
||||
});
|
||||
|
||||
await t.step("createSection", () => {
|
||||
it("createSection", () => {
|
||||
section = createSection(
|
||||
{ sx: 0, sy: 0 },
|
||||
{
|
||||
|
|
@ -62,8 +58,8 @@ Deno.test("section", async (t) => {
|
|||
},
|
||||
);
|
||||
|
||||
assertEquals(section.offsetX, 0);
|
||||
assertEquals(section.offsetY, 0);
|
||||
expect(section.offsetX).toBe(0);
|
||||
expect(section.offsetY).toBe(0);
|
||||
|
||||
function assertSectionContent<T>(
|
||||
content: T[][],
|
||||
|
|
@ -71,11 +67,11 @@ Deno.test("section", async (t) => {
|
|||
columnCount: number,
|
||||
value: T,
|
||||
) {
|
||||
assertEquals(content.length, rowCount);
|
||||
expect(content.length).toBe(rowCount);
|
||||
for (const row of content) {
|
||||
assertEquals(row.length, columnCount);
|
||||
expect(row.length).toBe(columnCount);
|
||||
for (const item of row) {
|
||||
assertEquals(item, value);
|
||||
expect(item).toBe(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -86,44 +82,44 @@ Deno.test("section", async (t) => {
|
|||
assertSectionContent(section.width, 3, 4, 1);
|
||||
});
|
||||
|
||||
await t.step("applyChange 1-width", () => {
|
||||
assert(section);
|
||||
it("applyChange 1-width", () => {
|
||||
expect(section).toBeDefined();
|
||||
|
||||
applyChange({ x: 0, y: 0, ch: "t" }, section);
|
||||
assertEquals(section.ch[0], ["t", " ", " ", " "]);
|
||||
assertEquals(section.ch[1], [" ", " ", " ", " "]);
|
||||
assertEquals(section.width[0], [1, 1, 1, 1]);
|
||||
applyChange({ x: 0, y: 0, ch: "t" }, section!);
|
||||
expect(section!.ch[0]).toEqual(["t", " ", " ", " "]);
|
||||
expect(section!.ch[1]).toEqual([" ", " ", " ", " "]);
|
||||
expect(section!.width[0]).toEqual([1, 1, 1, 1]);
|
||||
});
|
||||
|
||||
await t.step("applyChange 1-width at odd position", () => {
|
||||
assert(section);
|
||||
it("applyChange 1-width at odd position", () => {
|
||||
expect(section).toBeDefined();
|
||||
|
||||
applyChange({ x: 1, y: 0, ch: "t" }, section);
|
||||
assertEquals(section.ch[0], ["t", "t", " ", " "]);
|
||||
assertEquals(section.width[0], [1, 1, 1, 1]);
|
||||
applyChange({ x: 1, y: 0, ch: "t" }, section!);
|
||||
expect(section!.ch[0]).toEqual(["t", "t", " ", " "]);
|
||||
expect(section!.width[0]).toEqual([1, 1, 1, 1]);
|
||||
});
|
||||
|
||||
await t.step("applyChange 2-width at a correct position", () => {
|
||||
assert(section);
|
||||
it("applyChange 2-width at a correct position", () => {
|
||||
expect(section).toBeDefined();
|
||||
|
||||
applyChange({ x: 0, y: 0, ch: "あ" }, section);
|
||||
assertEquals(section.ch[0], ["あ", "t", " ", " "]);
|
||||
assertEquals(section.width[0], [2, 1, 1, 1]);
|
||||
applyChange({ x: 0, y: 0, ch: "あ" }, section!);
|
||||
expect(section!.ch[0]).toEqual(["あ", "t", " ", " "]);
|
||||
expect(section!.width[0]).toEqual([2, 1, 1, 1]);
|
||||
});
|
||||
|
||||
await t.step("applyChange 2-width at an alternate position", () => {
|
||||
assert(section);
|
||||
it("applyChange 2-width at an alternate position", () => {
|
||||
expect(section).toBeDefined();
|
||||
|
||||
applyChange({ x: 1, y: 0, ch: "あ" }, section);
|
||||
assertEquals(section.ch[0], ["あ", "t", " ", " "]);
|
||||
assertEquals(section.width[0], [2, 1, 1, 1]);
|
||||
applyChange({ x: 1, y: 0, ch: "あ" }, section!);
|
||||
expect(section!.ch[0]).toEqual(["あ", "t", " ", " "]);
|
||||
expect(section!.width[0]).toEqual([2, 1, 1, 1]);
|
||||
});
|
||||
|
||||
await t.step("applyChange incorrect section", () => {
|
||||
assertThrows(() => {
|
||||
assert(section);
|
||||
it("applyChange incorrect section", () => {
|
||||
expect(section).toBeDefined();
|
||||
|
||||
applyChange({ x: 6, y: 3, ch: "あ" }, section);
|
||||
});
|
||||
expect(() => {
|
||||
applyChange({ x: 6, y: 3, ch: "あ" }, section!);
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue