options.default.test.js
This file
Path
tests/options.default.test.js
195 lines · 8.1 KiB · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake it
The walk stopped after 200 commits: lines older than 471ec40 point at it.
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
lines 1–3why, one step back1import { Command, Option } from '../index.js';2import { test, describe } from 'node:test';3import assert from 'node:assert/strict';Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 4why, one step back4Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 5why, one step back5describe('Command.option() with default value and option not specified in parse', () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 6–9why, one step back6 test('when boolean option with boolean default then value is default', () => {7 const program = new Command();8 program.option('-d, --debug', 'description', false);9 program.parse([], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 10why, one step back10 assert.equal(program.opts().debug, false);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 11–16why, one step back11 });1213 test('when boolean option with number zero default then value is zero', () => {14 const program = new Command();15 program.option('-d, --debug', 'description', 0);16 program.parse([], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 17why, one step back17 assert.equal(program.opts().debug, 0);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 18–23why, one step back18 });1920 test('when boolean option with string default then value is default', () => {21 const program = new Command();22 program.option('-d, --debug', 'description', 'default');23 program.parse([], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 24why, one step back24 assert.equal(program.opts().debug, 'default');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 25–30why, one step back25 });2627 test('when required option-argument and default number then value is default', () => {28 const program = new Command();29 program.option('-p, --port <port-number>', 'description', 80);30 program.parse([], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 31why, one step back31 assert.equal(program.opts().port, 80);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 32–37why, one step back32 });3334 test('when required option-argument and default string then value is default', () => {35 const program = new Command();36 program.option('-p, --port <port-number>', 'description', 'foo');37 program.parse([], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 38why, one step back38 assert.equal(program.opts().port, 'foo');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 39–44why, one step back39 });4041 test('when optional option-argument and default number then value is default', () => {42 const program = new Command();43 program.option('-p, --port [port-number]', 'description', 80);44 program.parse([], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 45why, one step back45 assert.equal(program.opts().port, 80);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 46–51why, one step back46 });4748 test('when optional option-argument and default string then value is default', () => {49 const program = new Command();50 program.option('-p, --port [port-number]', 'description', 'foo');51 program.parse([], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 52why, one step back52 assert.equal(program.opts().port, 'foo');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 53–59why, one step back53 });5455 test('when negated and default string then value is default', () => {56 // Bit tricky thinking about what default means for a negated option, but treat as with other options.57 const program = new Command();58 program.option('--no-colour', 'description', 'RGB');59 program.parse([], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 60why, one step back60 assert.equal(program.opts().colour, 'RGB');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 61–63why, one step back61 });62});63Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 64why, one step back64describe('Option with default value and option not specified in parse', () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 65–68why, one step back65 test('when boolean option with boolean default then value is default', () => {66 const program = new Command();67 program.addOption(new Option('-d, --debug').default(false));68 program.parse([], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 69why, one step back69 assert.equal(program.opts().debug, false);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 70–75why, one step back70 });7172 test('when boolean option with number zero default then value is zero', () => {73 const program = new Command();74 program.addOption(new Option('-d, --debug').default(0));75 program.parse([], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 76why, one step back76 assert.equal(program.opts().debug, 0);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 77–82why, one step back77 });7879 test('when boolean option with string default then value is default', () => {80 const program = new Command();81 program.addOption(new Option('-d, --debug').default('default'));82 program.parse([], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 83why, one step back83 assert.equal(program.opts().debug, 'default');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 84–89why, one step back84 });8586 test('when required option-argument and default number then value is default', () => {87 const program = new Command();88 program.addOption(new Option('-p, --port <port-number>').default(80));89 program.parse([], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 90why, one step back90 assert.equal(program.opts().port, 80);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 91–96why, one step back91 });9293 test('when required option-argument and default string then value is default', () => {94 const program = new Command();95 program.addOption(new Option('-p, --port <port-number>').default('foo'));96 program.parse([], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 97why, one step back97 assert.equal(program.opts().port, 'foo');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 98–103why, one step back98 });99100 test('when optional option-argument and default number then value is default', () => {101 const program = new Command();102 program.addOption(new Option('-p, --port [port-number]').default(80));103 program.parse([], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 104why, one step back104 assert.equal(program.opts().port, 80);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 105–110why, one step back105 });106107 test('when optional option-argument and default string then value is default', () => {108 const program = new Command();109 program.addOption(new Option('-p, --port [port-number]').default('foo'));110 program.parse([], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 111why, one step back111 assert.equal(program.opts().port, 'foo');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 112–118why, one step back112 });113114 test('when negated and default string then value is default', () => {115 // Bit tricky thinking about what default means for a negated option, but treat as with other options.116 const program = new Command();117 program.addOption(new Option('--no-colour').default('RGB'));118 program.parse([], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 119why, one step back119 assert.equal(program.opts().colour, 'RGB');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 120–123why, one step back120 });121});122123// Fairly obvious this needs to happen, but was broken for optional in past!Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 124why, one step back124describe('option default value overwritten by option specified in parse', () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 125–128why, one step back125 test('when boolean option with boolean default then value is true', () => {126 const program = new Command();127 program.option('-d, --debug', 'description', false);128 program.parse(['-d'], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 129why, one step back129 assert.equal(program.opts().debug, true);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 130–135why, one step back130 });131132 test('when boolean option with number zero default then value is true', () => {133 const program = new Command();134 program.option('-d, --debug', 'description', 0);135 program.parse(['-d'], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 136why, one step back136 assert.equal(program.opts().debug, true);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 137–142why, one step back137 });138139 test('when boolean option with string default then value is true', () => {140 const program = new Command();141 program.option('-d, --debug', 'description', 'default');142 program.parse(['-d'], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 143why, one step back143 assert.equal(program.opts().debug, true);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 144–149why, one step back144 });145146 test('when required option-argument and default number then value is from args', () => {147 const program = new Command();148 program.option('-p, --port <port-number>', 'description', 80);149 program.parse(['-p', '1234'], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 150why, one step back150 assert.equal(program.opts().port, '1234');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 151–156why, one step back151 });152153 test('when required option-argument and default string then value is from args', () => {154 const program = new Command();155 program.option('-p, --port <port-number>', 'description', 'foo');156 program.parse(['-p', '1234'], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 157why, one step back157 assert.equal(program.opts().port, '1234');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 158–163why, one step back158 });159160 test('when optional option-argument and default number and option-argument specified then value is from args', () => {161 const program = new Command();162 program.option('-p, --port [port-number]', 'description', 80);163 program.parse(['-p', '1234'], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 164why, one step back164 assert.equal(program.opts().port, '1234');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 165–170why, one step back165 });166167 test('when optional option-argument and default string and option-argument specified then value is from args', () => {168 const program = new Command();169 program.option('-p, --port [port-number]', 'description', 'foo');170 program.parse(['-p', '1234'], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 171why, one step back171 assert.equal(program.opts().port, '1234');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 172–177why, one step back172 });173174 test('when optional option-argument and default number and option-argument not specified then value is true', () => {175 const program = new Command();176 program.option('-p, --port [port-number]', 'description', 80);177 program.parse(['-p'], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 178why, one step back178 assert.equal(program.opts().port, true);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 179–184why, one step back179 });180181 test('when optional option-argument and default string and option-argument not specified then value is true', () => {182 const program = new Command();183 program.option('-p, --port [port-number]', 'description', 'foo');184 program.parse(['-p'], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 185why, one step back185 assert.equal(program.opts().port, true);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 186–192why, one step back186 });187188 test('when negated and default string then value is false', () => {189 // Bit tricky thinking about what default means for a negated option, but treat as with other options.190 const program = new Command();191 program.option('--no-colour', 'description', 'RGB');192 program.parse(['--no-colour'], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 193why, one step back193 assert.equal(program.opts().colour, false);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 194–195why, one step back194 });195});