FPathTests.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 "FPathTests.h"
  17. #import "FPath.h"
  18. @implementation FPathTests
  19. - (void)testContains {
  20. XCTAssertTrue([[[FPath alloc] initWith:@"/"] contains:[[FPath alloc] initWith:@"/a/b/c"]],
  21. @"contains should be correct");
  22. XCTAssertTrue([[[FPath alloc] initWith:@"/a"] contains:[[FPath alloc] initWith:@"/a/b/c"]],
  23. @"contains should be correct");
  24. XCTAssertTrue([[[FPath alloc] initWith:@"/a/b"] contains:[[FPath alloc] initWith:@"/a/b/c"]],
  25. @"contains should be correct");
  26. XCTAssertTrue([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/a/b/c"]],
  27. @"contains should be correct");
  28. XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/a/b"]],
  29. @"contains should be correct");
  30. XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/a"]],
  31. @"contains should be correct");
  32. XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/"]],
  33. @"contains should be correct");
  34. NSArray *pathPieces = @[ @"a", @"b", @"c" ];
  35. XCTAssertTrue([[[FPath alloc] initWithPieces:pathPieces
  36. andPieceNum:1] contains:[[FPath alloc] initWith:@"/b/c"]],
  37. @"contains should be correct");
  38. XCTAssertTrue([[[FPath alloc] initWithPieces:pathPieces
  39. andPieceNum:1] contains:[[FPath alloc] initWith:@"/b/c/d"]],
  40. @"contains should be correct");
  41. XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/b/c"]],
  42. @"contains should be correct");
  43. XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/a/c/b"]],
  44. @"contains should be correct");
  45. XCTAssertFalse([[[FPath alloc] initWithPieces:pathPieces
  46. andPieceNum:1] contains:[[FPath alloc] initWith:@"/a/b/c"]],
  47. @"contains should be correct");
  48. XCTAssertTrue([[[FPath alloc] initWithPieces:pathPieces
  49. andPieceNum:1] contains:[[FPath alloc] initWith:@"/b/c"]],
  50. @"contains should be correct");
  51. XCTAssertTrue([[[FPath alloc] initWithPieces:pathPieces
  52. andPieceNum:1] contains:[[FPath alloc] initWith:@"/b/c/d"]],
  53. @"contains should be correct");
  54. }
  55. - (void)testPopFront {
  56. XCTAssertEqualObjects([[[FPath alloc] initWith:@"/a/b/c"] popFront],
  57. [[FPath alloc] initWith:@"/b/c"], @"should be correct");
  58. XCTAssertEqualObjects([[[[FPath alloc] initWith:@"/a/b/c"] popFront] popFront],
  59. [[FPath alloc] initWith:@"/c"], @"should be correct");
  60. XCTAssertEqualObjects([[[[[FPath alloc] initWith:@"/a/b/c"] popFront] popFront] popFront],
  61. [[FPath alloc] initWith:@"/"], @"should be correct");
  62. XCTAssertEqualObjects(
  63. [[[[[[FPath alloc] initWith:@"/a/b/c"] popFront] popFront] popFront] popFront],
  64. [[FPath alloc] initWith:@"/"], @"should be correct");
  65. }
  66. - (void)testParent {
  67. XCTAssertEqualObjects([[[FPath alloc] initWith:@"/a/b/c"] parent],
  68. [[FPath alloc] initWith:@"/a/b/"], @"should be correct");
  69. XCTAssertEqualObjects([[[[FPath alloc] initWith:@"/a/b/c"] parent] parent],
  70. [[FPath alloc] initWith:@"/a/"], @"should be correct");
  71. XCTAssertEqualObjects([[[[[FPath alloc] initWith:@"/a/b/c"] parent] parent] parent],
  72. [[FPath alloc] initWith:@"/"], @"should be correct");
  73. XCTAssertNil([[[[[[FPath alloc] initWith:@"/a/b/c"] parent] parent] parent] parent],
  74. @"should be correct");
  75. }
  76. - (void)testWireFormat {
  77. XCTAssertEqualObjects(@"/", [[FPath empty] wireFormat]);
  78. XCTAssertEqualObjects(@"a/b/c", [[[FPath alloc] initWith:@"/a/b//c/"] wireFormat]);
  79. XCTAssertEqualObjects(@"b/c", [[[[FPath alloc] initWith:@"/a/b//c/"] popFront] wireFormat]);
  80. }
  81. - (void)testComparison {
  82. NSArray *pathsInOrder = @[
  83. @"1", @"2", @"10", @"a", @"a/1", @"a/2", @"a/10", @"a/a", @"a/aa", @"a/b", @"a/b/c", @"b",
  84. @"b/a"
  85. ];
  86. for (NSInteger i = 0; i < pathsInOrder.count; i++) {
  87. FPath *path1 = PATH(pathsInOrder[i]);
  88. for (NSInteger j = i + 1; j < pathsInOrder.count; j++) {
  89. FPath *path2 = PATH(pathsInOrder[j]);
  90. XCTAssertEqual([path1 compare:path2], NSOrderedAscending);
  91. XCTAssertEqual([path2 compare:path1], NSOrderedDescending);
  92. }
  93. XCTAssertEqual([path1 compare:path1], NSOrderedSame);
  94. }
  95. }
  96. @end