Skip to content
Myr

help.preformatted.test.js

This file

Path

tests/help.preformatted.test.js

72 lines · 2.1 KiB · JavaScript

Last changed by

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

History of this file

Take it

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

lines 1–3why, one step back
1import { Help, Command } from '../index.js';
2import { test, describe } from 'node:test';3import assert from 'node:assert/strict';

Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947

line 4why, one step back
4

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

line 5why, one step back
5describe('Help.preformatted()', () => {

Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947

lines 6–7why, one step back
6 test('when single line then false', () => {
7 const helper = new Help();

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 8why, one step back
8 assert.equal(helper.preformatted('a b c'), false);

Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947

lines 9–12why, one step back
9 });
1011 test('when single line with leading whitespace then false', () => {12 const helper = new Help();

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 13why, one step back
13 assert.equal(helper.preformatted(' a b c'), false);

Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947

lines 14–17why, one step back
14 });
1516 test('when unix line break not followed by whitespace then false', () => {17 const helper = new Help();

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 18why, one step back
18 assert.equal(helper.preformatted('a\nb\nc'), false);

Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947

lines 19–22why, one step back
19 });
2021 test('when Windows line break not followed by whitespace then false', () => {22 const helper = new Help();

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 23why, one step back
23 assert.equal(helper.preformatted('a\r\nb\r\nc'), false);

Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947

lines 24–27why, one step back
24 });
2526 test('when unix line followed by whitespace then true', () => {27 const helper = new Help();

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 28why, one step back
28 assert.equal(helper.preformatted('a\n b'), true);

Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947

lines 29–32why, one step back
29 });
3031 test('when Windows line break followed by whitespace then true', () => {32 const helper = new Help();

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 33why, one step back
33 assert.equal(helper.preformatted('a\r\n b'), true);

Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947

lines 34–37why, one step back
34 });
3536 test('when empty unix lines then false', () => {37 const helper = new Help();

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 38why, one step back
38 assert.equal(helper.preformatted('a\n\n'), false);

Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947

lines 39–42why, one step back
39 });
4041 test('when empty Windows lines then false', () => {42 const helper = new Help();

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 43why, one step back
43 assert.equal(helper.preformatted('a\r\n\r\n'), false);

Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947

lines 44–70why, one step back
44 });
45});4647test('end-to-end: when option description is preformatted then manual format is preserved', () => {48 // #396: leave custom format alone, apart from space-space indent49 const optionSpec = '-t, --time <HH:MM>';50 const program = new Command();51 program.configureHelp({ helpWidth: 80 }).option(52 optionSpec,53 `select time5455Time can also be specified using special values:56 "dawn" - From night to sunrise.57`,58 );5960 const expectedOutput = `Usage: [options]6162Options:63 ${optionSpec} select time64 65 Time can also be specified using special values:66 "dawn" - From night to sunrise.67 68 -h, --help display help for command69`;70

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 71why, one step back
71 assert.equal(program.helpInformation(), expectedOutput);

Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947

line 72why, one step back
72});