дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 10:07:11 +02:00
Run oxfmt once over the whole repository (formatting only, no logic changes) and add `pnpm format:check` to the frontend CI job so unformatted code no longer builds up. `.oxfmtrc.json` now skips the generated theme docs, test fixtures and code blocks inside Markdown. Co-authored-by: jaw52 <[email protected]>
61 рядки
2.1 KiB
TypeScript
61 рядки
2.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { findAll, findRanges, formatDuration, pathLink, quoteText, withQuote } from "./conversation";
|
|
|
|
describe("quoting", () => {
|
|
it("quotes each line and leaves a line to type on", () => {
|
|
expect(quoteText("one\n\ntwo\n")).toBe("> one\n>\n> two\n\n");
|
|
});
|
|
it("adds the quote after a draft", () => {
|
|
expect(withQuote("", "x")).toBe("> x\n\n");
|
|
expect(withQuote("Why? ", "x")).toBe("Why?\n\n> x\n\n");
|
|
});
|
|
});
|
|
|
|
describe("pathLink", () => {
|
|
const cwd = "/repo";
|
|
it("resolves relative paths with a line and column", () => {
|
|
expect(pathLink("src/lib.rs", cwd)).toEqual({ path: "/repo/src/lib.rs" });
|
|
expect(pathLink("./src/main.rs:12", cwd)).toEqual({ path: "/repo/src/main.rs", line: 11 });
|
|
expect(pathLink("a/b.ts:3:5", cwd)).toEqual({ path: "/repo/a/b.ts", line: 2, col: 4 });
|
|
expect(pathLink("Cargo.toml", cwd)).toEqual({ path: "/repo/Cargo.toml" });
|
|
expect(pathLink("/abs/x.py#L7", cwd)).toEqual({ path: "/abs/x.py", line: 6 });
|
|
});
|
|
it("ignores code that isn't a path", () => {
|
|
for (const t of [
|
|
"foo()",
|
|
"cargo test",
|
|
"https://x.dev/a.md",
|
|
"inventory",
|
|
"1.5",
|
|
"v2.0",
|
|
"a.b()",
|
|
"failing-tests",
|
|
"tests/",
|
|
]) {
|
|
expect(pathLink(t, cwd)).toBeNull();
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("formatDuration", () => {
|
|
it("scales the unit", () => {
|
|
expect(formatDuration(850)).toBe("850ms");
|
|
expect(formatDuration(12_400)).toBe("12s");
|
|
expect(formatDuration(65_000)).toBe("1m 05s");
|
|
expect(formatDuration(2 * 3600_000 + 3 * 60_000)).toBe("2h 03m");
|
|
});
|
|
});
|
|
|
|
describe("finding", () => {
|
|
it("finds every occurrence, ignoring case", () => {
|
|
expect(findAll("Abc abc ABC", "abc")).toEqual([0, 4, 8]);
|
|
expect(findAll("aaa", "")).toEqual([]);
|
|
});
|
|
it("maps matches to DOM ranges", () => {
|
|
const root = document.createElement("div");
|
|
root.innerHTML = "<p>one <code>two</code> one</p>";
|
|
expect(findRanges(root, "one").map((r) => r.toString())).toEqual(["one", "one"]);
|
|
expect(findRanges(root, "TWO")).toHaveLength(1);
|
|
});
|
|
});
|