Skip to content

Commit

Permalink
Fixed bug where multiple included filetypes are not detected properly
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianquek committed Jul 24, 2015
1 parent 20bae6d commit e3cc1d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/main/java/backend/CommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CommandParser {
private static final int POSITION_PARAM_COMMAND = 0;
private static final int POSITION_FIRST_PARAM_ARGUMENT = 1;

private static final String REGEX_WHITESPACES = "\\s+";
private static final String REGEX_WHITESPACES = "[\\s,]+";

private static final String STRING_BACKSLASH = "\\";
private static final String STRING_FORWARD_SLASH = "/";
Expand Down Expand Up @@ -176,7 +176,7 @@ private ArrayList<String> findIncludedFileTypes(ArrayList<String> arguments) {
if (arguments.contains(KEYWORD_INCLUDE)) {
int fileTypesIndex = arguments.indexOf(KEYWORD_INCLUDE) + 1;
for (int i = fileTypesIndex; i < arguments.size(); i++) {
String inputFileType = arguments.get(i);
String inputFileType = arguments.get(i).toLowerCase();
if (isValidFileType(inputFileType)) {
fileTypes.add(inputFileType);
} else {
Expand All @@ -192,8 +192,7 @@ private ArrayList<String> findIncludedFileTypes(ArrayList<String> arguments) {
*
* @param inputFileType
*/
private boolean isValidFileType(String inputFileType) {
String fileType = inputFileType.trim().toLowerCase();
private boolean isValidFileType(String fileType) {
for (String keyword : KEYWORDS) {
if (keyword.equals(fileType)) {
return false;
Expand Down
8 changes: 6 additions & 2 deletions src/test/TestCommandParserAndCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ public void testCollateCommand() {
assertEquals("C:\\", command.getDirectory());
assertFalse(command.willScanCurrentDirOnly());
assertEquals(2, command.getFileTypes().size());
assertEquals("java", command.getFileTypes().get(0));
assertEquals("css", command.getFileTypes().get(1));

command = commandParser.parse("collate include css from C:/");
command = commandParser.parse("collate include css, FXML from C:/");
assertEquals(Command.Type.COLLATE, command.getCommandType());
assertEquals("C:\\", command.getDirectory());
assertFalse(command.willScanCurrentDirOnly());
assertEquals(1, command.getFileTypes().size());
assertEquals(2, command.getFileTypes().size());
assertEquals("css", command.getFileTypes().get(0));
assertEquals("fxml", command.getFileTypes().get(1));

command = commandParser.parse("collate include css from \"C:/Program Files\" only");
assertEquals(Command.Type.COLLATE, command.getCommandType());
Expand Down

0 comments on commit e3cc1d6

Please sign in to comment.