help.longestCommandTermLength.test.js
This file
Path
tests/help.longestCommandTermLength.test.js
61 lines · 2.1 KiB · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162import * as commander from '../index.js';import { test, describe } from 'node:test';import assert from 'node:assert/strict';
// 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('Help.longestSubcommandTermLength()', () => { test('when no commands then returns zero', () => { const program = new commander.Command(); const helper = new commander.Help(); assert.equal(helper.longestSubcommandTermLength(program, helper), 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(); assert.equal( helper.longestSubcommandTermLength(program, helper), 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(); assert.equal( helper.longestSubcommandTermLength(program, helper), 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(); assert.equal( helper.longestSubcommandTermLength(program, helper), 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(); assert.equal( helper.longestSubcommandTermLength(program, helper), 'help [command]'.length, ); });});