Skip to content

Commit

Permalink
test(command): update sub-command test
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed Apr 2, 2020
1 parent 8264b1a commit 0939b6d
Showing 1 changed file with 65 additions and 9 deletions.
74 changes: 65 additions & 9 deletions packages/command/test/command/sub-command_test.ts
Expand Up @@ -4,28 +4,84 @@ import { assertEquals, assertThrowsAsync } from '../lib/assert.ts';
const version = '1.0.0';
const description = 'Test description ...';

const cmd = new Command()
.throwErrors()
.version( version )
.description( description )
.arguments( '[command]' )
.command( 'sub-command <input:string> <output:string>' )
.option( '-f, --flag [value:string]', 'description ...', { required: true } )
.action( () => {} );
function command( states: any = {} ): Command {
return new Command()
.throwErrors()
.version( version )
.description( description )
.arguments( '[command]' )
.command( 'sub-command <input:string> <output:string>' )
.option( '-f, --flag [value:string]', 'description ...', { required: true } )
.action( () => { states.action1 = true; } )
.command( 'sub-command2 <input:string> <output:string>', new Command()
.description( description )
.arguments( '[command]' )
.action( () => { states.action2 = true; } )
.command( 'sub-command3 <input:string> <output:string>' )
.option( '-e, --eee [value:string]', 'description ...' )
.action( () => { states.action3 = true; } ) );
}

Deno.test( async function command_subCommand() {

const stats: any = {};
const cmd: Command = command( stats );
const { options, args } = await cmd.parse( [ 'sub-command', 'input-path', 'output-path' ] );

assertEquals( options, {} );
assertEquals( args[ 0 ], 'input-path' );
assertEquals( args[ 1 ], 'output-path' );
assertEquals( stats.action1, true );
assertEquals( stats.action2, undefined );
assertEquals( stats.action3, undefined );
} );

Deno.test( async function command_subCommand2() {

const stats: any = {};
const cmd: Command = command( stats );
const { options, args } = await cmd.parse( [ 'sub-command2', 'input-path', 'output-path' ] );

assertEquals( options, {} );
assertEquals( args[ 0 ], 'input-path' );
assertEquals( args[ 1 ], 'output-path' );
assertEquals( stats.action1, undefined );
assertEquals( stats.action2, true );
assertEquals( stats.action3, undefined );
} );

Deno.test( async function command_subCommand3() {

const stats: any = {};
const cmd: Command = command( stats );
const { options, args } = await cmd.parse( [ 'sub-command2', 'sub-command3', 'input-path', 'output-path' ] );

assertEquals( options, {} );
assertEquals( args[ 0 ], 'input-path' );
assertEquals( args[ 1 ], 'output-path' );
assertEquals( stats.action1, undefined );
assertEquals( stats.action2, undefined );
assertEquals( stats.action3, true );
} );

Deno.test( async function command_subCommand_typeString_flagMissing() {

await assertThrowsAsync( async () => {
await cmd.parse( [ 'sub-command', 'input-path' ] );
await command().parse( [ 'sub-command', 'input-path' ] );
}, Error, 'Missing argument: output' );
} );

Deno.test( async function command_subCommand2_typeString_flagMissing() {

await assertThrowsAsync( async () => {
await command().parse( [ 'sub-command2', 'input-path' ] );
}, Error, 'Missing argument: output' );
} );

Deno.test( async function command_subCommand3_typeString_flagMissing() {

await assertThrowsAsync( async () => {
await command().parse( [ 'sub-command2', 'sub-command3', 'input-path' ] );
}, Error, 'Missing argument: output' );
} );

Expand Down

0 comments on commit 0939b6d

Please sign in to comment.