don't merge predicate to negated and group

This commit is contained in:
Ari Lazier 2015-11-25 18:32:13 -08:00
parent 6449d34735
commit fbb1f42c6e
3 changed files with 4 additions and 28 deletions

View File

@ -179,9 +179,8 @@ struct ParserState
auto &sub_preds = current_group()->cpnd.sub_predicates;
auto second_last = sub_preds.end() - 2;
if (second_last->type == Predicate::Type::And) {
// if we are in an OR group and second to last predicate group is
// an AND group then move the last predicate inside
if (second_last->type == Predicate::Type::And && !second_last->negate) {
// make a new and group populated with the last two predicates
second_last->cpnd.sub_predicates.push_back(std::move(sub_preds.back()));
sub_preds.pop_back();
}

View File

@ -273,7 +273,8 @@
["ObjectSet", [0, 1], "IntObject", "intCol == 0 || intCol == 1 && intCol >= 1"],
["ObjectSet", [0, 1, 2],"IntObject", "intCol == 0 || intCol == 1 || intCol <= 2"],
["ObjectSet", [0, 1], "IntObject", "intCol == 1 && intCol >= 1 || intCol == 0"],
["ObjectSet", [0, 1], "IntObject", "intCol == 1 || intCol == 0 && intCol <= 0 && intCol >= 0"]
["ObjectSet", [0, 1], "IntObject", "intCol == 1 || intCol == 0 && intCol <= 0 && intCol >= 0"],
["ObjectSet", [0, 1], "IntObject", "intCol == 0 || NOT (intCol == 3 && intCol >= 0) && intCol == 1"]
]
}

View File

@ -942,30 +942,6 @@ module.exports = BaseTest.extend({
XCTAssertThrows([CircleArrayObject objectsInRealm:realm where:@"NONE data.circles = '2'"]);
}
- (void)testCompoundOrQuery {
RLMRealm *realm = [RLMRealm defaultRealm];
[realm beginWriteTransaction];
[PersonObject createInRealm:realm withValue:@[@"Tim", @29]];
[PersonObject createInRealm:realm withValue:@[@"Ari", @33]];
[realm commitWriteTransaction];
XCTAssertEqual(2U, [[PersonObject objectsWhere:@"name == 'Ari' or age < 30"] count]);
XCTAssertEqual(1U, [[PersonObject objectsWhere:@"name == 'Ari' or age > 40"] count]);
}
- (void)testCompoundAndQuery {
RLMRealm *realm = [RLMRealm defaultRealm];
[realm beginWriteTransaction];
[PersonObject createInRealm:realm withValue:@[@"Tim", @29]];
[PersonObject createInRealm:realm withValue:@[@"Ari", @33]];
[realm commitWriteTransaction];
XCTAssertEqual(1U, [[PersonObject objectsWhere:@"name == 'Ari' and age > 30"] count]);
XCTAssertEqual(0U, [[PersonObject objectsWhere:@"name == 'Ari' and age > 40"] count]);
}
- (void)testClass:(Class)class
withNormalCount:(NSUInteger)normalCount
notCount:(NSUInteger)notCount