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('type-boolean: different values', function () {
|
9 | const definitions = [
|
10 | { name: 'one', type: Boolean }
|
11 | ]
|
12 |
|
13 | a.deepStrictEqual(
|
14 | commandLineArgs(definitions, { argv: [ '--one' ] }),
|
15 | { one: true }
|
16 | )
|
17 | a.deepStrictEqual(
|
18 | commandLineArgs(definitions, { argv: [ '--one', 'true' ] }),
|
19 | { one: true }
|
20 | )
|
21 | a.deepStrictEqual(
|
22 | commandLineArgs(definitions, { argv: [ '--one', 'false' ] }),
|
23 | { one: true }
|
24 | )
|
25 | a.deepStrictEqual(
|
26 | commandLineArgs(definitions, { argv: [ '--one', 'sfsgf' ] }),
|
27 | { one: true }
|
28 | )
|
29 | })
|
30 |
|
31 | const origBoolean = Boolean
|
32 |
|
33 |
|
34 | runner.test('type-boolean: global Boolean overridden', function () {
|
35 | function Boolean () {
|
36 | return origBoolean.apply(origBoolean, arguments)
|
37 | }
|
38 |
|
39 | const definitions = [
|
40 | { name: 'one', type: Boolean }
|
41 | ]
|
42 |
|
43 | a.deepStrictEqual(
|
44 | commandLineArgs(definitions, { argv: [ '--one', 'true' ] }),
|
45 | { one: true }
|
46 | )
|
47 | a.deepStrictEqual(
|
48 | commandLineArgs(definitions, { argv: [ '--one', 'false' ] }),
|
49 | { one: true }
|
50 | )
|
51 | a.deepStrictEqual(
|
52 | commandLineArgs(definitions, { argv: [ '--one', 'sfsgf' ] }),
|
53 | { one: true }
|
54 | )
|
55 | a.deepStrictEqual(
|
56 | commandLineArgs(definitions, { argv: [ '--one' ] }),
|
57 | { one: true }
|
58 | )
|
59 | })
|
60 |
|
61 | runner.test('type-boolean-multiple: 1', function () {
|
62 | const definitions = [
|
63 | { name: 'array', type: Boolean, multiple: true }
|
64 | ]
|
65 | const argv = [ '--array', '--array', '--array' ]
|
66 | const result = commandLineArgs(definitions, { argv })
|
67 | a.deepStrictEqual(result, {
|
68 | array: [ true, true, true ]
|
69 | })
|
70 | })
|