From 401d5a31bec31e92c4cdf66e1674f274655bbf50 Mon Sep 17 00:00:00 2001 From: CYX22222003 Date: Sat, 2 Nov 2024 18:09:14 +0800 Subject: [PATCH 1/4] Update add tag parser --- src/main/java/seedu/address/logic/Messages.java | 2 +- .../seedu/address/logic/parser/AddTagCommandParser.java | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index fabbf6453b5..7327edb80af 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -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"; diff --git a/src/main/java/seedu/address/logic/parser/AddTagCommandParser.java b/src/main/java/seedu/address/logic/parser/AddTagCommandParser.java index a35b7259759..af34e076952 100644 --- a/src/main/java/seedu/address/logic/parser/AddTagCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddTagCommandParser.java @@ -1,6 +1,7 @@ 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; @@ -59,7 +60,11 @@ private Optional> parseTagsToAdd(Collection tags) throws ParseE if (tags.isEmpty()) { return Optional.empty(); } - Collection 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)); } } From 9155ef70d77a5d5aa8fa640ac7e54ed93d5924ed Mon Sep 17 00:00:00 2001 From: CYX22222003 Date: Sat, 2 Nov 2024 18:11:57 +0800 Subject: [PATCH 2/4] Modify style errors --- .../java/seedu/address/logic/parser/AddTagCommandParser.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/seedu/address/logic/parser/AddTagCommandParser.java b/src/main/java/seedu/address/logic/parser/AddTagCommandParser.java index af34e076952..074c8ca4e37 100644 --- a/src/main/java/seedu/address/logic/parser/AddTagCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddTagCommandParser.java @@ -8,7 +8,6 @@ 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; From fdd060ae9c8611437434c7a21f34c6e5f39fee8c Mon Sep 17 00:00:00 2001 From: CYX22222003 Date: Sat, 2 Nov 2024 18:15:50 +0800 Subject: [PATCH 3/4] Update test cases for new change in error message --- .../java/seedu/address/logic/commands/CommandTestUtil.java | 2 +- .../seedu/address/logic/parser/AddTagCommandParserTest.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index 8ac2f32b040..1cd20f03929 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -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"; diff --git a/src/test/java/seedu/address/logic/parser/AddTagCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddTagCommandParserTest.java index 8aa1ef0c59a..6e342cc0562 100644 --- a/src/test/java/seedu/address/logic/parser/AddTagCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddTagCommandParserTest.java @@ -5,6 +5,7 @@ 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; @@ -33,10 +34,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 From 787a2d2b8e4d7c6d9cf75108af564c2bb5909086 Mon Sep 17 00:00:00 2001 From: CYX22222003 Date: Sat, 2 Nov 2024 18:17:40 +0800 Subject: [PATCH 4/4] Correct style errors --- .../java/seedu/address/logic/parser/AddTagCommandParserTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/seedu/address/logic/parser/AddTagCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddTagCommandParserTest.java index 6e342cc0562..25344480236 100644 --- a/src/test/java/seedu/address/logic/parser/AddTagCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddTagCommandParserTest.java @@ -4,7 +4,6 @@ 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;