Skip to content
Myr

help.boxWrap.test.js

This file

Path

tests/help.boxWrap.test.js

122 lines · 4.3 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 * as commander 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

lines 5–11why, one step back
5describe('Help.boxWrap()', () => {
6 test('when empty string then return empty string', () => {7 const helper = new commander.Help();8 const text = '';9 const wrapped = helper.boxWrap(text, 50);10 assert.equal(wrapped, text);11 });

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

line 12why, one step back
12

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

lines 13–18why, one step back
13 test('when string contains unix line breaks then return (unix) empty lines', () => {
14 const helper = new commander.Help();15 const text = '\n\n\n';16 const wrapped = helper.boxWrap(text, 50);17 assert.equal(wrapped, text);18 });

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

line 19why, one step back
19

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

lines 20–25why, one step back
20 test('when string contains Windows line breaks then return (unix)) empty lines', () => {
21 const helper = new commander.Help();22 const text = '\r\n\r\n\r\n';23 const wrapped = helper.boxWrap(text, 50);24 assert.equal(wrapped, '\n\n\n');25 });

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

line 26why, one step back
26

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

lines 27–32why, one step back
27 test('when string contains only whitespace then returns empty string (trim right)', () => {
28 const helper = new commander.Help();29 const text = ' \t ';30 const wrapped = helper.boxWrap(text, 50);31 assert.equal(wrapped, '');32 });

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

line 33why, one step back
33

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

lines 34–39why, one step back
34 test('when string contains leading whitespace then returns string with leading whitespace', () => {
35 const helper = new commander.Help();36 const text = ' abc';37 const wrapped = helper.boxWrap(text, 50);38 assert.equal(wrapped, ' abc');39 });

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

line 40why, one step back
40

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

lines 41–46why, one step back
41 test('when string contains intermediate whitespace then returns string with intermediate whitespace', () => {
42 const helper = new commander.Help();43 const text = '123 456';44 const wrapped = helper.boxWrap(text, 50);45 assert.equal(wrapped, '123 456');46 });

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

line 47why, one step back
47

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

lines 48–53why, one step back
48 test('when string contains trailing whitespace then returns string without trailing whitespace (trim right)', () => {
49 const helper = new commander.Help();50 const text = '123 456 ';51 const wrapped = helper.boxWrap(text, 50);52 assert.equal(wrapped, '123 456');53 });

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

line 54why, one step back
54

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

lines 55–60why, one step back
55 test('when string contains escape sequences then returns string with escape sequences', () => {
56 const helper = new commander.Help();57 const text = '123 456 ';58 const wrapped = helper.boxWrap(text, 50);59 assert.equal(wrapped, '123 456');60 });

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

line 61why, one step back
61

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

lines 62–70why, one step back
62 test('when string has enough words to wrap then returns two wrapped lines', () => {
63 const helper = new commander.Help();64 const text = '123 567 901 345 789 123 567 901 345 789 123 567 901';65 const wrapped = helper.boxWrap(text, 45);66 assert.equal(67 wrapped,68 '123 567 901 345 789 123 567 901 345 789 123\n567 901',69 );70 });

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

line 71why, one step back
71

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

lines 72–80why, one step back
72 test('when string has enough words and escape sequences to wrap then returns wrapped line with break ignoring escape sequences', () => {
73 const helper = new commander.Help();74 const CSI = '\u001b[';75 const underlinedText = `${CSI}4mXYZ${CSI}24m`;76 const text = `${underlinedText}${' ABC'.repeat(19)}`;77 const wrapped = helper.boxWrap(text, 44);78 assert.equal(79 wrapped,80 `${underlinedText} ${'ABC '.repeat(9)}ABC

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

line 81why, one step back
81${'ABC '.repeat(8)}ABC`,

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

lines 82–83why, one step back
82 );
83 });

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

line 84why, one step back
84

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

lines 85–90why, one step back
85 test('when first word longer than width then soft wrap', () => {
86 const helper = new commander.Help();87 const text = 'abc'.repeat(20);88 const wrapped = helper.boxWrap(text, 40);89 assert.equal(wrapped, text);90 });

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

line 91why, one step back
91

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

lines 92–97why, one step back
92 test('when second word longer than width then wrap and soft wrap', () => {
93 const helper = new commander.Help();94 const text = 'xyz ' + 'abc'.repeat(20);95 const wrapped = helper.boxWrap(text, 40);96 assert.equal(wrapped, `xyz\n${'abc'.repeat(20)}`);97 });

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

line 98why, one step back
98

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

lines 99–106why, one step back
99 test('when set width 41 then wrap at 41', () => {
100 const helper = new commander.Help();101 const text = 'X'.repeat(39) + ' 1 2 3';102 let wrapped = helper.boxWrap(text, 40);103 assert.equal(wrapped, 'X'.repeat(39) + '\n1 2 3');104 wrapped = helper.boxWrap(text, 41);105 assert.equal(wrapped, 'X'.repeat(39) + ' 1\n2 3');106 });

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

line 107why, one step back
107

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

lines 108–113why, one step back
108 test('when set width 12 (too small) then skip wrap', () => {
109 const helper = new commander.Help();110 const text = ' x'.repeat(8) + ' yy'.repeat(6);111 let wrapped = helper.boxWrap(text, 14);112 assert.equal(wrapped, text);113 });

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

line 114why, one step back
114

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

lines 115–121why, one step back
115 test('when set width 12 (and set minWrapWidth) then skip wrap', () => {
116 const helper = new commander.Help();117 helper.minWidthToWrap = 1;118 const text = ' x'.repeat(8) + ' yy'.repeat(6);119 let wrapped = helper.boxWrap(text, 14);120 assert.equal(wrapped, ' x x x x x x x\nx yy yy yy yy\nyy yy');121 });

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

line 122why, one step back
122});