allow 'not' for negation in addition to '!'
This commit is contained in:
@@ -35,7 +35,7 @@ equal : EQUAL ;
|
||||
|
||||
AND : 'and' ;
|
||||
OR : 'or' ;
|
||||
NOT : '!';
|
||||
NOT : 'not' | '!';
|
||||
EQUAL : '=' ;
|
||||
IN : 'in' ;
|
||||
LPAREN : '(' ;
|
||||
|
||||
@@ -200,39 +200,62 @@ public class ProposerTest {
|
||||
}
|
||||
|
||||
public void testProposalOnEmptyKeyPrefix() throws Exception {
|
||||
assertProposals("name=* and ", ResultMode.FULL_VALUES, 11, //
|
||||
new Proposal("name", "name=* and name=* ", true, "name=* and name=", 16), //
|
||||
new Proposal("bird", "name=* and bird=* ", true, "name=* and bird=", 16), //
|
||||
new Proposal("dog", "name=* and dog=* ", true, "name=* and dog=", 15), //
|
||||
assertProposals("name=* and |", ResultMode.FULL_VALUES, //
|
||||
proposal("name", "name=* and name=* ", "name=* and name=|"), //
|
||||
proposal("bird", "name=* and bird=* ", "name=* and bird=|"), //
|
||||
proposal("dog", "name=* and dog=* ", "name=* and dog=|"), //
|
||||
// TODO it is wrong to return those two, because there are no values with name
|
||||
// and type|address, but I'll leave this for now, because this is a different
|
||||
// issue
|
||||
new Proposal("method", "name=* and method=* ", true, "name=* and method=", 18), //
|
||||
new Proposal("source", "name=* and source=* ", true, "name=* and source=", 18)//
|
||||
proposal("method", "name=* and method=* ", "name=* and method=|"), //
|
||||
proposal("source", "name=* and source=* ", "name=* and source=|")//
|
||||
);
|
||||
}
|
||||
|
||||
public void testProposalWithWildcards() throws Exception {
|
||||
assertProposals("name=*im", ResultMode.FULL_VALUES, 8, //
|
||||
new Proposal("Tim", "name=Tim", true, "name=Tim", 8), //
|
||||
new Proposal("Timothy", "name=Timothy", true, "name=Timothy", 12)//
|
||||
);
|
||||
|
||||
assertProposals("name=*im|", ResultMode.FULL_VALUES, //
|
||||
proposal("Tim", "name=Tim", "name=Tim|"), //
|
||||
proposal("Timothy", "name=Timothy", "name=Timothy|")//
|
||||
);
|
||||
}
|
||||
|
||||
public void testProposalWithAndExpression() throws Exception {
|
||||
assertProposals("name=*im and bird=eagle", ResultMode.FULL_VALUES, 8, //
|
||||
new Proposal("Tim", "name=Tim and bird=eagle", true, "name=Tim and bird=eagle", 8), //
|
||||
new Proposal("Timothy", "name=Timothy and bird=eagle", true, "name=Timothy and bird=eagle", 12)//
|
||||
assertProposals("name=*im| and bird=eagle", ResultMode.FULL_VALUES, //
|
||||
proposal("Tim", "name=Tim and bird=eagle", "name=Tim| and bird=eagle"), //
|
||||
proposal("Timothy", "name=Timothy and bird=eagle", "name=Timothy| and bird=eagle")//
|
||||
);
|
||||
|
||||
assertProposals("name=*im and bird=eagle,pigeon", ResultMode.FULL_VALUES, 8, //
|
||||
new Proposal("Tim", "name=Tim and bird=eagle,pigeon", true, "name=Tim and bird=eagle,pigeon", 8), //
|
||||
new Proposal("Timothy", "name=Timothy and bird=eagle,pigeon", true,
|
||||
"name=Timothy and bird=eagle,pigeon", 12)//
|
||||
assertProposals("name=*im| and bird=eagle,pigeon", ResultMode.FULL_VALUES, //
|
||||
proposal("Tim", "name=Tim and bird=eagle,pigeon", "name=Tim| and bird=eagle,pigeon"), //
|
||||
proposal("Timothy", "name=Timothy and bird=eagle,pigeon", "name=Timothy| and bird=eagle,pigeon")//
|
||||
);
|
||||
}
|
||||
|
||||
public void testProposalWithAndNotExpression() throws Exception {
|
||||
assertProposals("name=Tim and ! dog=labrador and bird=|", ResultMode.FULL_VALUES, //
|
||||
proposal("eagle", "name=Tim and ! dog=labrador and bird=eagle",
|
||||
"name=Tim and ! dog=labrador and bird=eagle|") //
|
||||
);
|
||||
assertProposals("name=Tim and not dog=labrador and bird=|", ResultMode.FULL_VALUES, //
|
||||
proposal("eagle", "name=Tim and not dog=labrador and bird=eagle",
|
||||
"name=Tim and not dog=labrador and bird=eagle|") //
|
||||
);
|
||||
}
|
||||
|
||||
private Proposal proposal(final String proposedTag, final String proposedQuery, final String newQuery) {
|
||||
final String newQueryWithoutCaretMarker = newQuery.replace("|", "");
|
||||
final int newCaretPosition = newQuery.indexOf('|');
|
||||
return new Proposal(proposedTag, proposedQuery, true, newQueryWithoutCaretMarker, newCaretPosition);
|
||||
}
|
||||
|
||||
private void assertProposals(final String query, final ResultMode resultMode, final Proposal... expected)
|
||||
throws InterruptedException {
|
||||
final int caretIndex = query.indexOf("|");
|
||||
final String q = query.replace("|", "");
|
||||
assertProposals(q, resultMode, caretIndex, expected);
|
||||
}
|
||||
|
||||
private void assertProposals(final String query, final ResultMode resultMode, final int caretIndex,
|
||||
final Proposal... expected) throws InterruptedException {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user