Fixed bug with unclosed quotes

Dieser Commit ist enthalten in:
zml2008 2011-09-17 21:10:39 -07:00
Ursprung 46ba1c7f5b
Commit 56fd654eed
2 geänderte Dateien mit 46 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -74,7 +74,7 @@ public class CommandContext {
build.append(' ').append(arg2); build.append(' ').append(arg2);
} }
} }
args = removePortionOfArray(args, i, endIndex, build.toString()); if (endIndex < args.length) args = removePortionOfArray(args, i, endIndex, build.toString());
} }
} }

Datei anzeigen

@ -11,7 +11,6 @@ import java.util.HashSet;
public class CommandContextTest { public class CommandContextTest {
final String firstCmdString = "herpderp -opw testers \"mani world\" 'another thing' because something"; final String firstCmdString = "herpderp -opw testers \"mani world\" 'another thing' because something";
CommandContext firstCommand; CommandContext firstCommand;
CommandContext secondCommand;
@Before @Before
public void setUpTest(){ public void setUpTest(){
@ -19,7 +18,7 @@ public class CommandContextTest {
firstCommand = new CommandContext(firstCmdString, new HashSet<Character>(Arrays.asList('o', 'w'))); firstCommand = new CommandContext(firstCmdString, new HashSet<Character>(Arrays.asList('o', 'w')));
} catch (CommandException e) { } catch (CommandException e) {
e.printStackTrace(); e.printStackTrace();
fail(); fail("Unexpected exception when creating CommandContext");
} }
} }
@ -29,4 +28,48 @@ public class CommandContextTest {
new CommandContext(failingCommand, new HashSet<Character>(Arrays.asList('o', 'w'))); new CommandContext(failingCommand, new HashSet<Character>(Arrays.asList('o', 'w')));
} }
@Test
public void testBasicArgs() {
String command = firstCommand.getCommand();
String argOne = firstCommand.getString(0);
String joinedArg = firstCommand.getJoinedStrings(0);
assertEquals(command, "herpderp");
assertEquals(argOne, "another thing");
assertEquals(joinedArg, "another thing because something");
}
@Test
public void testFlags() {
assertTrue(firstCommand.hasFlag('p'));
assertTrue(firstCommand.hasFlag('o'));
assertTrue(firstCommand.hasFlag('w'));
assertEquals(firstCommand.getFlag('o'), "testers");
assertEquals(firstCommand.getFlag('w'), "mani world");
assertNull(firstCommand.getFlag('u'));
}
@Test
public void testOnlyQuotedString() {
String cmd = "r \"hello goodbye have fun\"";
String cmd2 = "r 'hellogeedby' nnnnnee";
try {
CommandContext context = new CommandContext(cmd);
CommandContext context2 = new CommandContext(cmd2);
} catch (CommandException e) {
e.printStackTrace();
fail("Error creating CommandContext");
}
}
@Test
public void testHagingQuoted() {
String cmd = "r \"hello goodbye have fun";
try {
CommandContext context = new CommandContext(cmd);
} catch (CommandException e) {
e.printStackTrace();
fail("Error creating CommandContext");
}
}
} }