Skip to content

Commit

Permalink
test(flags): add collect test
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed Apr 4, 2020
1 parent c021659 commit 3c14011
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 61 deletions.
102 changes: 102 additions & 0 deletions packages/flags/test/option/collect_test.ts
@@ -0,0 +1,102 @@
import { parseFlags } from '../../lib/flags.ts';
import { IParseOptions, OptionType } from '../../lib/types.ts';
import { assertEquals, assertThrows } from '../lib/assert.ts';

const options = <IParseOptions>{
allowEmpty: false,
flags: [ {
name: 'flag',
aliases: [ 'f' ],
type: OptionType.STRING,
optionalValue: true
}, {
name: 'string',
aliases: [ 's' ],
type: OptionType.STRING,
collect: true
}, {
name: 'boolean',
aliases: [ 'b' ],
type: OptionType.BOOLEAN,
collect: true
}, {
name: 'number',
aliases: [ 'n' ],
type: OptionType.NUMBER,
collect: true
} ]
};

Deno.test( function flags_optionCollect_flag() {

assertThrows(
() => parseFlags( [ '-f', '-f' ], options ),
Error,
'Duplicate option: -f'
);
} );

Deno.test( function flags_optionCollect_flagLong() {

assertThrows(
() => parseFlags( [ '-f', '--flag' ], options ),
Error,
'Duplicate option: --flag'
);
} );

Deno.test( function flags_optionCollect_flagTrueLongFalse() {

assertThrows(
() => parseFlags( [ '-f', 'true', '--flag', 'false' ], options ),
Error,
'Duplicate option: --flag'
);
} );

Deno.test( function flags_optionCollect_flagTrueNoFlag() {

assertThrows(
() => parseFlags( [ '-f', 'true', '--no-flag' ], options ),
Error,
'Duplicate option: --no-flag'
);
} );

Deno.test( function flags_optionCollect_flagTrueNoFlagTrue() {

assertThrows(
() => parseFlags( [ '-f', 'true', '--no-flag', 'true' ], options ),
Error,
'Duplicate option: --no-flag'
);
} );

Deno.test( function flags_optionCollect_boolean() {

const { flags, unknown, literal } = parseFlags( [ '-b', '1', '--boolean', '0' ], options );

assertEquals( flags, { boolean: [ true, false ] } );
assertEquals( unknown, [] );
assertEquals( literal, [] );
} );

Deno.test( function flags_optionCollect_string() {

const { flags, unknown, literal } = parseFlags( [ '-s', '1', '--string', '0' ], options );

assertEquals( flags, { string: [ '1', '0' ] } );
assertEquals( unknown, [] );
assertEquals( literal, [] );
} );

Deno.test( function flags_optionCollect_number() {

const { flags, unknown, literal } = parseFlags( [ '-n', '1', '--number', '0' ], options );

assertEquals( flags, { number: [ 1, 0 ] } );
assertEquals( unknown, [] );
assertEquals( literal, [] );
} );

await Deno.runTests();
61 changes: 0 additions & 61 deletions packages/flags/test/option/duplicate_test.ts

This file was deleted.

0 comments on commit 3c14011

Please sign in to comment.