Skip to content

Commit

Permalink
Merge pull request #118 from marquestye/info-command
Browse files Browse the repository at this point in the history
Update info and delete parser
  • Loading branch information
yyyaohhh authored Oct 20, 2023
2 parents 4117353 + 6d32741 commit d319501
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/logic/commands/InfoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class InfoCommand extends Command {
public static final String COMMAND_WORD = "info";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Shows information on the module identified by the module code. "
+ ": Shows information on the module identified by the module code. \n"
+ "Parameters: " + "code \n"
+ "Example: " + COMMAND_WORD + " " + "CS1101S ";
public static final String MESSAGE_INFO_MODULE_SUCCESS = "%1$s: %2$s \n"
+ "%3$s \n"
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/seedu/address/logic/parser/DeleteCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.module.ModuleCode;
Expand All @@ -11,20 +14,24 @@
*/
public class DeleteCommandParser implements Parser<DeleteCommand> {

// Pattern to check for single argument (no spaces)
private static final Pattern SINGLE_ARGUMENT_FORMAT = Pattern.compile("^[^\\s]+$");

/**
* Parses the given {@code String} of arguments in the context of the DeleteCommand
* and returns a DeleteCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public DeleteCommand parse(String args) throws ParseException {
try {
ModuleCode code = ParserUtil.parseModuleCode(args);
return new DeleteCommand(code);

} catch (ParseException pe) {
Matcher matcher = SINGLE_ARGUMENT_FORMAT.matcher(args.trim());
if (!matcher.matches()) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE), pe);
String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE));
}

ModuleCode moduleCode = ParserUtil.parseModuleCode(args);
return new DeleteCommand(moduleCode);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class InfoCommandParser implements Parser<InfoCommand> {

// Probably should be defined elsewhere
// Pattern to check for single argument (no spaces)
private static final Pattern SINGLE_ARGUMENT_FORMAT = Pattern.compile("^[\\w/]+$");
private static final Pattern SINGLE_ARGUMENT_FORMAT = Pattern.compile("^[^\\s]+$");

/**
* Parses the given {@code String} of arguments in the context of the InfoCommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess;
import static seedu.address.model.module.ModuleCode.MESSAGE_CONSTRAINTS;
import static seedu.address.testutil.TypicalModules.CS2030S;

import org.junit.jupiter.api.Test;
Expand All @@ -26,8 +27,14 @@ public void parse_validArgs_returnsDeleteCommand() {
}

@Test
public void parse_invalidArgs_throwsParseException() {
assertParseFailure(parser, "a", String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE));
assertParseFailure(parser, "2030", String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE));
public void parse_invalidSingleArg_throwsParseException() {
assertParseFailure(parser, "ab", MESSAGE_CONSTRAINTS);
assertParseFailure(parser, "2030s", MESSAGE_CONSTRAINTS);
}

@Test
public void parse_invalidMultipleArgs_throwsParseException() {
assertParseFailure(parser, "a b", String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE));
assertParseFailure(parser, "2030 s", String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.junit.jupiter.api.Test;

public class InfoCommandParserTest {

private InfoCommandParser parser = new InfoCommandParser();

@Test
Expand Down

0 comments on commit d319501

Please sign in to comment.