-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
21 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
import { assertThrows } from '../../../flags/test/lib/assert.ts'; | ||
import { Command } from '../../lib/command.ts'; | ||
import { assertEquals } from '../lib/assert.ts'; | ||
import { assertEquals, assertThrowsAsync } from '../lib/assert.ts'; | ||
|
||
const cmd: Command = new Command() | ||
.throwErrors() | ||
.option( '--flag1', 'flag 1' ) | ||
.option( '--flag2 <val:string>', 'flag 2', { depends: [ 'flag1' ], default: 'example' } ); | ||
function command(): Command { | ||
return new Command() | ||
.throwErrors() | ||
.option( '-f, --flag1', 'flag 1' ) | ||
.option( '-F, --flag2 <val:string>', 'flag 2', { depends: [ 'flag1' ], default: 'example' } ); | ||
} | ||
|
||
Deno.test( 'command depends option with default value: should accept no arguments', async () => { | ||
|
||
const { options, args } = await cmd.parse( [] ); | ||
const { options, args } = await command().parse( [] ); | ||
|
||
assertEquals( options, { flag2: 'example' } ); | ||
assertEquals( args, [] ); | ||
} ); | ||
|
||
Deno.test( 'command depends option with default value: should accept -h', async () => { | ||
|
||
const { options, args } = await cmd.parse( [ '-h' ] ); | ||
|
||
assertEquals( options, { flag2: 'example' } ); | ||
assertEquals( args, [] ); | ||
} ); | ||
// disabled because the -h flag call's Deno.exit() and stops the test's. | ||
// Deno.test( 'command depends option with default value: should accept -h', async () => { | ||
// | ||
// const { options, args } = await cmd().parse( [ '-h' ] ); | ||
// | ||
// assertEquals( options, { flag2: 'example' } ); | ||
// assertEquals( args, [] ); | ||
// } ); | ||
|
||
Deno.test( 'command depends option with default value: should accept --flag1', async () => { | ||
|
||
const { options, args } = await cmd.parse( [ '--flag1' ] ); | ||
const { options, args } = await command().parse( [ '--flag1' ] ); | ||
|
||
assertEquals( options, { flag1: true, flag2: 'example' } ); | ||
assertEquals( args, [] ); | ||
} ); | ||
|
||
Deno.test( 'command depends option with default value: should accept --flag1 --flag2 test', async () => { | ||
|
||
const { options, args } = await cmd.parse( [ '--flag1', '--flag2', 'test' ] ); | ||
const { options, args } = await command().parse( [ '--flag1', '--flag2', 'test' ] ); | ||
|
||
assertEquals( options, { flag1: true, flag2: 'test' } ); | ||
assertEquals( args, [] ); | ||
} ); | ||
|
||
Deno.test( 'command depends option with default value: should not accept --flag2 test', async () => { | ||
|
||
assertThrows( | ||
() => cmd.parse( [ '--flag2', 'test' ] ), | ||
Error, | ||
'Option --flag2 depends on option: --flag1' | ||
); | ||
await assertThrowsAsync( async () => { | ||
await command().parse( [ '--flag2', 'test' ] ); | ||
}, Error, 'Option --flag2 depends on option: --flag1' ); | ||
} ); |