-
Notifications
You must be signed in to change notification settings - Fork 8
/
command.test.ts
82 lines (67 loc) · 2.15 KB
/
command.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { assertEquals, test } from "../deps.ts";
import Command from "../src/Command.ts";
test("command_word_command", function () {
const command = new Command({
value: "new [name]",
description: "Create a new file",
});
assertEquals(command.word_command, "new");
});
test("command_option", function () {
const command = new Command({
value: "new [name]",
description: "Create a new file",
});
command.addOption({
flags: "-p --port",
description: "Description goes here",
});
assertEquals(command.hasOptions(), true);
assertEquals(command.options[0].word_option, "help");
assertEquals(command.options[1].word_option, "port");
assertEquals(command.options[1].isRequired, false);
});
test("command_required_option", function () {
const command = new Command({
value: "new [name]",
description: "Create a new file",
});
command.addOption({
flags: "-p --port",
description: "Description goes here",
isRequired: true,
});
assertEquals(command.hasOptions(), true);
assertEquals(command.options[0].word_option, "help");
assertEquals(command.options[1].word_option, "port");
assertEquals(command.options[1].isRequired, true);
});
test("command_alias", function () {
const command = new Command({
value: "new [name]",
description: "Create a new file",
});
command.addAlias("alias1");
command.addAlias("alias2");
assertEquals(command.hasAlias(), true);
assertEquals(command.aliases, ["alias1", "alias2"]);
});
test("default_command", function () {
const command = new Command({
value: "[msg]",
description: "Print a message",
isDefault: true,
});
assertEquals(command.isDefault, true);
assertEquals(command.word_command, "[msg]"); // Command name is still the first parameter
});
test("sub_commands", function () {
const parent_command = new Command({ value: "parent" });
const sub_command = new Command({
value: "child",
subCommand: { parent: parent_command },
});
assertEquals(parent_command.hasSubCommands(), true);
assertEquals(parent_command.subCommands.includes(sub_command), true);
assertEquals(sub_command.parentCommand, parent_command);
});