FPathTests.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. {
  21. XCTAssertTrue([[[FPath alloc] initWith:@"/"] contains:[[FPath alloc] initWith:@"/a/b/c"]], @"contains should be correct");
  22. XCTAssertTrue([[[FPath alloc] initWith:@"/a"] contains:[[FPath alloc] initWith:@"/a/b/c"]], @"contains should be correct");
  23. XCTAssertTrue([[[FPath alloc] initWith:@"/a/b"] contains:[[FPath alloc] initWith:@"/a/b/c"]], @"contains should be correct");
  24. XCTAssertTrue([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/a/b/c"]], @"contains should be correct");
  25. XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/a/b"]], @"contains should be correct");
  26. XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/a"]], @"contains should be correct");
  27. XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/"]], @"contains should be correct");
  28. NSArray *pathPieces = @[@"a",@"b",@"c"];
  29. XCTAssertTrue([[[FPath alloc] initWithPieces:pathPieces andPieceNum:1] contains:[[FPath alloc] initWith:@"/b/c"]], @"contains should be correct");
  30. XCTAssertTrue([[[FPath alloc] initWithPieces:pathPieces andPieceNum:1] contains:[[FPath alloc] initWith:@"/b/c/d"]], @"contains should be correct");
  31. XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/b/c"]], @"contains should be correct");
  32. XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/a/c/b"]], @"contains should be correct");
  33. XCTAssertFalse([[[FPath alloc] initWithPieces:pathPieces andPieceNum:1]contains:[[FPath alloc] initWith:@"/a/b/c"]], @"contains should be correct");
  34. XCTAssertTrue([[[FPath alloc] initWithPieces:pathPieces andPieceNum:1] contains:[[FPath alloc] initWith:@"/b/c"]], @"contains should be correct");
  35. XCTAssertTrue([[[FPath alloc] initWithPieces:pathPieces andPieceNum:1] contains:[[FPath alloc] initWith:@"/b/c/d"]], @"contains should be correct");
  36. }
  37. - (void)testPopFront
  38. {
  39. XCTAssertEqualObjects([[[FPath alloc] initWith:@"/a/b/c"] popFront], [[FPath alloc] initWith:@"/b/c"], @"should be correct");
  40. XCTAssertEqualObjects([[[[FPath alloc] initWith:@"/a/b/c"] popFront] popFront], [[FPath alloc] initWith:@"/c"], @"should be correct");
  41. XCTAssertEqualObjects([[[[[FPath alloc] initWith:@"/a/b/c"] popFront] popFront] popFront], [[FPath alloc] initWith:@"/"], @"should be correct");
  42. XCTAssertEqualObjects([[[[[[FPath alloc] initWith:@"/a/b/c"] popFront] popFront] popFront] popFront], [[FPath alloc] initWith:@"/"], @"should be correct");
  43. }
  44. - (void)testParent
  45. {
  46. XCTAssertEqualObjects([[[FPath alloc] initWith:@"/a/b/c"] parent], [[FPath alloc] initWith:@"/a/b/"], @"should be correct");
  47. XCTAssertEqualObjects([[[[FPath alloc] initWith:@"/a/b/c"] parent] parent], [[FPath alloc] initWith:@"/a/"], @"should be correct");
  48. XCTAssertEqualObjects([[[[[FPath alloc] initWith:@"/a/b/c"] parent] parent] parent], [[FPath alloc] initWith:@"/"], @"should be correct");
  49. XCTAssertNil([[[[[[FPath alloc] initWith:@"/a/b/c"] parent] parent] parent] parent], @"should be correct");
  50. }
  51. - (void)testWireFormat
  52. {
  53. XCTAssertEqualObjects(@"/", [[FPath empty] wireFormat]);
  54. XCTAssertEqualObjects(@"a/b/c", [[[FPath alloc] initWith:@"/a/b//c/"] wireFormat]);
  55. XCTAssertEqualObjects(@"b/c", [[[[FPath alloc] initWith:@"/a/b//c/"] popFront] wireFormat]);
  56. }
  57. - (void)testComparison
  58. {
  59. NSArray *pathsInOrder = @[@"1", @"2", @"10", @"a", @"a/1", @"a/2", @"a/10", @"a/a", @"a/aa", @"a/b", @"a/b/c",
  60. @"b", @"b/a"];
  61. for (NSInteger i = 0; i < pathsInOrder.count; i++) {
  62. FPath *path1 = PATH(pathsInOrder[i]);
  63. for (NSInteger j = i + 1; j < pathsInOrder.count; j++) {
  64. FPath *path2 = PATH(pathsInOrder[j]);
  65. XCTAssertEqual([path1 compare:path2], NSOrderedAscending);
  66. XCTAssertEqual([path2 compare:path1], NSOrderedDescending);
  67. }
  68. XCTAssertEqual([path1 compare:path1], NSOrderedSame);
  69. }
  70. }
  71. @end