FSTDocumentKeyTests.m 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #import "Firestore/Source/Model/FSTPath.h"
  19. NS_ASSUME_NONNULL_BEGIN
  20. @interface FSTDocumentKeyTests : XCTestCase
  21. @end
  22. @implementation FSTDocumentKeyTests
  23. - (void)testConstructor {
  24. FSTResourcePath *path =
  25. [FSTResourcePath pathWithSegments:@[ @"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