Skip to content

Commit

Permalink
Merge pull request #199
Browse files Browse the repository at this point in the history
Update add tag parser
  • Loading branch information
KrashKart authored Nov 2, 2024
2 parents 1b736bc + 787a2d2 commit 6d350d5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Messages {
public static final String MESSAGE_NO_TAG = "The person does not contain the tag";
public static final String MESSAGE_TAG_NOT_FOUND = "There is no tag presented in the command!";
public static final String MESSAGE_DELETE_TAG_SUCCESS = "Tag %1$s is deleted from student %2$s";

public static final String MESSAGE_ADD_TAG_EMPTY_TAGS = "Should not add empty tag to a person";
public static final String MESSAGE_UNDO_FAILURE = "Already at the oldest change";

public static final String MESSAGE_REDO_FAILURE = "Already at the latest change";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package seedu.address.logic.parser;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.Messages.MESSAGE_ADD_TAG_EMPTY_TAGS;
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.commands.AddTagCommand.MESSAGE_NOT_ADD;
import static seedu.address.logic.commands.AddTagCommand.MESSAGE_USAGE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;

Expand Down Expand Up @@ -59,7 +59,11 @@ private Optional<Set<Tag>> parseTagsToAdd(Collection<String> tags) throws ParseE
if (tags.isEmpty()) {
return Optional.empty();
}
Collection<String> tagSet = tags.size() == 1 && tags.contains("") ? Collections.emptySet() : tags;
return Optional.of(ParserUtil.parseTags(tagSet));

if (tags.contains("")) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, MESSAGE_ADD_TAG_EMPTY_TAGS));
}

return Optional.of(ParserUtil.parseTags(tags));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class CommandTestUtil {
public static final String INVALID_PHONE_DESC = " " + PREFIX_PHONE + "911a"; // 'a' not allowed in phones
public static final String INVALID_EMAIL_DESC = " " + PREFIX_EMAIL + "bob!yahoo"; // missing '@' symbol
public static final String INVALID_TAG_DESC = " " + PREFIX_TAG + "hubby*"; // '*' not allowed in tags

public static final String INVALID_TAG_DESC_NO_SPACE = PREFIX_TAG + "hubby*";
public static final String PREAMBLE_WHITESPACE = "\t \r \n";
public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.commands.AddTagCommand.MESSAGE_NOT_ADD;
import static seedu.address.logic.commands.AddTagCommand.MESSAGE_USAGE;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_TAG_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_TAG_DESC_NO_SPACE;
import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_HUSBAND;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess;
Expand Down Expand Up @@ -33,10 +33,10 @@ public void parse_invalidTagCharacter_throwsParseException() {
String expectedMessage = String.format(Tag.MESSAGE_CONSTRAINTS);

// one invalid tag
assertParseFailure(parser, "1 t/" + INVALID_TAG_DESC, expectedMessage);
assertParseFailure(parser, "1 " + INVALID_TAG_DESC_NO_SPACE, expectedMessage);

// two invalid tags
assertParseFailure(parser, "2 t/" + INVALID_TAG_DESC + " t/c#lassmate", expectedMessage);
assertParseFailure(parser, "2 " + INVALID_TAG_DESC_NO_SPACE + " t/c#lassmate", expectedMessage);
}

@Test
Expand Down

0 comments on commit 6d350d5

Please sign in to comment.