parser test suite done, all green
This commit is contained in:
@@ -0,0 +1,70 @@
|
|||||||
|
import { parseCommand } from "@core/util/parser";
|
||||||
|
import { describe, expect, test } from "vitest";
|
||||||
|
|
||||||
|
describe("parseCommand", () => {
|
||||||
|
test("returns an empty ParsedCommand object", () => {
|
||||||
|
expect(parseCommand("")).toEqual({ command: "", flags: [], args: [] });
|
||||||
|
});
|
||||||
|
test("returns an empty ParsedCommand object", () => {
|
||||||
|
expect(parseCommand("")).toEqual({ command: "", flags: [], args: [] });
|
||||||
|
});
|
||||||
|
test("returns an empty ParsedCommand object", () => {
|
||||||
|
expect(parseCommand("")).toEqual({ command: "", flags: [], args: [] });
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns a parsed ls command without any args", () => {
|
||||||
|
expect(parseCommand("ls")).toEqual({ command: "ls", flags: [], args: [] });
|
||||||
|
});
|
||||||
|
test("returns a parsed ls command with arg /tmp", () => {
|
||||||
|
expect(parseCommand("ls /tmp")).toEqual({ command: "ls", flags: [], args: ["/tmp"] });
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns a parsed ls command with flags l and no args", () => {
|
||||||
|
expect(parseCommand("ls -l")).toEqual({ command: "ls", flags: ["l"], args: [] });
|
||||||
|
});
|
||||||
|
test("returns a parsed command with flags l,a and no args", () => {
|
||||||
|
expect(parseCommand("ls -la")).toEqual({ command: "ls", flags: ["l", "a"], args: [] });
|
||||||
|
});
|
||||||
|
test("returns a parsed command with flags l,a and no args", () => {
|
||||||
|
expect(parseCommand("ls -l -a")).toEqual({ command: "ls", flags: ["l", "a"], args: [] });
|
||||||
|
});
|
||||||
|
test("returns a parsed command with flags l,a and a /tmp arg", () => {
|
||||||
|
expect(parseCommand("ls -la /tmp")).toEqual({ command: "ls", flags: ["l", "a"], args: ["/tmp"] });
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns a parsed grep command with a valued color flag", () => {
|
||||||
|
expect(parseCommand("grep --color=auto")).toEqual({ command: "grep", flags: ["color=auto"], args: [] });
|
||||||
|
});
|
||||||
|
test("returns a parsed grep command with a valued color and r flags", () => {
|
||||||
|
expect(parseCommand("grep --color=auto -r")).toEqual({
|
||||||
|
command: "grep",
|
||||||
|
flags: ["color=auto", "r"],
|
||||||
|
args: [],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns a parsed echo command with a --version arg", () => {
|
||||||
|
expect(parseCommand("echo -- --version")).toEqual({ command: "echo", flags: [], args: ["--version"] });
|
||||||
|
});
|
||||||
|
test("returns a parsed echo command with a -f arg", () => {
|
||||||
|
expect(parseCommand("echo -- -f")).toEqual({ command: "echo", flags: [], args: ["-f"] });
|
||||||
|
});
|
||||||
|
test("returns a parsed echo command without any args", () => {
|
||||||
|
expect(parseCommand("echo --")).toEqual({ command: "echo", flags: [], args: [] });
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns a parsed ls command with flags l,a and a --tmp arg", () => {
|
||||||
|
expect(parseCommand("ls -la -- --tmp")).toEqual({ command: "ls", flags: ["l", "a"], args: ["--tmp"] });
|
||||||
|
});
|
||||||
|
test("returns a parsed rm command with flags r,f,no-preserve-root and a / arg", () => {
|
||||||
|
expect(parseCommand("rm -rf --no-preserve-root /")).toEqual({
|
||||||
|
command: "rm",
|
||||||
|
flags: ["r", "f", "no-preserve-root"],
|
||||||
|
args: ["/"],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("throws an UnclosedQuote error", () => {
|
||||||
|
expect(() => parseCommand('echo "hello')).toThrow(expect.objectContaining({ type: "UnclosedQuote" }));
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user