Files
t3tui/test/editor.test.ts
Callum Alpass eb5cccece1 Windows: fix cmd quoting, CRLF saves and Neovim's remote output
cmd strips outer quotes when a line starts with one, which broke .cmd editors with spaces in both paths. Neovim on Windows prints remote results to the console, so they ran over the screen and never reached us; give it a hidden console and read results from a file.
2026-11-04 08:10:32 +11:00

31 lines
1.3 KiB
TypeScript

import { expect, test } from "bun:test";
import { writeFileSync } from "node:fs";
import { isNvim, scratchFile, windowsCommand, windowsWords } from "../src/ui/editor.ts";
test("splits a Windows command line on spaces outside quotes", () => {
expect(windowsWords('"C:\\Program Files\\Git\\usr\\bin\\vim.exe" -p')).toEqual(["C:\\Program Files\\Git\\usr\\bin\\vim.exe", "-p"]);
expect(windowsWords("code --wait")).toEqual(["code", "--wait"]);
});
test("runs a .cmd through cmd, and anything else as it is", () => {
const which = (program: string) => ({ code: "C:\\VS Code\\bin\\code.cmd", nvim: "C:\\nvim\\nvim.exe" })[program] ?? null;
expect(windowsCommand("code --wait", which)).toEqual(["cmd.exe", "/c", "call", "C:\\VS Code\\bin\\code.cmd", "--wait"]);
expect(windowsCommand("nvim", which)).toEqual(["C:\\nvim\\nvim.exe"]);
expect(windowsCommand("missing", which)).toEqual(["missing"]);
});
test("knows Neovim by name or path", () => {
expect(isNvim("nvim")).toBe(true);
expect(isNvim("/usr/bin/nvim")).toBe(true);
expect(isNvim("C:\\Program Files\\Neovim\\bin\\nvim.exe")).toBe(true);
expect(isNvim("vim")).toBe(false);
});
test("reads back a scratch file saved with CRLF", () => {
const file = scratchFile("");
writeFileSync(file.path, "one\r\ntwo\r\n");
expect(file.read()).toBe("one\ntwo");
file.remove();
});