-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathhelp.longestCommandTermLength.test.js
52 lines (46 loc) · 1.97 KB
/
help.longestCommandTermLength.test.js
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
const commander = require('../');
// These are tests of the Help class, not of the Command help.
// There is some overlap with the higher level Command tests (which predate Help).
describe('longestSubcommandTermLength', () => {
test('when no commands then returns zero', () => {
const program = new commander.Command();
const helper = new commander.Help();
expect(helper.longestSubcommandTermLength(program, helper)).toEqual(0);
});
test('when command and no help then returns length of term', () => {
const sub = new commander.Command('sub');
const program = new commander.Command();
program
.addHelpCommand(false)
.addCommand(sub);
const helper = new commander.Help();
expect(helper.longestSubcommandTermLength(program, helper)).toEqual(helper.subcommandTerm(sub).length);
});
test('when command with arg and no help then returns length of term', () => {
const sub = new commander.Command('sub <file)');
const program = new commander.Command();
program
.addHelpCommand(false)
.addCommand(sub);
const helper = new commander.Help();
expect(helper.longestSubcommandTermLength(program, helper)).toEqual(helper.subcommandTerm(sub).length);
});
test('when multiple commands then returns longest length', () => {
const longestCommandName = 'alphabet-soup <longer_than_help>';
const program = new commander.Command();
program
.addHelpCommand(false)
.command('before', 'desc')
.command(longestCommandName, 'desc')
.command('after', 'desc');
const helper = new commander.Help();
expect(helper.longestSubcommandTermLength(program, helper)).toEqual(longestCommandName.length);
});
test('when just help command then returns length of help term', () => {
const program = new commander.Command();
program
.addHelpCommand(true);
const helper = new commander.Help();
expect(helper.longestSubcommandTermLength(program, helper)).toEqual('help [command]'.length);
});
});