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-number: different values', function () {
|
9 | const optionDefinitions = [
|
10 | { name: 'one', type: Number }
|
11 | ]
|
12 | a.deepStrictEqual(
|
13 | commandLineArgs(optionDefinitions, { argv: [ '--one', '1' ] }),
|
14 | { one: 1 }
|
15 | )
|
16 | a.deepStrictEqual(
|
17 | commandLineArgs(optionDefinitions, { argv: [ '--one' ] }),
|
18 | { one: null }
|
19 | )
|
20 | a.deepStrictEqual(
|
21 | commandLineArgs(optionDefinitions, { argv: [ '--one', '-1' ] }),
|
22 | { one: -1 }
|
23 | )
|
24 | const result = commandLineArgs(optionDefinitions, { argv: [ '--one', 'asdf' ] })
|
25 | a.ok(isNaN(result.one))
|
26 | })
|
27 |
|
28 | runner.test('number multiple: 1', function () {
|
29 | const optionDefinitions = [
|
30 | { name: 'array', type: Number, multiple: true }
|
31 | ]
|
32 | const argv = [ '--array', '1', '2', '3' ]
|
33 | const result = commandLineArgs(optionDefinitions, { argv })
|
34 | a.deepStrictEqual(result, {
|
35 | array: [ 1, 2, 3 ]
|
36 | })
|
37 | a.notDeepStrictEqual(result, {
|
38 | array: [ '1', '2', '3' ]
|
39 | })
|
40 | })
|
41 |
|
42 | runner.test('number multiple: 2', function () {
|
43 | const optionDefinitions = [
|
44 | { name: 'array', type: Number, multiple: true }
|
45 | ]
|
46 | const argv = [ '--array', '1', '--array', '2', '--array', '3' ]
|
47 | const result = commandLineArgs(optionDefinitions, { argv })
|
48 | a.deepStrictEqual(result, {
|
49 | array: [ 1, 2, 3 ]
|
50 | })
|
51 | a.notDeepStrictEqual(result, {
|
52 | array: [ '1', '2', '3' ]
|
53 | })
|
54 | })
|