options.bool.combo.test.js
This file
Path
tests/options.bool.combo.test.js
195 lines · 7.2 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 * as commander from '../index.js';2import { test, describe } from 'node:test';3import assert from 'node:assert/strict';Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 4–7why, one step back45// Test combination of flag and --no-flag6// (single flags tested in options.bool.test.js)7Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 8–17why, one step back8describe('boolean option combos (--foo and --no-foo)', () => {9 // boolean option combo with no default10 describe('positive option with no default', () => {11 function createPepperProgram() {12 const program = new commander.Command();13 program14 .option('-p, --pepper', 'add pepper')15 .option('-P, --no-pepper', 'remove pepper');16 return program;17 }Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 18why, one step back18Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 19–23why, one step back19 test('when option not specified then value is undefined', () => {20 const program = createPepperProgram();21 program.parse(['node', 'test']);22 assert.equal(program.opts().pepper, undefined);23 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 24why, one step back24Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 25–29why, one step back25 test('when positive option then value is true', () => {26 const program = createPepperProgram();27 program.parse(['node', 'test', '--pepper']);28 assert.equal(program.opts().pepper, true);29 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 30why, one step back30Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 31–35why, one step back31 test('when negative option then value is false', () => {32 const program = createPepperProgram();33 program.parse(['node', 'test', '--no-pepper']);34 assert.equal(program.opts().pepper, false);35 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 36why, one step back36Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 37–41why, one step back37 test('when last option is positive then value is true', () => {38 const program = createPepperProgram();39 program.parse(['node', 'test', '--no-pepper', '--pepper']);40 assert.equal(program.opts().pepper, true);41 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 42why, one step back42Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 43–47why, one step back43 test('when last option is negative then value is false', () => {44 const program = createPepperProgram();45 program.parse(['node', 'test', '--pepper', '--no-pepper']);46 assert.equal(program.opts().pepper, false);47 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 48–49why, one step back48 });49Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 50why, one step back50 // Flag with default, say from an environment variable.Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 51why, one step back51Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 52–58why, one step back52 function createPepperProgramWithDefault(defaultValue) {53 const program = new commander.Command();54 program55 .option('-p, --pepper', 'add pepper', defaultValue)56 .option('-P, --no-pepper', 'remove pepper');57 return program;58 }Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 59why, one step back59Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 60–66why, one step back60 // boolean option combo, default true, long flags61 describe('option with default of true, long flags', () => {62 test('when option not specified then value is true', () => {63 const program = createPepperProgramWithDefault(true);64 program.parse(['node', 'test']);65 assert.equal(program.opts().pepper, true);66 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 67why, one step back67Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 68–72why, one step back68 test('when positive option then value is true', () => {69 const program = createPepperProgramWithDefault(true);70 program.parse(['node', 'test', '--pepper']);71 assert.equal(program.opts().pepper, true);72 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 73why, one step back73Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 74–78why, one step back74 test('when negative option then value is false', () => {75 const program = createPepperProgramWithDefault(true);76 program.parse(['node', 'test', '--no-pepper']);77 assert.equal(program.opts().pepper, false);78 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 79–80why, one step back79 });80Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 81–87why, one step back81 // boolean option combo, default false, short flags82 describe('option with default of false, short flags', () => {83 test('when option not specified then value is false', () => {84 const program = createPepperProgramWithDefault(false);85 program.parse(['node', 'test']);86 assert.equal(program.opts().pepper, false);87 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 88why, one step back88Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 89–93why, one step back89 test('when positive option then value is true', () => {90 const program = createPepperProgramWithDefault(false);91 program.parse(['node', 'test', '-p']);92 assert.equal(program.opts().pepper, true);93 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 94why, one step back94Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 95–99why, one step back95 test('when negative option then value is false', () => {96 const program = createPepperProgramWithDefault(false);97 program.parse(['node', 'test', '-P']);98 assert.equal(program.opts().pepper, false);99 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 100–101why, one step back100 });101Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 102–109why, one step back102 // boolean option combo with non-boolean default.103 // Changed behaviour to normal default in Commander 9.104 describe('option with non-boolean default', () => {105 test('when option not specified then value is default', () => {106 const program = createPepperProgramWithDefault('default');107 program.parse(['node', 'test']);108 assert.equal(program.opts().pepper, 'default');109 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 110why, one step back110Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 111–115why, one step back111 test('when positive option then value is true', () => {112 const program = createPepperProgramWithDefault('default');113 program.parse(['node', 'test', '--pepper']);114 assert.equal(program.opts().pepper, true);115 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 116why, one step back116Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 117–121why, one step back117 test('when negative option then value is false', () => {118 const program = createPepperProgramWithDefault('default');119 program.parse(['node', 'test', '--no-pepper']);120 assert.equal(program.opts().pepper, false);121 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 122–123why, one step back122 });123Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 124–135why, one step back124 describe('option with non-boolean default and preset', () => {125 function createPepperProgramWithDefaultAndPreset() {126 const program = new commander.Command();127 program128 .addOption(129 new commander.Option('-p, --pepper')130 .default('default')131 .preset('preset'),132 )133 .option('-P, --no-pepper', 'remove pepper');134 return program;135 }Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 136why, one step back136Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 137–141why, one step back137 test('when option not specified then value is default', () => {138 const program = createPepperProgramWithDefaultAndPreset();139 program.parse(['node', 'test']);140 assert.equal(program.opts().pepper, 'default');141 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 142why, one step back142Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 143–147why, one step back143 test('when positive option then value is preset', () => {144 const program = createPepperProgramWithDefaultAndPreset();145 program.parse(['node', 'test', '--pepper']);146 assert.equal(program.opts().pepper, 'preset');147 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 148why, one step back148Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 149–153why, one step back149 test('when negative option then value is false', () => {150 const program = createPepperProgramWithDefaultAndPreset();151 program.parse(['node', 'test', '--no-pepper']);152 assert.equal(program.opts().pepper, false);153 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 154why, one step back154 });Make order not matter for adding combo positive/negative options (#2405)John Geebefore adoption63eed4a
line 155why, one step back155Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 156–162why, one step back156 describe('only lone negative causes implicit default of true', () => {157 test('when lone negative then default value is true', () => {158 const program = new commander.Command();159 program.option('--no-pepper', 'remove pepper');160 program.parse([], { from: 'user' });161 assert.equal(program.opts().pepper, true);162 });Make order not matter for adding combo positive/negative options (#2405)John Geebefore adoption63eed4a
line 163why, one step back163Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 164–172why, one step back164 test('when boolean combo and negative first then no implicit default', () => {165 // New behaviour in Commander 15, now only lone negative gets implicit default of true.166 const program = new commander.Command();167 program168 .option('--no-pepper', 'remove pepper')169 .option('--pepper', 'pepper only');170 program.parse([], { from: 'user' });171 assert.equal(program.opts().pepper, undefined);172 });Make order not matter for adding combo positive/negative options (#2405)John Geebefore adoption63eed4a
line 173why, one step back173Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 174–181why, one step back174 test('when boolean combo and negative second then no implicit default', () => {175 const program = new commander.Command();176 program177 .option('--pepper', 'pepper only')178 .option('--no-pepper', 'remove pepper');179 program.parse([], { from: 'user' });180 assert.equal(program.opts().pepper, undefined);181 });Make order not matter for adding combo positive/negative options (#2405)John Geebefore adoption63eed4a
line 182why, one step back182Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 183–193why, one step back183 test('when boolean combo and negative second with explicit default then get explicit default', () => {184 // Prior to Commander 15, negative second would ignore implicit and explicit default value.185 // Simpler rule now and the special default behaviour is for lone negative only. Add test since186 // intentional change of behaviour for unlikely edge case.187 const program = new commander.Command();188 program189 .option('--pepper', 'pepper only')190 .option('--no-pepper', 'remove pepper', 'plain');191 program.parse([], { from: 'user' });192 assert.equal(program.opts().pepper, 'plain');193 });Make order not matter for adding combo positive/negative options (#2405)John Geebefore adoption63eed4a
lines 194–195why, one step back194 });195});