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('bad-input: handles missing option value', function () {
|
9 | const definitions = [
|
10 | { name: 'colour', type: String },
|
11 | { name: 'files' }
|
12 | ]
|
13 | a.deepStrictEqual(commandLineArgs(definitions, { argv: [ '--colour' ] }), {
|
14 | colour: null
|
15 | })
|
16 | a.deepStrictEqual(commandLineArgs(definitions, { argv: [ '--colour', '--files', 'yeah' ] }), {
|
17 | colour: null,
|
18 | files: 'yeah'
|
19 | })
|
20 | })
|
21 |
|
22 | runner.test('bad-input: handles arrays with relative paths', function () {
|
23 | const definitions = [
|
24 | { name: 'colours', type: String, multiple: true }
|
25 | ]
|
26 | const argv = [ '--colours', '../what', '../ever' ]
|
27 | a.deepStrictEqual(commandLineArgs(definitions, { argv }), {
|
28 | colours: [ '../what', '../ever' ]
|
29 | })
|
30 | })
|
31 |
|
32 | runner.test('bad-input: empty string', function () {
|
33 | const definitions = [
|
34 | { name: 'one', type: String },
|
35 | { name: 'two', type: Number },
|
36 | { name: 'three', type: Number, multiple: true },
|
37 | { name: 'four', type: String },
|
38 | { name: 'five', type: Boolean }
|
39 | ]
|
40 | const argv = [ '--one', '', '', '--two', '0', '--three=', '', '--four=', '--five=' ]
|
41 | a.deepStrictEqual(commandLineArgs(definitions, { argv }), {
|
42 | one: '',
|
43 | two: 0,
|
44 | three: [ 0, 0 ],
|
45 | four: '',
|
46 | five: true
|
47 | })
|
48 | })
|