Internal restructuring of CommandContext

- getJoinedStrings(n) will now return literally everything after the first space following the (n-1)th argument. Mixing flags in after that is undefined
- What was in args before is now a List named parsedArgs, which also no longer contains the command, which was split off into a separate field.
- get[Padded]Slice now operates on the unparsed args with flags and all, allowing whoever uses it (script commands) to obtain a more low-level input.
- Added a test for the exactness of getJoinedStrings and adjusted an existing test to the new old behaviour.
This commit is contained in:
TomyLobo
2011-09-20 02:35:15 +02:00
parent 2d86b1b40d
commit 67918f171b
2 changed files with 56 additions and 35 deletions

View File

@ -54,7 +54,7 @@ public class CommandContextTest {
String joinedArg = firstCommand.getJoinedStrings(0);
assertEquals("herpderp", command);
assertEquals("another thing", argOne);
assertEquals("another thing because something", joinedArg);
assertEquals("'another thing' because something", joinedArg);
}
@Test
@ -64,7 +64,7 @@ public class CommandContextTest {
assertTrue(firstCommand.hasFlag('w'));
assertEquals("testers", firstCommand.getFlag('o'));
assertEquals("mani world", firstCommand.getFlag('w'));
assertNull(firstCommand.getFlag('u'));
assertFalse(firstCommand.hasFlag('u'));
}
@Test
@ -103,7 +103,7 @@ public class CommandContextTest {
}
@Test
public void testflagsAnywhere() {
public void testFlagsAnywhere() {
try {
CommandContext context = new CommandContext("r hello -f");
assertTrue(context.hasFlag('f'));
@ -115,4 +115,20 @@ public class CommandContextTest {
fail("Error creating CommandContext");
}
}
@Test
public void testExactJoinedStrings() {
try {
CommandContext context = new CommandContext("r -f \"hello world\" foo bar");
assertTrue(context.hasFlag('f'));
assertEquals("\"hello world\" foo bar", context.getJoinedStrings(0));
assertEquals("foo bar", context.getJoinedStrings(1));
CommandContext context2 = new CommandContext("pm name \"hello world\" foo bar");
assertEquals("\"hello world\" foo bar", context2.getJoinedStrings(1));
} catch (CommandException e) {
e.printStackTrace();
fail("Error creating CommandContext");
}
}
}