/
help.padWidth.test.js
55 lines (50 loc) · 1.87 KB
/
help.padWidth.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
53
54
55
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('padWidth', () => {
test('when argument term longest return argument length', () => {
const longestThing = 'veryLongThingBiggerThanOthers';
const program = new commander.Command();
program
.argument(`<${longestThing}>`, 'description')
.option('-o');
program
.command('sub');
const helper = new commander.Help();
expect(helper.padWidth(program, helper)).toEqual(longestThing.length);
});
test('when option term longest return option length', () => {
const longestThing = '--very-long-thing-bigger-than-others';
const program = new commander.Command();
program
.argument('<file>', 'desc')
.option(longestThing);
program
.command('sub');
const helper = new commander.Help();
expect(helper.padWidth(program, helper)).toEqual(longestThing.length);
});
test('when global option term longest return global option length', () => {
const longestThing = '--very-long-thing-bigger-than-others';
const program = new commander.Command();
program
.argument('<file>', 'desc')
.option(longestThing)
.configureHelp({ showGlobalOptions: true });
const sub = program
.command('sub');
const helper = sub.createHelp();
expect(helper.padWidth(sub, helper)).toEqual(longestThing.length);
});
test('when command term longest return command length', () => {
const longestThing = 'very-long-thing-bigger-than-others';
const program = new commander.Command();
program
.argument('<file>', 'desc')
.option('-o');
program
.command(longestThing);
const helper = new commander.Help();
expect(helper.padWidth(program, helper)).toEqual(longestThing.length);
});
});