diff options
author | rsgowman <rgowman@google.com> | 2018-07-11 21:59:49 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-11 21:59:49 -0400 |
commit | 82ef0886bf89339bfe7a1855e697e61959eeb486 (patch) | |
tree | 67869be000dd249cf088ab899d96b250a16c2ca4 /Firestore/Example | |
parent | 7fc953fc6ffa69d159c0523d3902d867fe8c0ca5 (diff) |
Move creation of FSTFilter objects to static create method on FSTFilter. (#1512)
Rather than previously inlining it in the calling code. This is to unify
filter creation across platforms.
(This change involves altering FSTFilter from a protocol to an abstract
class.)
Diffstat (limited to 'Firestore/Example')
-rw-r--r-- | Firestore/Example/Tests/Core/FSTQueryTests.mm | 17 | ||||
-rw-r--r-- | Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm | 5 | ||||
-rw-r--r-- | Firestore/Example/Tests/Util/FSTHelpers.h | 4 | ||||
-rw-r--r-- | Firestore/Example/Tests/Util/FSTHelpers.mm | 13 |
4 files changed, 16 insertions, 23 deletions
diff --git a/Firestore/Example/Tests/Core/FSTQueryTests.mm b/Firestore/Example/Tests/Core/FSTQueryTests.mm index 6118d0f..362a94c 100644 --- a/Firestore/Example/Tests/Core/FSTQueryTests.mm +++ b/Firestore/Example/Tests/Core/FSTQueryTests.mm @@ -287,20 +287,19 @@ NS_ASSUME_NONNULL_BEGIN FSTQuery *baseQuery = FSTTestQuery("collection"); FSTDocument *doc1 = FSTTestDoc("collection/doc", 0, @{ @"tags" : @[ @"foo", @1, @YES ] }, NO); - NSArray<id<FSTFilter>> *matchingFilters = - @[ FSTTestFilter("tags", @"==", @[ @"foo", @1, @YES ]) ]; + NSArray<FSTFilter *> *matchingFilters = @[ FSTTestFilter("tags", @"==", @[ @"foo", @1, @YES ]) ]; - NSArray<id<FSTFilter>> *nonMatchingFilters = @[ + NSArray<FSTFilter *> *nonMatchingFilters = @[ FSTTestFilter("tags", @"==", @"foo"), FSTTestFilter("tags", @"==", @[ @"foo", @1 ]), FSTTestFilter("tags", @"==", @[ @"foo", @YES, @1 ]), ]; - for (id<FSTFilter> filter in matchingFilters) { + for (FSTFilter *filter in matchingFilters) { XCTAssertTrue([[baseQuery queryByAddingFilter:filter] matchesDocument:doc1]); } - for (id<FSTFilter> filter in nonMatchingFilters) { + for (FSTFilter *filter in nonMatchingFilters) { XCTAssertFalse([[baseQuery queryByAddingFilter:filter] matchesDocument:doc1]); } } @@ -311,7 +310,7 @@ NS_ASSUME_NONNULL_BEGIN FSTTestDoc("collection/doc", 0, @{ @"tags" : @{@"foo" : @"foo", @"a" : @0, @"b" : @YES, @"c" : @(NAN)} }, NO); - NSArray<id<FSTFilter>> *matchingFilters = @[ + NSArray<FSTFilter *> *matchingFilters = @[ FSTTestFilter("tags", @"==", @{ @"foo" : @"foo", @"a" : @0, @@ -325,7 +324,7 @@ NS_ASSUME_NONNULL_BEGIN FSTTestFilter("tags.foo", @"==", @"foo") ]; - NSArray<id<FSTFilter>> *nonMatchingFilters = @[ + NSArray<FSTFilter *> *nonMatchingFilters = @[ FSTTestFilter("tags", @"==", @"foo"), FSTTestFilter("tags", @"==", @{ @"foo" : @"foo", @"a" : @0, @@ -333,11 +332,11 @@ NS_ASSUME_NONNULL_BEGIN }) ]; - for (id<FSTFilter> filter in matchingFilters) { + for (FSTFilter *filter in matchingFilters) { XCTAssertTrue([[baseQuery queryByAddingFilter:filter] matchesDocument:doc1]); } - for (id<FSTFilter> filter in nonMatchingFilters) { + for (FSTFilter *filter in nonMatchingFilters) { XCTAssertFalse([[baseQuery queryByAddingFilter:filter] matchesDocument:doc1]); } } diff --git a/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm b/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm index da47aaa..51e99a8 100644 --- a/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm +++ b/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm @@ -476,7 +476,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testEncodesRelationFilter { - FSTRelationFilter *input = FSTTestFilter("item.part.top", @"==", @"food"); + FSTRelationFilter *input = (FSTRelationFilter *)FSTTestFilter("item.part.top", @"==", @"food"); GCFSStructuredQuery_Filter *actual = [self.serializer encodedRelationFilter:input]; GCFSStructuredQuery_Filter *expected = [GCFSStructuredQuery_Filter message]; @@ -488,7 +488,8 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testEncodesArrayContainsFilter { - FSTRelationFilter *input = FSTTestFilter("item.tags", @"array_contains", @"food"); + FSTRelationFilter *input = + (FSTRelationFilter *)FSTTestFilter("item.tags", @"array_contains", @"food"); GCFSStructuredQuery_Filter *actual = [self.serializer encodedRelationFilter:input]; GCFSStructuredQuery_Filter *expected = [GCFSStructuredQuery_Filter message]; diff --git a/Firestore/Example/Tests/Util/FSTHelpers.h b/Firestore/Example/Tests/Util/FSTHelpers.h index 7946c06..8e5a86f 100644 --- a/Firestore/Example/Tests/Util/FSTHelpers.h +++ b/Firestore/Example/Tests/Util/FSTHelpers.h @@ -34,6 +34,7 @@ @class FSTDocumentKeyReference; @class FSTDocumentSet; @class FSTFieldValue; +@class FSTFilter; @class FSTLocalViewChanges; @class FSTPatchMutation; @class FSTQuery; @@ -46,7 +47,6 @@ @class FSTView; @class FSTViewSnapshot; @class FSTObjectValue; -@protocol FSTFilter; NS_ASSUME_NONNULL_BEGIN @@ -242,7 +242,7 @@ FSTQuery *FSTTestQuery(const absl::string_view path); * A convenience method to create a FSTFilter using a string representation for both field * and operator (<, <=, ==, >=, >, array_contains). */ -id<FSTFilter> FSTTestFilter(const absl::string_view field, NSString *op, id value); +FSTFilter *FSTTestFilter(const absl::string_view field, NSString *op, id value); /** A convenience method for creating sort orders. */ FSTSortOrder *FSTTestOrderBy(const absl::string_view field, NSString *direction); diff --git a/Firestore/Example/Tests/Util/FSTHelpers.mm b/Firestore/Example/Tests/Util/FSTHelpers.mm index 8ece82f..58513b0 100644 --- a/Firestore/Example/Tests/Util/FSTHelpers.mm +++ b/Firestore/Example/Tests/Util/FSTHelpers.mm @@ -179,7 +179,7 @@ FSTQuery *FSTTestQuery(const absl::string_view path) { return [FSTQuery queryWithPath:testutil::Resource(path)]; } -id<FSTFilter> FSTTestFilter(const absl::string_view field, NSString *opString, id value) { +FSTFilter *FSTTestFilter(const absl::string_view field, NSString *opString, id value) { const FieldPath path = testutil::Field(field); FSTRelationFilterOperator op; if ([opString isEqualToString:@"<"]) { @@ -199,15 +199,8 @@ id<FSTFilter> FSTTestFilter(const absl::string_view field, NSString *opString, i } FSTFieldValue *data = FSTTestFieldValue(value); - if ([data isEqual:[FSTDoubleValue nanValue]]) { - HARD_ASSERT(op == FSTRelationFilterOperatorEqual, "Must use == with NAN."); - return [[FSTNanFilter alloc] initWithField:path]; - } else if ([data isEqual:[FSTNullValue nullValue]]) { - HARD_ASSERT(op == FSTRelationFilterOperatorEqual, "Must use == with Null."); - return [[FSTNullFilter alloc] initWithField:path]; - } else { - return [FSTRelationFilter filterWithField:path filterOperator:op value:data]; - } + + return [FSTFilter filterWithField:path filterOperator:op value:data]; } FSTSortOrder *FSTTestOrderBy(const absl::string_view field, NSString *direction) { |