From 923a3b14d56705ab26f572746543fd3902cdf861 Mon Sep 17 00:00:00 2001 From: juergba Date: Sat, 15 Jun 2019 18:48:02 +0200 Subject: [PATCH] tests --- test/yargs-parser.js | 62 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 7 deletions(-) diff --git a/test/yargs-parser.js b/test/yargs-parser.js index a8628261..37a603d2 100644 --- a/test/yargs-parser.js +++ b/test/yargs-parser.js @@ -1108,7 +1108,7 @@ describe('yargs-parser', function () { }) }) - describe('with implied false default', function () { + describe('without any default value', function () { var opts = null beforeEach(function () { @@ -1125,8 +1125,8 @@ describe('yargs-parser', function () { parser(['--no-flag'], opts).flag.should.be.false // eslint-disable-line }) - it('should set false if no flag in arg', function () { - expect(parser([], opts).flag).to.be.undefined // eslint-disable-line + it('should not add property if no flag in arg', function () { + parser([''], opts).should.not.have.property('flag') }) }) @@ -2321,7 +2321,7 @@ describe('yargs-parser', function () { describe('type=number', function () { it('[-x 1 -x 2 -x 3] => 3', function () { var parsed = parser('-x 1 -x 2 -x 3', { - number: 'x', + number: ['x'], configuration: { 'duplicate-arguments-array': false, 'flatten-duplicate-arrays': false @@ -2330,6 +2330,18 @@ describe('yargs-parser', function () { parsed['x'].should.deep.equal(3) }) }) + describe('type=boolean', function () { + it('[-x true -x true -x false] => false', function () { + var parsed = parser('-x true -x true -x false', { + boolean: ['x'], + configuration: { + 'duplicate-arguments-array': false, + 'flatten-duplicate-arrays': false + } + }) + parsed['x'].should.deep.equal(false) + }) + }) }) describe('duplicate=false, flatten=true,', function () { describe('type=array', function () { @@ -2357,7 +2369,7 @@ describe('yargs-parser', function () { describe('type=number', function () { it('[-x 1 -x 2 -x 3] => 3', function () { var parsed = parser('-x 1 -x 2 -x 3', { - number: 'x', + number: ['x'], configuration: { 'duplicate-arguments-array': false, 'flatten-duplicate-arrays': true @@ -2366,6 +2378,18 @@ describe('yargs-parser', function () { parsed['x'].should.deep.equal(3) }) }) + describe('type=boolean', function () { + it('[-x true -x true -x false] => false', function () { + var parsed = parser('-x true -x true -x false', { + boolean: ['x'], + configuration: { + 'duplicate-arguments-array': false, + 'flatten-duplicate-arrays': true + } + }) + parsed['x'].should.deep.equal(false) + }) + }) }) describe('duplicate=true, flatten=true,', function () { describe('type=array', function () { @@ -2393,7 +2417,7 @@ describe('yargs-parser', function () { describe('type=number', function () { it('[-x 1 -x 2 -x 3] => [1, 2, 3]', function () { var parsed = parser('-x 1 -x 2 -x 3', { - number: 'x', + number: ['x'], configuration: { 'duplicate-arguments-array': true, 'flatten-duplicate-arrays': true @@ -2402,6 +2426,18 @@ describe('yargs-parser', function () { parsed['x'].should.deep.equal([1, 2, 3]) }) }) + describe('type=boolean', function () { + it('[-x true -x true -x false] => [true, true, false]', function () { + var parsed = parser('-x true -x true -x false', { + boolean: ['x'], + configuration: { + 'duplicate-arguments-array': true, + 'flatten-duplicate-arrays': true + } + }) + parsed['x'].should.deep.equal([true, true, false]) + }) + }) }) describe('duplicate=true, flatten=false,', function () { describe('type=array', function () { @@ -2429,7 +2465,7 @@ describe('yargs-parser', function () { describe('type=number', function () { it('[-x 1 -x 2 -x 3] => [1, 2, 3]', function () { var parsed = parser('-x 1 -x 2 -x 3', { - number: 'x', + number: ['x'], configuration: { 'duplicate-arguments-array': true, 'flatten-duplicate-arrays': false @@ -2438,6 +2474,18 @@ describe('yargs-parser', function () { parsed['x'].should.deep.equal([1, 2, 3]) }) }) + describe('type=boolean', function () { + it('[-x true -x true -x false] => [true, true, false]', function () { + var parsed = parser('-x true -x true -x false', { + boolean: ['x'], + configuration: { + 'duplicate-arguments-array': true, + 'flatten-duplicate-arrays': false + } + }) + parsed['x'].should.deep.equal([true, true, false]) + }) + }) }) })