|
1 | 1 | import { test, expect } from "bun:test" |
2 | | -import { ShellArity } from "../../src/tool/shell/arity" |
| 2 | +import { BashArity } from "../../src/permission/arity" |
3 | 3 |
|
4 | 4 | test("arity 1 - unknown commands default to first token", () => { |
5 | | - expect(ShellArity.prefix(["unknown", "command", "subcommand"], "bash")).toEqual(["unknown"]) |
6 | | - expect(ShellArity.prefix(["touch", "foo.txt"], "bash")).toEqual(["touch"]) |
| 5 | + expect(BashArity.prefix(["unknown", "command", "subcommand"])).toEqual(["unknown"]) |
| 6 | + expect(BashArity.prefix(["touch", "foo.txt"])).toEqual(["touch"]) |
7 | 7 | }) |
8 | 8 |
|
9 | 9 | test("arity 2 - two token commands", () => { |
10 | | - expect(ShellArity.prefix(["git", "checkout", "main"], "bash")).toEqual(["git", "checkout"]) |
11 | | - expect(ShellArity.prefix(["docker", "run", "nginx"], "bash")).toEqual(["docker", "run"]) |
| 10 | + expect(BashArity.prefix(["git", "checkout", "main"])).toEqual(["git", "checkout"]) |
| 11 | + expect(BashArity.prefix(["docker", "run", "nginx"])).toEqual(["docker", "run"]) |
12 | 12 | }) |
13 | 13 |
|
14 | 14 | test("arity 3 - three token commands", () => { |
15 | | - expect(ShellArity.prefix(["aws", "s3", "ls", "my-bucket"], "bash")).toEqual(["aws", "s3", "ls"]) |
16 | | - expect(ShellArity.prefix(["npm", "run", "dev", "script"], "bash")).toEqual(["npm", "run", "dev"]) |
| 15 | + expect(BashArity.prefix(["aws", "s3", "ls", "my-bucket"])).toEqual(["aws", "s3", "ls"]) |
| 16 | + expect(BashArity.prefix(["npm", "run", "dev", "script"])).toEqual(["npm", "run", "dev"]) |
17 | 17 | }) |
18 | 18 |
|
19 | 19 | test("longest match wins - nested prefixes", () => { |
20 | | - expect(ShellArity.prefix(["docker", "compose", "up", "service"], "bash")).toEqual(["docker", "compose", "up"]) |
21 | | - expect(ShellArity.prefix(["consul", "kv", "get", "config"], "bash")).toEqual(["consul", "kv", "get"]) |
| 20 | + expect(BashArity.prefix(["docker", "compose", "up", "service"])).toEqual(["docker", "compose", "up"]) |
| 21 | + expect(BashArity.prefix(["consul", "kv", "get", "config"])).toEqual(["consul", "kv", "get"]) |
22 | 22 | }) |
23 | 23 |
|
24 | 24 | test("exact length matches", () => { |
25 | | - expect(ShellArity.prefix(["git", "checkout"], "bash")).toEqual(["git", "checkout"]) |
26 | | - expect(ShellArity.prefix(["npm", "run", "dev"], "bash")).toEqual(["npm", "run", "dev"]) |
| 25 | + expect(BashArity.prefix(["git", "checkout"])).toEqual(["git", "checkout"]) |
| 26 | + expect(BashArity.prefix(["npm", "run", "dev"])).toEqual(["npm", "run", "dev"]) |
27 | 27 | }) |
28 | 28 |
|
29 | 29 | test("edge cases", () => { |
30 | | - expect(ShellArity.prefix([], "bash")).toEqual([]) |
31 | | - expect(ShellArity.prefix(["single"], "bash")).toEqual(["single"]) |
32 | | - expect(ShellArity.prefix(["git"], "bash")).toEqual(["git"]) |
33 | | -}) |
34 | | - |
35 | | -test("powershell verb-noun structures", () => { |
36 | | - expect(ShellArity.prefix(["Get-Content", "file.txt"], "pwsh")).toEqual(["Get-Content"]) |
37 | | - expect(ShellArity.prefix(["Remove-Item", "-Recurse", "dir"], "powershell")).toEqual(["Remove-Item"]) |
38 | | - expect(ShellArity.prefix(["git", "checkout", "main"], "pwsh")).toEqual(["git", "checkout"]) |
39 | | - expect(ShellArity.prefix(["redis-cli", "ping"], "pwsh")).toEqual(["redis-cli", "ping"]) |
| 30 | + expect(BashArity.prefix([])).toEqual([]) |
| 31 | + expect(BashArity.prefix(["single"])).toEqual(["single"]) |
| 32 | + expect(BashArity.prefix(["git"])).toEqual(["git"]) |
40 | 33 | }) |
0 commit comments