-
Notifications
You must be signed in to change notification settings - Fork 8
/
utils.test.ts
78 lines (63 loc) · 1.95 KB
/
utils.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
import { assertEquals, test } from "../deps.ts";
import Command from "../src/Command.ts";
import {
arraysHaveMatchingCommand,
findCommandFromArgs,
} from "../src/utils/find.ts";
import { itContainsBrackets } from "../src/utils/detect.ts";
import {
removeCommandFromArray,
removeDashes,
trimString,
} from "../src/utils/remove.ts";
test("find_command_from_args", function () {
const commands: Array<Command> = [];
const arg = "--help";
commands.push(
new Command({
value: "-h --help",
description: "Print command line options (currently set)",
}),
);
const command = findCommandFromArgs(commands, arg);
if (command) {
assertEquals(command.word_command, "help");
}
});
test("remove_command_from_array", function () {
const cloneCommand = new Command({
value: "clone",
description: "Clone Command",
});
const pullCommand = new Command({
value: "pull",
description: "Pull Command",
});
const commands_before: Array<Command> = [cloneCommand, pullCommand];
const commands_after: Array<Command> = [cloneCommand];
assertEquals(removeCommandFromArray(commands_before, "pull"), commands_after);
});
test("arrays_have_matching_command", function () {
const helpCommand = new Command({
value: "-h --help",
description: "Helper of the app",
});
const versionCommand = new Command({
value: "-v --version",
description: "Version of the app",
});
const array1: Array<Command> = [versionCommand, helpCommand];
const array2: Array<Command> = [helpCommand];
assertEquals(arraysHaveMatchingCommand(helpCommand, array1, array2), true);
});
test("strip_dashes", function () {
assertEquals(removeDashes("--test"), "test");
});
test("contains_brackets", function () {
assertEquals(itContainsBrackets("new [name]"), true);
assertEquals(itContainsBrackets("start"), false);
});
test("trim_string", function () {
const value = " -- port ";
assertEquals(trimString(value), "--port");
});