Skip to content

Commit

Permalink
Add test for bad command groups
Browse files Browse the repository at this point in the history
  • Loading branch information
dyedgreen committed Dec 26, 2021
1 parent 65b8201 commit efe9d2b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/group_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Command } from "./command.ts";
import { CommandGroup } from "./group.ts";
import { string } from "./types.ts";
import { assertEquals } from "https://deno.land/std@0.118.0/testing/asserts.ts";
import {
assertEquals,
assertThrows,
} from "https://deno.land/std@0.118.0/testing/asserts.ts";

const cmd = new Command("Test child.").required(string, "test");

Expand All @@ -17,6 +20,18 @@ Deno.test("basic command groups", () => {
assertEquals(secondResult, { second: { test: "test" } });
});

Deno.test("basic command group errors", () => {
const group = new CommandGroup("A test group.")
.subcommand("first", cmd)
.subcommand("second", cmd);

assertThrows(() => group.parse(["bad-key", "test"]));
assertThrows(() => group.parse(["FIRST", "test"]));
assertThrows(() => group.parse(["Second", "test"]));
assertThrows(() => group.parse(["first", "test", "too many"]));
assertThrows(() => group.parse(["first"]));
});

Deno.test("command group help output", () => {
const innerGroup = new CommandGroup("Inner group.")
.subcommand("first", cmd)
Expand Down

0 comments on commit efe9d2b

Please sign in to comment.