import { describe, expect, it } from "vitest"; import { ARITY, prefix } from "../src/bash-arity"; describe("ARITY dictionary", () => { it("is exported as a plain object", () => { expect(typeof ARITY).toBe("object"); }); it("maps 'git' to arity 2", () => { expect(ARITY["git"]).toBe(2); }); it("maps 'npm run' to arity 3", () => { expect(ARITY["npm run"]).toBe(3); }); it("maps 'npm' to arity 2 (fallback when 'npm run' does not match)", () => { expect(ARITY["npm"]).toBe(2); }); it("maps 'docker compose' to arity 3", () => { expect(ARITY["docker compose"]).toBe(3); }); it("maps 'docker' to arity 2 (fallback)", () => { expect(ARITY["docker"]).toBe(2); }); }); describe("prefix", () => { it("returns empty array for empty input", () => { expect(prefix([])).toEqual([]); }); it("returns single-element array for a bare known command", () => { // 'git' alone has arity 2 but only 1 token is available — clamp. expect(prefix(["git"])).toEqual(["git"]); }); it("returns arity-2 prefix for git subcommands", () => { expect(prefix(["git", "checkout", "main"])).toEqual(["git", "checkout"]); }); it("returns arity-2 prefix for git status with flags", () => { expect(prefix(["git", "status", "--short"])).toEqual(["git", "status"]); }); it("returns arity-3 prefix for npm run (longest match wins over npm arity-2)", () => { expect(prefix(["npm", "run", "dev"])).toEqual(["npm", "run", "dev"]); }); it("returns arity-2 prefix for npm install (npm fallback, npm run does not match)", () => { expect(prefix(["npm", "install", "lodash"])).toEqual(["npm", "install"]); }); it("returns arity-3 prefix for docker compose subcommands", () => { expect(prefix(["docker", "compose", "up", "--build"])).toEqual([ "docker", "compose", "up", ]); }); it("returns arity-2 prefix for docker pull (docker fallback)", () => { expect(prefix(["docker", "pull", "ubuntu"])).toEqual(["docker", "pull"]); }); it("returns arity-1 prefix for unknown commands", () => { expect(prefix(["unknown-tool", "--flag"])).toEqual(["unknown-tool"]); }); it("returns arity-1 prefix for rm (args are targets, not subcommands)", () => { expect(prefix(["rm", "-rf", "node_modules"])).toEqual(["rm"]); }); it("returns arity-1 prefix for cat", () => { expect(prefix(["cat", "file.txt"])).toEqual(["cat"]); }); it("is case-insensitive: 'Git' looks up as 'git'", () => { // Tokens are preserved as-is; only the lookup key is lowercased. expect(prefix(["Git", "checkout", "main"])).toEqual(["Git", "checkout"]); }); it("clamps arity to available token count when command is shorter than arity", () => { // npm run has arity 3; only ["npm", "run"] provided → return both. expect(prefix(["npm", "run"])).toEqual(["npm", "run"]); }); it("returns arity-2 prefix for pnpm run (longest match wins over pnpm)", () => { // pnpm run