FSTDocumentKeyTests.mm 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "Firestore/Source/Model/FSTDocumentKey.h"
  17. #import <XCTest/XCTest.h>
  18. #include "Firestore/core/src/firebase/firestore/model/document_key.h"
  19. #include "Firestore/core/src/firebase/firestore/model/resource_path.h"
  20. using firebase::firestore::model::DocumentKey;
  21. using firebase::firestore::model::ResourcePath;
  22. NS_ASSUME_NONNULL_BEGIN
  23. @interface FSTDocumentKeyTests : XCTestCase
  24. @end
  25. @implementation FSTDocumentKeyTests
  26. - (void)testConstructor {
  27. ResourcePath path{"rooms", "firestore", "messages", "1"};
  28. FSTDocumentKey *key = [FSTDocumentKey keyWithPath:path];
  29. XCTAssertEqual(path, key.path);
  30. }
  31. - (void)testComparison {
  32. FSTDocumentKey *key1 = [FSTDocumentKey keyWithSegments:{"a", "b", "c", "d"}];
  33. FSTDocumentKey *key2 = [FSTDocumentKey keyWithSegments:{"a", "b", "c", "d"}];
  34. FSTDocumentKey *key3 = [FSTDocumentKey keyWithSegments:{"x", "y", "z", "w"}];
  35. XCTAssertTrue([key1 isEqualToKey:key2]);
  36. XCTAssertFalse([key1 isEqualToKey:key3]);
  37. FSTDocumentKey *empty = [FSTDocumentKey keyWithSegments:{}];
  38. FSTDocumentKey *a = [FSTDocumentKey keyWithSegments:{"a", "a"}];
  39. FSTDocumentKey *b = [FSTDocumentKey keyWithSegments:{"b", "b"}];
  40. FSTDocumentKey *ab = [FSTDocumentKey keyWithSegments:{"a", "a", "b", "b"}];
  41. XCTAssertEqual(NSOrderedAscending, [empty compare:a]);
  42. XCTAssertEqual(NSOrderedAscending, [a compare:b]);
  43. XCTAssertEqual(NSOrderedAscending, [a compare:ab]);
  44. XCTAssertEqual(NSOrderedDescending, [a compare:empty]);
  45. XCTAssertEqual(NSOrderedDescending, [b compare:a]);
  46. XCTAssertEqual(NSOrderedDescending, [ab compare:a]);
  47. }
  48. - (void)testConverter {
  49. const ResourcePath path{"rooms", "firestore", "messages", "1"};
  50. FSTDocumentKey *objcKey = [FSTDocumentKey keyWithPath:path];
  51. XCTAssertEqualObjects(objcKey, (FSTDocumentKey *)(DocumentKey{objcKey}));
  52. DocumentKey cpp_key{path};
  53. XCTAssertEqual(cpp_key, DocumentKey{(FSTDocumentKey *)(cpp_key)});
  54. }
  55. @end
  56. NS_ASSUME_NONNULL_END