forked from nus-cs2103-AY1819S2/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 5
/
SearchCommandParserTest.java
executable file
·95 lines (81 loc) · 4.72 KB
/
SearchCommandParserTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package seedu.address.logic.parser;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_BAR;
import static seedu.address.logic.commands.CommandTestUtil.TITLE_DESC_ENGINEERING;
import static seedu.address.logic.commands.CommandTestUtil.TYPE_DESC_ENGINEERING;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DETAILS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TITLE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TYPE;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess;
import org.junit.Test;
import seedu.address.logic.commands.SearchCommand;
import seedu.address.model.source.SourceContainsKeywordsPredicate;
public class SearchCommandParserTest {
private SearchCommandParser parser = new SearchCommandParser();
@Test
public void parse_emptyArg_throwsParseException() {
assertParseFailure(parser, " ",
String.format(MESSAGE_INVALID_COMMAND_FORMAT, SearchCommand.MESSAGE_USAGE));
}
@Test
public void parse_emptyTitlePrefixArgs_returnsSearchCommand() {
String input = " " + PREFIX_TITLE + " ";
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(input,
PREFIX_TITLE, PREFIX_TYPE, PREFIX_DETAILS, PREFIX_TAG);
SearchCommand expectedSearchCommand = new SearchCommand(new SourceContainsKeywordsPredicate(argMultimap));
assertParseSuccess(parser, " " + PREFIX_TITLE + " ", expectedSearchCommand);
}
@Test
public void parse_emptyTypePrefixArgs_returnsSearchCommand() {
String input = " " + PREFIX_TYPE + " ";
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(input,
PREFIX_TITLE, PREFIX_TYPE, PREFIX_DETAILS, PREFIX_TAG);
SearchCommand expectedSearchCommand = new SearchCommand(new SourceContainsKeywordsPredicate(argMultimap));
assertParseSuccess(parser, " " + PREFIX_TYPE + " ", expectedSearchCommand);
}
@Test
public void parse_emptyDetailPrefixArgs_returnsSearchCommand() {
String input = " " + PREFIX_DETAILS + " ";
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(input,
PREFIX_TITLE, PREFIX_TYPE, PREFIX_DETAILS, PREFIX_TAG);
SearchCommand expectedSearchCommand = new SearchCommand(new SourceContainsKeywordsPredicate(argMultimap));
assertParseSuccess(parser, " " + PREFIX_DETAILS + " ", expectedSearchCommand);
}
@Test
public void parse_emptyTagPrefixArgs_returnsSearchCommand() {
String input = " " + PREFIX_TAG + " ";
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(input,
PREFIX_TITLE, PREFIX_TYPE, PREFIX_DETAILS, PREFIX_TAG);
SearchCommand expectedSearchCommand = new SearchCommand(new SourceContainsKeywordsPredicate(argMultimap));
assertParseSuccess(parser, " " + PREFIX_TAG + " ", expectedSearchCommand);
}
@Test
public void parse_validSingleArg_returnsSearchCommand() {
String input = TITLE_DESC_ENGINEERING;
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(input,
PREFIX_TITLE, PREFIX_TYPE, PREFIX_DETAILS, PREFIX_TAG);
// no leading and trailing whitespaces
SearchCommand expectedSearchCommand = new SearchCommand(new SourceContainsKeywordsPredicate(argMultimap));
assertParseSuccess(parser, TITLE_DESC_ENGINEERING, expectedSearchCommand);
// multiple whitespaces between keywords
assertParseSuccess(parser, "\n \t" + TITLE_DESC_ENGINEERING, expectedSearchCommand);
}
@Test
public void parse_validMultipleArgs_returnsSearchCommand() {
String input = TYPE_DESC_ENGINEERING + TYPE_DESC_ENGINEERING;
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(input,
PREFIX_TITLE, PREFIX_TYPE, PREFIX_DETAILS, PREFIX_TAG);
SearchCommand expectedSearchCommand = new SearchCommand(new SourceContainsKeywordsPredicate(argMultimap));
assertParseSuccess(parser, TYPE_DESC_ENGINEERING + TYPE_DESC_ENGINEERING, expectedSearchCommand);
}
@Test
public void parse_validCompoundArgs_returnsSearchCommand() {
String input = TYPE_DESC_ENGINEERING + TAG_DESC_BAR;
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(input,
PREFIX_TITLE, PREFIX_TYPE, PREFIX_DETAILS, PREFIX_TAG);
SearchCommand expectedSearchCommand = new SearchCommand(new SourceContainsKeywordsPredicate(argMultimap));
assertParseSuccess(parser, TYPE_DESC_ENGINEERING + TAG_DESC_BAR, expectedSearchCommand);
}
}