import { describe, expect, it } from "vitest"; import { completeTestCommandArguments, currentCompletionToken, testCommandTailBeforeCursor, } from "./complete-test-command-arguments.ts"; describe("completeTestCommandArguments", () => { it("suggests supported flags for an empty argument prefix", () => { expect(completeTestCommandArguments("")).toEqual([ { value: "--info", label: "--info", description: "Show full command output", }, { value: "--tags", label: "--tags", description: "Run with Go build tags", }, { value: "--comment", label: "--comment", description: "Ask the model to analyze the test results", }, ]); }); it("suggests the supported test command flags", () => { expect(completeTestCommandArguments("--")).toEqual([ { value: "--info", label: "--info", description: "Show full command output", }, { value: "--tags", label: "--tags", description: "Run with Go build tags", }, { value: "--comment", label: "--comment", description: "Ask the model to analyze the test results", }, ]); }); it("filters suggestions by the current flag prefix", () => { expect(completeTestCommandArguments("--i")).toEqual([ { value: "--info", label: "--info", description: "Show full command output", }, ]); }); it("does not suggest the alternate --tags= form", () => { const values = completeTestCommandArguments("--")?.map( (item) => item.value, ); expect(values).toEqual(["--info", "--tags", "--comment"]); }); it("suggests remaining flags after --info is already present", () => { expect(completeTestCommandArguments("--info ")).toEqual([ { value: "--tags", label: "--tags", description: "Run with Go build tags", }, { value: "--comment", label: "--comment", description: "Ask the model to analyze the test results", }, ]); }); it("suggests remaining flags after a tag value is complete", () => { expect(completeTestCommandArguments("--tags contract,e2e ")).toEqual([ { value: "--info", label: "--info", description: "Show full command output", }, { value: "--comment", label: "--comment", description: "Ask the model to analyze the test results", }, ]); }); it("filters remaining flags after a tag value is complete", () => { expect(completeTestCommandArguments("--tags contract,e2e --")).toEqual([ { value: "--info", label: "--info", description: "Show full command output", }, { value: "--comment", label: "--comment", description: "Ask the model to analyze the test results", }, ]); }); it("suggests the only remaining flag when the others are present", () => { expect(completeTestCommandArguments("--info --tags contract,e2e ")).toEqual( [ { value: "--comment", label: "--comment", description: "Ask the model to analyze the test results", }, ], ); }); it("does not suggest flags that are already present", () => { expect( completeTestCommandArguments("--info --tags --comment contract,e2e "), ).toBeNull(); }); it("does not suggest --comment when already present", () => { expect(completeTestCommandArguments("--comment ")).toEqual([ { value: "--info", label: "--info", description: "Show full command output", }, { value: "--tags", label: "--tags", description: "Run with Go build tags", }, ]); expect(completeTestCommandArguments("--comment --info ")).toEqual([ { value: "--tags", label: "--tags", description: "Run with Go build tags", }, ]); }); it("returns no suggestions when completing a tag value", () => { expect(completeTestCommandArguments("--tags contract")).toBeNull(); }); }); describe("testCommandTailBeforeCursor", () => { it("detects a bare /test as an empty args context", () => { expect(testCommandTailBeforeCursor("/test", 5)).toBe(""); }); it("detects a /test with trailing space as an empty args context", () => { expect(testCommandTailBeforeCursor("/test ", 6)).toBe(""); }); it("returns the full args tail after /test ", () => { expect(testCommandTailBeforeCursor("/test --info", 12)).toBe("--info"); }); it("derives the args context from the text before the cursor", () => { expect(testCommandTailBeforeCursor("/test --info", 7)).toBe("-"); }); it("returns an empty tail at the boundary right after /test ", () => { expect(testCommandTailBeforeCursor("/test --info", 6)).toBe(""); }); it("keeps the trailing space in the args tail", () => { expect(testCommandTailBeforeCursor("/test --tags contract,e2e ", 27)).toBe( "--tags contract,e2e ", ); }); it("does not treat an incomplete command as an args context", () => { expect(testCommandTailBeforeCursor("/te", 3)).toBeUndefined(); }); it("does not treat other slash words as an args context", () => { expect(testCommandTailBeforeCursor("/testx", 6)).toBeUndefined(); expect(testCommandTailBeforeCursor("/testx ", 7)).toBeUndefined(); }); }); describe("currentCompletionToken", () => { it("returns an empty prefix for an empty args tail", () => { expect(currentCompletionToken("")).toBe(""); }); it("returns an empty prefix for whitespace-only tails", () => { expect(currentCompletionToken(" ")).toBe(""); }); it("returns an empty prefix after a trailing space", () => { expect(currentCompletionToken("--info ")).toBe(""); expect(currentCompletionToken("--tags contract,e2e ")).toBe(""); }); it("returns the current token being typed", () => { expect(currentCompletionToken("--info")).toBe("--info"); expect(currentCompletionToken("--tags contract,e2e --")).toBe("--"); }); it("returns the last complete token", () => { expect(currentCompletionToken("--info --tags")).toBe("--tags"); }); });