port DocumentKey to non-container types of Model/* (#930)

* naively remove FSTPath import and source/test files.

* port FieldPath, part I

* port FieldPath, part II

* port ResourcePath, part I

* port ResourcePath, part II

* the grand commit to fix build errors

* use testutil:: helper instead of those from FSTHelpers

* fix test and lint

* use c_str in errmsg directly

* fix

* fix

* make code clean

* fix integration test I missed

* fix to avoid naming collision in preprocessor

* address changes

* address changes

* address changes

* fix: fieldMask are actually shared with different context.

* address changes

* add converter function between two DocumentKey implementations

* add unit test

* address changes

* fix lint

* using DocumentKey in model except for the container types `FSTDocumentDictionary`, `FSTDocumentKeySet`, and  `FSTDocumentVersionDictionary`

* change other place w.r.t. the use of `DocumentKey` in model

* update parameter of test helpers from NSString to string_view

* revert a temporary change used in debug

* address changes
This commit is contained in:
zxu authored and GitHub committed 2018-03-16 15:42:05 -04:00
1 parent 1395c8202b
commit 4e7296b080
37 files changed
+590 -527

No files matched your search

+17 -16
View File
@@ -58,14 +58,14 @@ FIRFirestore *FSTTestFirestore() {
return sharedInstance;
}
FIRDocumentSnapshot *FSTTestDocSnapshot(NSString *path,
FIRDocumentSnapshot *FSTTestDocSnapshot(const absl::string_view path,
FSTTestSnapshotVersion version,
NSDictionary<NSString *, id> *_Nullable data,
BOOL hasMutations,
BOOL fromCache) {
FSTDocument *doc = data ? FSTTestDoc(path, version, data, hasMutations) : nil;
return [FIRDocumentSnapshot snapshotWithFirestore:FSTTestFirestore()
documentKey:FSTTestDocKey(path)
documentKey:testutil::Key(path)
document:doc
fromCache:fromCache];
}
@@ -82,7 +82,7 @@ FIRDocumentReference *FSTTestDocRef(const absl::string_view path) {
/** A convenience method for creating a query snapshots for tests. */
FIRQuerySnapshot *FSTTestQuerySnapshot(
NSString *path,
const absl::string_view path,
NSDictionary<NSString *, NSDictionary<NSString *, id> *> *oldDocs,
NSDictionary<NSString *, NSDictionary<NSString *, id> *> *docsToAdd,
BOOL hasPendingWrites,
@@ -92,30 +92,31 @@ FIRQuerySnapshot *FSTTestQuerySnapshot(
FSTDocumentSet *oldDocuments = FSTTestDocSet(FSTDocumentComparatorByKey, @[]);
for (NSString *key in oldDocs) {
oldDocuments = [oldDocuments
documentSetByAddingDocument:FSTTestDoc([NSString stringWithFormat:@"%@/%@", path, key], 1,
oldDocs[key], hasPendingWrites)];
documentSetByAddingDocument:FSTTestDoc(util::MakeStringView([NSString
stringWithFormat:@"%s/%@", path.data(), key]),
1, oldDocs[key], hasPendingWrites)];
}
FSTDocumentSet *newDocuments = oldDocuments;
NSArray<FSTDocumentViewChange *> *documentChanges = [NSArray array];
for (NSString *key in docsToAdd) {
FSTDocument *docToAdd = FSTTestDoc([NSString stringWithFormat:@"%@/%@", path, key], 1,
docsToAdd[key], hasPendingWrites);
FSTDocument *docToAdd =
FSTTestDoc(util::MakeStringView([NSString stringWithFormat:@"%s/%@", path.data(), key]), 1,
docsToAdd[key], hasPendingWrites);
newDocuments = [newDocuments documentSetByAddingDocument:docToAdd];
documentChanges = [documentChanges
arrayByAddingObject:[FSTDocumentViewChange
changeWithDocument:docToAdd
type:FSTDocumentViewChangeTypeAdded]];
}
FSTViewSnapshot *viewSnapshot =
[[FSTViewSnapshot alloc] initWithQuery:FSTTestQuery(util::MakeStringView(path))
documents:newDocuments
oldDocuments:oldDocuments
documentChanges:documentChanges
fromCache:fromCache
hasPendingWrites:hasPendingWrites
syncStateChanged:YES];
FSTViewSnapshot *viewSnapshot = [[FSTViewSnapshot alloc] initWithQuery:FSTTestQuery(path)
documents:newDocuments
oldDocuments:oldDocuments
documentChanges:documentChanges
fromCache:fromCache
hasPendingWrites:hasPendingWrites
syncStateChanged:YES];
return [FIRQuerySnapshot snapshotWithFirestore:FSTTestFirestore()
originalQuery:FSTTestQuery(util::MakeStringView(path))
originalQuery:FSTTestQuery(path)
snapshot:viewSnapshot
metadata:metadata];
}