Skip to content

Commit

Permalink
added test to check for bad arguments error
Browse files Browse the repository at this point in the history
  • Loading branch information
Paolo Infante committed Jun 6, 2022
1 parent 6f81f11 commit 4e8f6d9
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/tests/terminalemulator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ class DummyOutputStream extends OutputStream {
clear(): void {}
}

class StringOutputStream extends OutputStream {
public buffer: string = '';

write(message: string): void {
this.buffer += message;
}

clear(): void {
this.buffer = '';
}
}

test('scheme parser', async () => {
const terminal = new TerminalEmulator(
new DummyOutputStream(),
Expand Down Expand Up @@ -88,3 +100,23 @@ test('command not found 2', async () => {

expect(await terminal.parse('test2 --arg1 --arg2 testval')).toBe(false);
});

test('command with bad arguments, should print the error message signaling bad arguments', async () => {
const outStream = new StringOutputStream('\n');

const terminal = new TerminalEmulator(outStream, new DefaultLocalization());

const callback = async (_: string, __: Argument[]) => true;

terminal.command(
new CommandSchemeBuilder('test')
.withFlagArgument('hello')
.withPositionalArgument()
.callback(callback)
.build()
);

await terminal.parse('test --hello');

expect(outStream.buffer.includes('Bad arguments'));
});

0 comments on commit 4e8f6d9

Please sign in to comment.