Skip to content

Commit c6b8c52

Browse files
authored
Merge pull request #552 from firebase/mrschmidt-clang
Running scripts/style.sh
2 parents dea9c23 + e23236b commit c6b8c52

File tree

2 files changed

+45
-42
lines changed

2 files changed

+45
-42
lines changed

Firestore/Example/Tests/API/FIRQueryTests.m

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,25 @@ - (void)testFilteringWithPredicate {
4242
workerDispatchQueue:nil
4343
firebaseApp:nil];
4444
FSTResourcePath *path = [FSTResourcePath pathWithString:@"foo"];
45-
FIRQuery *query = [FIRQuery referenceWithQuery:[FSTQuery queryWithPath:path]
46-
firestore:firestore];
45+
FIRQuery *query = [FIRQuery referenceWithQuery:[FSTQuery queryWithPath:path] firestore:firestore];
4746
FIRQuery *query1 = [query queryWhereField:@"f" isLessThanOrEqualTo:@1];
48-
FIRQuery *query2 = [query queryFilteredUsingPredicate:
49-
[NSPredicate predicateWithFormat:@"f<=1"]];
50-
FIRQuery *query3 = [[query queryWhereField:@"f1" isLessThan:@2]
51-
queryWhereField:@"f2" isEqualTo:@3];
52-
FIRQuery *query4 = [query queryFilteredUsingPredicate:
53-
[NSPredicate predicateWithFormat:@"f1<2 && f2==3"]];
54-
FIRQuery *query5 = [[[[[query queryWhereField:@"f1" isLessThan:@2]
55-
queryWhereField:@"f2" isEqualTo:@3]
56-
queryWhereField:@"f1" isLessThanOrEqualTo:@"four"]
57-
queryWhereField:@"f1" isGreaterThanOrEqualTo:@"five"]
58-
queryWhereField:@"f1" isGreaterThan:@6];
59-
FIRQuery *query6 = [query queryFilteredUsingPredicate:
60-
[NSPredicate predicateWithFormat:
61-
@"f1<2 && f2==3 && f1<='four' && f1>='five' && f1>6"]];
62-
FIRQuery *query7 = [query queryFilteredUsingPredicate:
63-
[NSPredicate predicateWithFormat:
64-
@"2>f1 && 3==f2 && 'four'>=f1 && 'five'<=f1 && 6<f1"]];
47+
FIRQuery *query2 = [query queryFilteredUsingPredicate:[NSPredicate predicateWithFormat:@"f<=1"]];
48+
FIRQuery *query3 =
49+
[[query queryWhereField:@"f1" isLessThan:@2] queryWhereField:@"f2" isEqualTo:@3];
50+
FIRQuery *query4 =
51+
[query queryFilteredUsingPredicate:[NSPredicate predicateWithFormat:@"f1<2 && f2==3"]];
52+
FIRQuery *query5 =
53+
[[[[[query queryWhereField:@"f1" isLessThan:@2] queryWhereField:@"f2" isEqualTo:@3]
54+
queryWhereField:@"f1"
55+
isLessThanOrEqualTo:@"four"] queryWhereField:@"f1"
56+
isGreaterThanOrEqualTo:@"five"] queryWhereField:@"f1"
57+
isGreaterThan:@6];
58+
FIRQuery *query6 = [query
59+
queryFilteredUsingPredicate:
60+
[NSPredicate predicateWithFormat:@"f1<2 && f2==3 && f1<='four' && f1>='five' && f1>6"]];
61+
FIRQuery *query7 = [query
62+
queryFilteredUsingPredicate:
63+
[NSPredicate predicateWithFormat:@"2>f1 && 3==f2 && 'four'>=f1 && 'five'<=f1 && 6<f1"]];
6564
XCTAssertEqualObjects(query1, query2);
6665
XCTAssertNotEqualObjects(query2, query3);
6766
XCTAssertEqualObjects(query3, query4);

