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-other: different values', function () {
|
9 | const definitions = [
|
10 | {
|
11 | name: 'file',
|
12 | type: function (file) {
|
13 | return file
|
14 | }
|
15 | }
|
16 | ]
|
17 |
|
18 | a.deepStrictEqual(
|
19 | commandLineArgs(definitions, { argv: [ '--file', 'one.js' ] }),
|
20 | { file: 'one.js' }
|
21 | )
|
22 | a.deepStrictEqual(
|
23 | commandLineArgs(definitions, { argv: [ '--file' ] }),
|
24 | { file: null }
|
25 | )
|
26 | })
|
27 |
|
28 | runner.test('type-other: broken custom type function', function () {
|
29 | const definitions = [
|
30 | {
|
31 | name: 'file',
|
32 | type: function (file) {
|
33 | lasdfjsfakn
|
34 | }
|
35 | }
|
36 | ]
|
37 | a.throws(function () {
|
38 | commandLineArgs(definitions, { argv: [ '--file', 'one.js' ] })
|
39 | })
|
40 | })
|
41 |
|
42 | runner.test('type-other-multiple: different values', function () {
|
43 | const definitions = [
|
44 | {
|
45 | name: 'file',
|
46 | multiple: true,
|
47 | type: function (file) {
|
48 | return file
|
49 | }
|
50 | }
|
51 | ]
|
52 |
|
53 | a.deepStrictEqual(
|
54 | commandLineArgs(definitions, { argv: [ '--file', 'one.js' ] }),
|
55 | { file: [ 'one.js' ] }
|
56 | )
|
57 | a.deepStrictEqual(
|
58 | commandLineArgs(definitions, { argv: [ '--file', 'one.js', 'two.js' ] }),
|
59 | { file: [ 'one.js', 'two.js' ] }
|
60 | )
|
61 | a.deepStrictEqual(
|
62 | commandLineArgs(definitions, { argv: [ '--file' ] }),
|
63 | { file: [] }
|
64 | )
|
65 | })
|