FSTDocumentKeyTests.mm 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/resource_path.h"
  19. using firebase::firestore::model::ResourcePath;
  20. NS_ASSUME_NONNULL_BEGIN
  21. @interface FSTDocumentKeyTests : XCTestCase
  22. @end
  23. @implementation FSTDocumentKeyTests
  24. - (void)testConstructor {
  25. ResourcePath path{"rooms", "firestore", "messages", "1"};
  26. FSTDocumentKey *key = [FSTDocumentKey keyWithPath:path];
  27. XCTAssertEqual(path, key.path);
  28. }
  29. - (void)testComparison {
  30. FSTDocumentKey *key1 = [FSTDocumentKey keyWithSegments:{"a", "b", "c", "d"}];
  31. FSTDocumentKey *key2 = [FSTDocumentKey keyWithSegments:{"a", "b", "c", "d"}];
  32. FSTDocumentKey *key3 = [FSTDocumentKey keyWithSegments:{"x", "y", "z", "w"}];
  33. XCTAssertTrue([key1 isEqualToKey:key2]);
  34. XCTAssertFalse([key1 isEqualToKey:key3]);
  35. FSTDocumentKey *empty = [FSTDocumentKey keyWithSegments:{}];
  36. FSTDocumentKey *a = [FSTDocumentKey keyWithSegments:{"a", "a"}];
  37. FSTDocumentKey *b = [FSTDocumentKey keyWithSegments:{"b", "b"}];
  38. FSTDocumentKey *ab = [FSTDocumentKey keyWithSegments:{"a", "a", "b", "b"}];
  39. XCTAssertEqual(NSOrderedAscending, [empty compare:a]);
  40. XCTAssertEqual(NSOrderedAscending, [a compare:b]);
  41. XCTAssertEqual(NSOrderedAscending, [a compare:ab]);
  42. XCTAssertEqual(NSOrderedDescending, [a compare:empty]);
  43. XCTAssertEqual(NSOrderedDescending, [b compare:a]);
  44. XCTAssertEqual(NSOrderedDescending, [ab compare:a]);
  45. }
  46. @end
  47. NS_ASSUME_NONNULL_END