Skip to content

Commit bdd0701

Browse files
authored
Merge pull request #219 from reynardian/find-bugfixes-pe-d
Update find command to allow partial matching of phone number with less than 3 digits
2 parents 95f2870 + 868f5fd commit bdd0701

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/main/java/seedu/address/logic/parser/FindCommandParser.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ private void validateValueByPrefix(Prefix prefix, String value) throws ParseExce
125125
} else if (prefix.equals(PREFIX_ADDRESS)) {
126126
ParserUtil.parseAddress(value);
127127
} else if (prefix.equals(PREFIX_PARENT_PHONE)) {
128-
ParserUtil.parsePhone(value);
128+
if (!value.matches("\\d+")) {
129+
throw new ParseException("Phone numbers should only contain digits.");
130+
}
129131
} else if (prefix.equals(PREFIX_PARENT_EMAIL)) {
130132
ParserUtil.parseEmail(value);
131133
} else if (prefix.equals(PREFIX_TAG)) {

src/test/java/seedu/address/logic/parser/FindCommandParserTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public void parse_validArgs_returnsFindCommand() {
5050
duplicatePrefixMap.put(PREFIX_NAME, Arrays.asList("Alice", "Bob"));
5151
assertParseSuccess(parser, " n/Alice n/Bob", new FindCommand(
5252
new NameContainsKeywordsPredicate(duplicatePrefixMap)));
53+
54+
// 3. Short Phone Number
55+
Map<Prefix, List<String>> phoneMap = new HashMap<>();
56+
phoneMap.put(PREFIX_PARENT_PHONE, Arrays.asList("91"));
57+
assertParseSuccess(parser, " pc/91", new FindCommand(
58+
new NameContainsKeywordsPredicate(phoneMap)));
5359
}
5460

5561
@Test
@@ -98,7 +104,7 @@ public void parse_invalidPrefix_throwsParseException() {
98104
public void parse_invalidValue_throwsParseException() {
99105
// 1. Invalid format for specific types
100106
assertParseFailure(parser, " a/notAnAge", Age.MESSAGE_CONSTRAINTS);
101-
assertParseFailure(parser, " pc/notAPhone", seedu.address.model.person.Phone.MESSAGE_CONSTRAINTS);
107+
assertParseFailure(parser, " pc/notAPhone", "Phone numbers should only contain digits.");
102108

103109
// 2. Empty values (after the prefix)
104110
assertParseFailure(parser, " n/ ", Name.MESSAGE_CONSTRAINTS);

0 commit comments

Comments
 (0)