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