Files
firebase-ios-sdk/Example/Database/Tests/Unit/FPathTests.m
T

109 lines
5.1 KiB
Objective-C
Raw Normal View History

2017-05-15 12:27:07 -07:00
/*
* Copyright 2017 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import "FPathTests.h"
#import "FPath.h"
@implementation FPathTests
2019-08-05 13:27:47 -07:00
- (void)testContains {
XCTAssertTrue([[[FPath alloc] initWith:@"/"] contains:[[FPath alloc] initWith:@"/a/b/c"]],
@"contains should be correct");
XCTAssertTrue([[[FPath alloc] initWith:@"/a"] contains:[[FPath alloc] initWith:@"/a/b/c"]],
@"contains should be correct");
XCTAssertTrue([[[FPath alloc] initWith:@"/a/b"] contains:[[FPath alloc] initWith:@"/a/b/c"]],
@"contains should be correct");
XCTAssertTrue([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/a/b/c"]],
@"contains should be correct");
2017-06-30 10:47:37 -07:00
2019-08-05 13:27:47 -07:00
XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/a/b"]],
@"contains should be correct");
XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/a"]],
@"contains should be correct");
XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/"]],
@"contains should be correct");
2017-05-15 12:27:07 -07:00
2019-08-05 13:27:47 -07:00
NSArray *pathPieces = @[ @"a", @"b", @"c" ];
2017-05-15 12:27:07 -07:00
2019-08-05 13:27:47 -07:00
XCTAssertTrue([[[FPath alloc] initWithPieces:pathPieces
andPieceNum:1] contains:[[FPath alloc] initWith:@"/b/c"]],
@"contains should be correct");
XCTAssertTrue([[[FPath alloc] initWithPieces:pathPieces
andPieceNum:1] contains:[[FPath alloc] initWith:@"/b/c/d"]],
@"contains should be correct");
2017-06-30 10:47:37 -07:00
2019-08-05 13:27:47 -07:00
XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/b/c"]],
@"contains should be correct");
XCTAssertFalse([[[FPath alloc] initWith:@"/a/b/c"] contains:[[FPath alloc] initWith:@"/a/c/b"]],
@"contains should be correct");
2017-05-15 12:27:07 -07:00
2019-08-05 13:27:47 -07:00
XCTAssertFalse([[[FPath alloc] initWithPieces:pathPieces
andPieceNum:1] contains:[[FPath alloc] initWith:@"/a/b/c"]],
@"contains should be correct");
XCTAssertTrue([[[FPath alloc] initWithPieces:pathPieces
andPieceNum:1] contains:[[FPath alloc] initWith:@"/b/c"]],
@"contains should be correct");
XCTAssertTrue([[[FPath alloc] initWithPieces:pathPieces
andPieceNum:1] contains:[[FPath alloc] initWith:@"/b/c/d"]],
@"contains should be correct");
2017-05-15 12:27:07 -07:00
}
2019-08-05 13:27:47 -07:00
- (void)testPopFront {
XCTAssertEqualObjects([[[FPath alloc] initWith:@"/a/b/c"] popFront],
[[FPath alloc] initWith:@"/b/c"], @"should be correct");
XCTAssertEqualObjects([[[[FPath alloc] initWith:@"/a/b/c"] popFront] popFront],
[[FPath alloc] initWith:@"/c"], @"should be correct");
XCTAssertEqualObjects([[[[[FPath alloc] initWith:@"/a/b/c"] popFront] popFront] popFront],
[[FPath alloc] initWith:@"/"], @"should be correct");
XCTAssertEqualObjects(
[[[[[[FPath alloc] initWith:@"/a/b/c"] popFront] popFront] popFront] popFront],
[[FPath alloc] initWith:@"/"], @"should be correct");
2017-05-15 12:27:07 -07:00
}
2019-08-05 13:27:47 -07:00
- (void)testParent {
XCTAssertEqualObjects([[[FPath alloc] initWith:@"/a/b/c"] parent],
[[FPath alloc] initWith:@"/a/b/"], @"should be correct");
XCTAssertEqualObjects([[[[FPath alloc] initWith:@"/a/b/c"] parent] parent],
[[FPath alloc] initWith:@"/a/"], @"should be correct");
XCTAssertEqualObjects([[[[[FPath alloc] initWith:@"/a/b/c"] parent] parent] parent],
[[FPath alloc] initWith:@"/"], @"should be correct");
XCTAssertNil([[[[[[FPath alloc] initWith:@"/a/b/c"] parent] parent] parent] parent],
@"should be correct");
2017-05-15 12:27:07 -07:00
}
2019-08-05 13:27:47 -07:00
- (void)testWireFormat {
XCTAssertEqualObjects(@"/", [[FPath empty] wireFormat]);
XCTAssertEqualObjects(@"a/b/c", [[[FPath alloc] initWith:@"/a/b//c/"] wireFormat]);
XCTAssertEqualObjects(@"b/c", [[[[FPath alloc] initWith:@"/a/b//c/"] popFront] wireFormat]);
2017-05-15 12:27:07 -07:00
}
2019-08-05 13:27:47 -07:00
- (void)testComparison {
NSArray *pathsInOrder = @[
@"1", @"2", @"10", @"a", @"a/1", @"a/2", @"a/10", @"a/a", @"a/aa", @"a/b", @"a/b/c", @"b",
@"b/a"
];
for (NSInteger i = 0; i < pathsInOrder.count; i++) {
FPath *path1 = PATH(pathsInOrder[i]);
for (NSInteger j = i + 1; j < pathsInOrder.count; j++) {
FPath *path2 = PATH(pathsInOrder[j]);
XCTAssertEqual([path1 compare:path2], NSOrderedAscending);
XCTAssertEqual([path2 compare:path1], NSOrderedDescending);
2017-05-15 12:27:07 -07:00
}
2019-08-05 13:27:47 -07:00
XCTAssertEqual([path1 compare:path1], NSOrderedSame);
}
2017-05-15 12:27:07 -07:00
}
@end