Skip to content
Myr

options.dual-options.test.js

This file

Path

tests/options.dual-options.test.js

99 lines · 3.8 KiB · JavaScript

Last changed by

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

History of this file

Take it

The walk stopped after 200 commits: lines older than 471ec40 point at it.

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

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

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 5–7why, one step back
5
6// This tests an internal helper class which is not currently exposed on the package.7

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

lines 8–16why, one step back
8describe('DualOptions internal helper class', () => {
9 test('when positive option then stored in positiveOptions', () => {10 const program = new Command();11 program.option('--one');12 const helper = new DualOptions(program.options);13 assert.equal(helper.positiveOptions.size, 1);14 assert.equal(helper.negativeOptions.size, 0);15 assert.equal(helper.dualOptions.size, 0);16 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 17why, one step back
17

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

lines 18–25why, one step back
18 test('when negative option then stored in negativeOptions', () => {
19 const program = new Command();20 program.option('--no-one');21 const helper = new DualOptions(program.options);22 assert.equal(helper.positiveOptions.size, 0);23 assert.equal(helper.negativeOptions.size, 1);24 assert.equal(helper.dualOptions.size, 0);25 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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 unrelated positive and negative options then no dual options', () => {
28 const program = new Command();29 program.option('--one').option('--no-two');30 const helper = new DualOptions(program.options);31 assert.equal(helper.dualOptions.size, 0);32 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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 related positive and negative options then stored as dual option', () => {
35 const program = new Command();36 program.option('--one').option('--no-one');37 const helper = new DualOptions(program.options);38 assert.equal(helper.dualOptions.size, 1);39 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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 related negative and positive options then stored as dual option', () => {
42 const program = new Command();43 program.option('--no-one').option('--one');44 const helper = new DualOptions(program.options);45 assert.equal(helper.dualOptions.size, 1);46 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 47why, one step back
47

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

lines 48–51why, one step back
48 describe('valueFromOption with boolean option', () => {
49 const positiveOption = new Option('--one');50 const negativeOption = new Option('--no-one');51 const options = [positiveOption, negativeOption];

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 52why, one step back
52

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

lines 53–56why, one step back
53 test('when negativeOption with false then return true', () => {
54 const helper = new DualOptions(options);55 assert.equal(helper.valueFromOption(false, negativeOption), true);56 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 57why, one step back
57

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

lines 58–61why, one step back
58 test('when negativeOption with true then return false', () => {
59 const helper = new DualOptions(options);60 assert.equal(helper.valueFromOption(true, negativeOption), false);61 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 62why, one step back
62

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

lines 63–66why, one step back
63 test('when positiveOption with false then return false', () => {
64 const helper = new DualOptions(options);65 assert.equal(helper.valueFromOption(false, positiveOption), false);66 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 67why, one step back
67

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

lines 68–71why, one step back
68 test('when positiveOption with true then return true', () => {
69 const helper = new DualOptions(options);70 assert.equal(helper.valueFromOption(true, positiveOption), true);71 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 72–73why, one step back
72 });
73

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

lines 74–77why, one step back
74 describe('valueFromOption with option expecting value and negative with preset', () => {
75 const positiveOption = new Option('--one <value>');76 const negativeOption = new Option('--no-one').preset('FALSE');77 const options = [positiveOption, negativeOption];

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 78why, one step back
78

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

lines 79–82why, one step back
79 test('when negativeOption with FALSE then return true', () => {
80 const helper = new DualOptions(options);81 assert.equal(helper.valueFromOption('FALSE', negativeOption), true);82 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 83why, one step back
83

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

lines 84–87why, one step back
84 test('when negativeOption with string then return false', () => {
85 const helper = new DualOptions(options);86 assert.equal(helper.valueFromOption('foo', negativeOption), false);87 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 88why, one step back
88

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

lines 89–92why, one step back
89 test('when positiveOption with FALSE then return false', () => {
90 const helper = new DualOptions(options);91 assert.equal(helper.valueFromOption('FALSE', positiveOption), false);92 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 93why, one step back
93

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

lines 94–97why, one step back
94 test('when positiveOption with true then return true', () => {
95 const helper = new DualOptions(options);96 assert.equal(helper.valueFromOption('foo', positiveOption), true);97 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 98–99why, one step back
98 });
99});