From de5818accfdb8768abcd847f993d7001e6dd0f66 Mon Sep 17 00:00:00 2001 From: nexdrew Date: Sat, 9 Jan 2016 18:05:38 -0500 Subject: [PATCH] add tests for group reset and option uniqueness per group --- test/usage.js | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ test/yargs.js | 2 ++ 2 files changed, 54 insertions(+) diff --git a/test/usage.js b/test/usage.js index 4950d9a8e..16f5c3a67 100644 --- a/test/usage.js +++ b/test/usage.js @@ -1200,6 +1200,34 @@ describe('usage tests', function () { 'Missing', 'required', 'argument:', 'y' ]) }) + + it('resets groups for a command handler, respecting order', function () { + var r = checkUsage(function () { + return yargs(['upload', '-h']) + .command('upload', 'upload something', function (yargs, argv) { + argv = yargs + .option('q', { + type: 'boolean', + group: 'Flags:' + }) + .help('h').group('h', 'Global Flags:') + .wrap(null) + .argv + }) + .help('h').group('h', 'Global Flags:') + .wrap(null) + .argv + }) + + r.logs[0].split('\n').should.deep.equal([ + 'Flags:', + ' -q [boolean]', + '', + 'Global Flags:', + ' -h Show help [boolean]', + '' + ]) + }) }) describe('epilogue', function () { @@ -1747,6 +1775,30 @@ describe('usage tests', function () { '' ]) }) + + it('only displays a duplicated option once per group', function () { + var r = checkUsage(function () { + return yargs(['-h']) + .help('h') + .group(['batman', 'batman'], 'Heroes:') + .group('robin', 'Heroes:') + .option('robin', { + group: 'Heroes:' + }) + .wrap(null) + .argv + }) + + r.logs[0].split('\n').should.deep.equal([ + 'Heroes:', + ' --batman', + ' --robin', + '', + 'Options:', + ' -h Show help [boolean]', + '' + ]) + }) }) describe('cjk', function () { diff --git a/test/yargs.js b/test/yargs.js index 467916fad..8b87e8267 100644 --- a/test/yargs.js +++ b/test/yargs.js @@ -213,6 +213,7 @@ describe('yargs dsl tests', function () { .string('foo') .choices('foo', ['bar', 'baz']) .implies('foo', 'snuh') + .group('foo', 'Group:') .strict() .exitProcess(false) // defaults to true. .env('YARGS') @@ -242,6 +243,7 @@ describe('yargs dsl tests', function () { expect(y.getStrict()).to.equal(false) expect(y.getDemanded()).to.deep.equal({}) expect(y.getCommandHandlers()).to.deep.equal({}) + expect(y.getGroups()).to.deep.equal({}) }) })