1 | 'use strict'
|
2 | const TestRunner = require('test-runner')
|
3 | const commandLineArgs = require('../')
|
4 | const a = require('assert')
|
5 |
|
6 | const runner = new TestRunner()
|
7 |
|
8 | runner.test('groups', function () {
|
9 | const definitions = [
|
10 | { name: 'one', group: 'a' },
|
11 | { name: 'two', group: 'a' },
|
12 | { name: 'three', group: 'b' }
|
13 | ]
|
14 | const argv = [ '--one', '1', '--two', '2', '--three', '3' ]
|
15 | const output = commandLineArgs(definitions, { argv })
|
16 | a.deepStrictEqual(output, {
|
17 | a: {
|
18 | one: '1',
|
19 | two: '2'
|
20 | },
|
21 | b: {
|
22 | three: '3'
|
23 | },
|
24 | _all: {
|
25 | one: '1',
|
26 | two: '2',
|
27 | three: '3'
|
28 | }
|
29 | })
|
30 | })
|
31 |
|
32 | runner.test('groups: multiple and _none', function () {
|
33 | const definitions = [
|
34 | { name: 'one', group: ['a', 'f'] },
|
35 | { name: 'two', group: ['a', 'g'] },
|
36 | { name: 'three' }
|
37 | ]
|
38 |
|
39 | a.deepStrictEqual(commandLineArgs(definitions, { argv: [ '--one', '1', '--two', '2', '--three', '3' ] }), {
|
40 | a: {
|
41 | one: '1',
|
42 | two: '2'
|
43 | },
|
44 | f: {
|
45 | one: '1'
|
46 | },
|
47 | g: {
|
48 | two: '2'
|
49 | },
|
50 | _none: {
|
51 | three: '3'
|
52 | },
|
53 | _all: {
|
54 | one: '1',
|
55 | two: '2',
|
56 | three: '3'
|
57 | }
|
58 | })
|
59 | })
|
60 |
|
61 | runner.test('groups: nothing set', function () {
|
62 | const definitions = [
|
63 | { name: 'one', group: 'a' },
|
64 | { name: 'two', group: 'a' },
|
65 | { name: 'three', group: 'b' }
|
66 | ]
|
67 | const argv = [ ]
|
68 | const output = commandLineArgs(definitions, { argv })
|
69 | a.deepStrictEqual(output, {
|
70 | a: {},
|
71 | b: {},
|
72 | _all: {}
|
73 | })
|
74 | })
|
75 |
|
76 | runner.test('groups: nothing set with one ungrouped', function () {
|
77 | const definitions = [
|
78 | { name: 'one', group: 'a' },
|
79 | { name: 'two', group: 'a' },
|
80 | { name: 'three' }
|
81 | ]
|
82 | const argv = [ ]
|
83 | const output = commandLineArgs(definitions, { argv })
|
84 | a.deepStrictEqual(output, {
|
85 | a: {},
|
86 | _all: {}
|
87 | })
|
88 | })
|
89 |
|
90 | runner.test('groups: two ungrouped, one set', function () {
|
91 | const definitions = [
|
92 | { name: 'one', group: 'a' },
|
93 | { name: 'two', group: 'a' },
|
94 | { name: 'three' },
|
95 | { name: 'four' }
|
96 | ]
|
97 | const argv = [ '--three', '3' ]
|
98 | const output = commandLineArgs(definitions, { argv })
|
99 | a.deepStrictEqual(output, {
|
100 | a: {},
|
101 | _all: { three: '3' },
|
102 | _none: { three: '3' }
|
103 | })
|
104 | })
|
105 |
|
106 | runner.test('groups: two ungrouped, both set', function () {
|
107 | const definitions = [
|
108 | { name: 'one', group: 'a' },
|
109 | { name: 'two', group: 'a' },
|
110 | { name: 'three' },
|
111 | { name: 'four' }
|
112 | ]
|
113 | const argv = [ '--three', '3', '--four', '4' ]
|
114 | const output = commandLineArgs(definitions, { argv })
|
115 | a.deepStrictEqual(output, {
|
116 | a: {},
|
117 | _all: { three: '3', four: '4' },
|
118 | _none: { three: '3', four: '4' }
|
119 | })
|
120 | })
|