CommandLine cl;
CommandInfo cmdInfo;
Command cmd;
try {
cl = new CommandLine(new Token("cmd"), new Token[] {}, null);
cmdInfo = cl.parseCommandLine(shell);
Assert.fail("no exception");
} catch (CommandSyntaxException ex) {
// expected
}
cl =
new CommandLine(new Token("cmd"), new Token[] {new Token("-f"), new Token("F1")},
null);
cmdInfo = cl.parseCommandLine(shell);
cmd = cmdInfo.createCommandInstance();
Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("fileArg").getValues().length);
Assert.assertEquals("F1", cmd.getArgumentBundle().getArgument("fileArg").getValue()
.toString());
Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("intArg").getValues().length);
Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("flagArg").getValues().length);
cl =
new CommandLine(new Token("cmd"), new Token[] {new Token("-i"), new Token("41")},
null);
cmdInfo = cl.parseCommandLine(shell);
cmd = cmdInfo.createCommandInstance();
Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("fileArg").getValues().length);
Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("intArg").getValues().length);
Assert.assertEquals("41", cmd.getArgumentBundle().getArgument("intArg").getValue()
.toString());
Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("flagArg").getValues().length);
cl = new CommandLine(new Token("cmd"), new Token[] {new Token("--xxx")}, null);
cmdInfo = cl.parseCommandLine(shell);
cmd = cmdInfo.createCommandInstance();
Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("fileArg").getValues().length);
Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("intArg").getValues().length);
Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("flagArg").getValues().length);
try {
cl =
new CommandLine(new Token("cmd"), new Token[] {new Token("--xxx"),
new Token("-f"), new Token("F1")}, null);
cl.parseCommandLine(shell);
Assert.fail("no exception");
} catch (CommandSyntaxException ex) {
// expected
}