Firestore/Source/API/FIRQuery.m

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,9 @@ - (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path isGreaterThanOrEqualTo:(i
259259
- (FIRQuery *)queryFilteredUsingComparisonPredicate:(NSPredicate *)predicate {
260260
NSComparisonPredicate *comparison = (NSComparisonPredicate *)predicate;
261261
if (comparison.comparisonPredicateModifier != NSDirectPredicateModifier) {
262-
FSTThrowInvalidArgument(@"Invalid query. Predicate cannot have an "
263-
"aggregate modifier.");
262+
FSTThrowInvalidArgument(
263+
@"Invalid query. Predicate cannot have an "
264+
"aggregate modifier.");
264265
}
265266
NSString *path;
266267
id value = nil;
@@ -279,8 +280,7 @@ - (FIRQuery *)queryFilteredUsingComparisonPredicate:(NSPredicate *)predicate {
279280
return [self queryWhereField:path isGreaterThan:value];
280281
case NSGreaterThanOrEqualToPredicateOperatorType:
281282
return [self queryWhereField:path isGreaterThanOrEqualTo:value];
282-
default:
283-
; // Fallback below to throw assertion.
283+
default:; // Fallback below to throw assertion.
284284
}
285285
} else if ([comparison.leftExpression expressionType] == NSConstantValueExpressionType &&
286286
[comparison.rightExpression expressionType] == NSKeyPathExpressionType) {
@@ -297,18 +297,19 @@ - (FIRQuery *)queryFilteredUsingComparisonPredicate:(NSPredicate *)predicate {
297297
return [self queryWhereField:path isLessThan:value];
298298
case NSGreaterThanOrEqualToPredicateOperatorType:
299299
return [self queryWhereField:path isLessThanOrEqualTo:value];
300-
default:
301-
; // Fallback below to throw assertion.
300+
default:; // Fallback below to throw assertion.
302301
}
303302
} else {
304-
FSTThrowInvalidArgument(@"Invalid query. Predicate comparisons must "
305-
"include a key path and a constant.");
303+
FSTThrowInvalidArgument(
304+
@"Invalid query. Predicate comparisons must "
305+
"include a key path and a constant.");
306306
}
307307
// Fallback cases of unsupported comparison operator.
308308
switch (comparison.predicateOperatorType) {
309309
case NSCustomSelectorPredicateOperatorType:
310-
FSTThrowInvalidArgument(@"Invalid query. Custom predicate filters are "
311-
"not supported.");
310+
FSTThrowInvalidArgument(
311+
@"Invalid query. Custom predicate filters are "
312+
"not supported.");
312313
break;
313314
default:
314315
FSTThrowInvalidArgument(@"Invalid query. Operator type %lu is not supported.",
@@ -318,10 +319,10 @@ - (FIRQuery *)queryFilteredUsingComparisonPredicate:(NSPredicate *)predicate {
318319

319320
- (FIRQuery *)queryFilteredUsingCompoundPredicate:(NSPredicate *)predicate {
320321
NSCompoundPredicate *compound = (NSCompoundPredicate *)predicate;
321-
if (compound.compoundPredicateType != NSAndPredicateType ||
322-
compound.subpredicates.count == 0) {
323-
FSTThrowInvalidArgument(@"Invalid query. Only compound queries using AND "
324-
"are supported.");
322+
if (compound.compoundPredicateType != NSAndPredicateType || compound.subpredicates.count == 0) {
323+
FSTThrowInvalidArgument(
324+
@"Invalid query. Only compound queries using AND "
325+
"are supported.");
325326
}
326327
FIRQuery *query = self;
327328
for (NSPredicate *pred in compound.subpredicates) {
@@ -335,16 +336,19 @@ - (FIRQuery *)queryFilteredUsingPredicate:(NSPredicate *)predicate {
335336
return [self queryFilteredUsingComparisonPredicate:predicate];
336337
} else if ([predicate isKindOfClass:[NSCompoundPredicate class]]) {
337338
return [self queryFilteredUsingCompoundPredicate:predicate];
338-
} else if ([predicate isKindOfClass:
339-
[[NSPredicate predicateWithBlock:
340-
^BOOL(id obj, NSDictionary *bindings) { return true; }] class]]) {
341-
FSTThrowInvalidArgument(@"Invalid query. Block-based predicates are not "
342-
"supported. Please use predicateWithFormat to "
343-
"create predicates instead.");
339+
} else if ([predicate isKindOfClass:[[NSPredicate
340+
predicateWithBlock:^BOOL(id obj, NSDictionary *bindings) {
341+
return true;
342+
}] class]]) {
343+
FSTThrowInvalidArgument(
344+
@"Invalid query. Block-based predicates are not "
345+
"supported. Please use predicateWithFormat to "
346+
"create predicates instead.");
344347
} else {
345-
FSTThrowInvalidArgument(@"Invalid query. Expect comparison or compound of "
346-
"comparison predicate. Please use "
347-
"predicateWithFormat to create predicates.");
348+
FSTThrowInvalidArgument(
349+
@"Invalid query. Expect comparison or compound of "
350+
"comparison predicate. Please use "
351+
"predicateWithFormat to create predicates.");
348352
}
349353
}
350354

0 commit comments

Comments
 (0)