aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Firestore/Example/Tests/API/FIRQueryTests.m37
-rw-r--r--Firestore/Source/API/FIRQuery.m50
2 files changed, 45 insertions, 42 deletions
diff --git a/Firestore/Example/Tests/API/FIRQueryTests.m b/Firestore/Example/Tests/API/FIRQueryTests.m
index bd0d860..366a6bf 100644
--- a/Firestore/Example/Tests/API/FIRQueryTests.m
+++ b/Firestore/Example/Tests/API/FIRQueryTests.m
@@ -42,26 +42,25 @@ NS_ASSUME_NONNULL_BEGIN
workerDispatchQueue:nil
firebaseApp:nil];
FSTResourcePath *path = [FSTResourcePath pathWithString:@"foo"];
- FIRQuery *query = [FIRQuery referenceWithQuery:[FSTQuery queryWithPath:path]
- firestore:firestore];
+ FIRQuery *query = [FIRQuery referenceWithQuery:[FSTQuery queryWithPath:path] firestore:firestore];
FIRQuery *query1 = [query queryWhereField:@"f" isLessThanOrEqualTo:@1];
- FIRQuery *query2 = [query queryFilteredUsingPredicate:
- [NSPredicate predicateWithFormat:@"f<=1"]];
- FIRQuery *query3 = [[query queryWhereField:@"f1" isLessThan:@2]
- queryWhereField:@"f2" isEqualTo:@3];
- FIRQuery *query4 = [query queryFilteredUsingPredicate:
- [NSPredicate predicateWithFormat:@"f1<2 && f2==3"]];
- FIRQuery *query5 = [[[[[query queryWhereField:@"f1" isLessThan:@2]
- queryWhereField:@"f2" isEqualTo:@3]
- queryWhereField:@"f1" isLessThanOrEqualTo:@"four"]
- queryWhereField:@"f1" isGreaterThanOrEqualTo:@"five"]
- queryWhereField:@"f1" isGreaterThan:@6];
- FIRQuery *query6 = [query queryFilteredUsingPredicate:
- [NSPredicate predicateWithFormat:
- @"f1<2 && f2==3 && f1<='four' && f1>='five' && f1>6"]];
- FIRQuery *query7 = [query queryFilteredUsingPredicate:
- [NSPredicate predicateWithFormat:
- @"2>f1 && 3==f2 && 'four'>=f1 && 'five'<=f1 && 6<f1"]];
+ FIRQuery *query2 = [query queryFilteredUsingPredicate:[NSPredicate predicateWithFormat:@"f<=1"]];
+ FIRQuery *query3 =
+ [[query queryWhereField:@"f1" isLessThan:@2] queryWhereField:@"f2" isEqualTo:@3];
+ FIRQuery *query4 =
+ [query queryFilteredUsingPredicate:[NSPredicate predicateWithFormat:@"f1<2 && f2==3"]];
+ FIRQuery *query5 =
+ [[[[[query queryWhereField:@"f1" isLessThan:@2] queryWhereField:@"f2" isEqualTo:@3]
+ queryWhereField:@"f1"
+ isLessThanOrEqualTo:@"four"] queryWhereField:@"f1"
+ isGreaterThanOrEqualTo:@"five"] queryWhereField:@"f1"
+ isGreaterThan:@6];
+ FIRQuery *query6 = [query
+ queryFilteredUsingPredicate:
+ [NSPredicate predicateWithFormat:@"f1<2 && f2==3 && f1<='four' && f1>='five' && f1>6"]];
+ FIRQuery *query7 = [query
+ queryFilteredUsingPredicate:
+ [NSPredicate predicateWithFormat:@"2>f1 && 3==f2 && 'four'>=f1 && 'five'<=f1 && 6<f1"]];
XCTAssertEqualObjects(query1, query2);
XCTAssertNotEqualObjects(query2, query3);
XCTAssertEqualObjects(query3, query4);
diff --git a/Firestore/Source/API/FIRQuery.m b/Firestore/Source/API/FIRQuery.m
index 9ab854a..70bd51e 100644
--- a/Firestore/Source/API/FIRQuery.m
+++ b/Firestore/Source/API/FIRQuery.m
@@ -259,8 +259,9 @@ addSnapshotListenerInternalWithOptions:(FSTListenOptions *)internalOptions
- (FIRQuery *)queryFilteredUsingComparisonPredicate:(NSPredicate *)predicate {
NSComparisonPredicate *comparison = (NSComparisonPredicate *)predicate;
if (comparison.comparisonPredicateModifier != NSDirectPredicateModifier) {
- FSTThrowInvalidArgument(@"Invalid query. Predicate cannot have an "
- "aggregate modifier.");
+ FSTThrowInvalidArgument(
+ @"Invalid query. Predicate cannot have an "
+ "aggregate modifier.");
}
NSString *path;
id value = nil;
@@ -279,8 +280,7 @@ addSnapshotListenerInternalWithOptions:(FSTListenOptions *)internalOptions
return [self queryWhereField:path isGreaterThan:value];
case NSGreaterThanOrEqualToPredicateOperatorType:
return [self queryWhereField:path isGreaterThanOrEqualTo:value];
- default:
- ; // Fallback below to throw assertion.
+ default:; // Fallback below to throw assertion.
}
} else if ([comparison.leftExpression expressionType] == NSConstantValueExpressionType &&
[comparison.rightExpression expressionType] == NSKeyPathExpressionType) {
@@ -297,18 +297,19 @@ addSnapshotListenerInternalWithOptions:(FSTListenOptions *)internalOptions
return [self queryWhereField:path isLessThan:value];
case NSGreaterThanOrEqualToPredicateOperatorType:
return [self queryWhereField:path isLessThanOrEqualTo:value];
- default:
- ; // Fallback below to throw assertion.
+ default:; // Fallback below to throw assertion.
}
} else {
- FSTThrowInvalidArgument(@"Invalid query. Predicate comparisons must "
- "include a key path and a constant.");
+ FSTThrowInvalidArgument(
+ @"Invalid query. Predicate comparisons must "
+ "include a key path and a constant.");
}
// Fallback cases of unsupported comparison operator.
switch (comparison.predicateOperatorType) {
case NSCustomSelectorPredicateOperatorType:
- FSTThrowInvalidArgument(@"Invalid query. Custom predicate filters are "
- "not supported.");
+ FSTThrowInvalidArgument(
+ @"Invalid query. Custom predicate filters are "
+ "not supported.");
break;
default:
FSTThrowInvalidArgument(@"Invalid query. Operator type %lu is not supported.",
@@ -318,10 +319,10 @@ addSnapshotListenerInternalWithOptions:(FSTListenOptions *)internalOptions
- (FIRQuery *)queryFilteredUsingCompoundPredicate:(NSPredicate *)predicate {
NSCompoundPredicate *compound = (NSCompoundPredicate *)predicate;
- if (compound.compoundPredicateType != NSAndPredicateType ||
- compound.subpredicates.count == 0) {
- FSTThrowInvalidArgument(@"Invalid query. Only compound queries using AND "
- "are supported.");
+ if (compound.compoundPredicateType != NSAndPredicateType || compound.subpredicates.count == 0) {
+ FSTThrowInvalidArgument(
+ @"Invalid query. Only compound queries using AND "
+ "are supported.");
}
FIRQuery *query = self;
for (NSPredicate *pred in compound.subpredicates) {
@@ -335,16 +336,19 @@ addSnapshotListenerInternalWithOptions:(FSTListenOptions *)internalOptions
return [self queryFilteredUsingComparisonPredicate:predicate];
} else if ([predicate isKindOfClass:[NSCompoundPredicate class]]) {
return [self queryFilteredUsingCompoundPredicate:predicate];
- } else if ([predicate isKindOfClass:
- [[NSPredicate predicateWithBlock:
- ^BOOL(id obj, NSDictionary *bindings) { return true; }] class]]) {
- FSTThrowInvalidArgument(@"Invalid query. Block-based predicates are not "
- "supported. Please use predicateWithFormat to "
- "create predicates instead.");
+ } else if ([predicate isKindOfClass:[[NSPredicate
+ predicateWithBlock:^BOOL(id obj, NSDictionary *bindings) {
+ return true;
+ }] class]]) {
+ FSTThrowInvalidArgument(
+ @"Invalid query. Block-based predicates are not "
+ "supported. Please use predicateWithFormat to "
+ "create predicates instead.");
} else {
- FSTThrowInvalidArgument(@"Invalid query. Expect comparison or compound of "
- "comparison predicate. Please use "
- "predicateWithFormat to create predicates.");
+ FSTThrowInvalidArgument(
+ @"Invalid query. Expect comparison or compound of "
+ "comparison predicate. Please use "
+ "predicateWithFormat to create predicates.");
}
}