Skip to content

Commit

Permalink
feat: Add shortened commands for listTag and findTag
Browse files Browse the repository at this point in the history
  • Loading branch information
HugeNoob committed Oct 27, 2023
1 parent 80b7f18 commit 2282e2f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public class FindTagCommand extends Command {

public static final String COMMAND_WORD = "findTag";
public static final String SHORTENED_COMMAND_WORD = "ftag";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons and tasks whose tag contain any of "
+ "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
* Lists all tags in CoordiMate to the user.
*/
public class ListTagCommand extends Command {

public static final String COMMAND_WORD = "listTag";
public static final String SHORTENED_COMMAND_WORD = "ltag";

public static final String MESSAGE_NO_TAGS_FOUND = "No tags found!";
public static final String MESSAGE_SUCCESS = "Listed all tags: \n%s\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,13 @@ public Command parseCommand(String userInput) throws ParseException {
return new DeleteAllTaskCommand();

case FindTagCommand.COMMAND_WORD:
// Fallthrough
case FindTagCommand.SHORTENED_COMMAND_WORD:
return new FindTagCommandParser().parse(arguments);

case ListTagCommand.COMMAND_WORD:
// Fallthrough
case ListTagCommand.SHORTENED_COMMAND_WORD:
return new ListTagCommand();

case ExitCommand.COMMAND_WORD:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ public void parseCommand_shortened_findTask() throws Exception {
assertEquals(new FindTaskCommand(new TaskContainsKeywordsPredicate(keywords)), command);
}

@Test
public void parseCommand_findTag() throws Exception {
List<String> tagKeywords = Arrays.asList("tag1", "tag2", "tag3");
FindTagCommand command = (FindTagCommand) parser.parseCommand(
Expand All @@ -219,6 +220,17 @@ public void parseCommand_findTag() throws Exception {
command);
}

@Test
public void parseCommand_shortened_findTag() throws Exception {
List<String> tagKeywords = Arrays.asList("tag1", "tag2", "tag3");
FindTagCommand command = (FindTagCommand) parser.parseCommand(
FindTagCommand.SHORTENED_COMMAND_WORD + " " + String.join(" ", tagKeywords));
assertEquals(new FindTagCommand(
new PersonContainsTagsPredicate(tagKeywords),
new TaskContainsTagsPredicate(tagKeywords)),
command);
}

@Test
public void parseCommand_findDone() throws Exception {
assertTrue(parser.parseCommand(FindDoneCommand.COMMAND_WORD) instanceof FindDoneCommand);
Expand Down Expand Up @@ -308,24 +320,29 @@ public void parseCommand_deleteAllTask() throws Exception {
}

@Test
<<<<<<< HEAD
public void parseCommand_shortened_deleteAllTask() throws Exception {
assertTrue(parser.parseCommand(DeleteAllTaskCommand.SHORTENED_COMMAND_WORD) instanceof DeleteAllTaskCommand);
assertTrue(
parser.parseCommand(
DeleteAllTaskCommand.SHORTENED_COMMAND_WORD + " 3") instanceof DeleteAllTaskCommand);
=======
}

@Test
public void parseCommand_listTag() throws Exception {
assertTrue(parser.parseCommand(ListTagCommand.COMMAND_WORD) instanceof ListTagCommand);
assertTrue(parser.parseCommand(ListTagCommand.COMMAND_WORD + " 3") instanceof ListTagCommand);
>>>>>>> master
}

@Test
public void parseCommand_shortened_listTag() throws Exception {
assertTrue(parser.parseCommand(ListTagCommand.SHORTENED_COMMAND_WORD) instanceof ListTagCommand);
assertTrue(parser.parseCommand(ListTagCommand.SHORTENED_COMMAND_WORD + " 3") instanceof ListTagCommand);
}

@Test
public void parseCommand_unrecognisedInput_throwsParseException() {
assertThrows(ParseException.class, String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE),
() -> parser.parseCommand(""));
assertThrows(ParseException.class, String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE), ()
-> parser.parseCommand(""));
}

@Test
Expand Down

0 comments on commit 2282e2f

Please sign in to comment.