Spaces:
Sleeping
Sleeping
File size: 1,376 Bytes
be5030f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
'use strict'
const TestRunner = require('test-runner')
const a = require('assert')
const commandLineArgs = require('../')
const runner = new TestRunner()
runner.test('stopAtFirstUnknown', function () {
const optionDefinitions = [
{ name: 'one', type: Boolean },
{ name: 'two', type: Boolean }
]
const argv = [ '--one', 'a', '--two' ]
const result = commandLineArgs(optionDefinitions, { argv, stopAtFirstUnknown: true, partial: true })
a.deepStrictEqual(result, {
one: true,
_unknown: [ 'a', '--two' ]
})
})
runner.test('stopAtFirstUnknown: with a singlular defaultOption', function () {
const optionDefinitions = [
{ name: 'one', defaultOption: true },
{ name: 'two' }
]
const argv = [ '--one', '1', '--', '--two', '2' ]
const result = commandLineArgs(optionDefinitions, { argv, stopAtFirstUnknown: true })
a.deepStrictEqual(result, {
one: '1',
_unknown: [ '--', '--two', '2' ]
})
})
runner.test('stopAtFirstUnknown: with a singlular defaultOption and partial', function () {
const optionDefinitions = [
{ name: 'one', defaultOption: true },
{ name: 'two' }
]
const argv = [ '--one', '1', '--', '--two', '2' ]
const result = commandLineArgs(optionDefinitions, { argv, stopAtFirstUnknown: true, partial: true })
a.deepStrictEqual(result, {
one: '1',
_unknown: [ '--', '--two', '2' ]
})
})
|