From 501cccc6f03247b48d080dd010487e4614135792 Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Tue, 21 Mar 2023 19:12:01 -0700 Subject: [PATCH] Provide full test coverage for IGListDiffKit model description strings Summary: Five model classes in IGListDiffKit: `IGListBatchUpdateData`, `IGListIndexPathResult`, `IGListIndexSetResult`, `IGListMoveIndex`, and `IGListMoveIndexPath` didn't have 100% test coverage because their `description` debug string methods weren't being tested. I added a new unit test file specifically for testing description strings in IGListDiffKit wrote a basic test to verify each one. This brings IGListDiffKit's test coverage back up to 100%. Differential Revision: D44002058 fbshipit-source-id: ebb1bbb3c9a6d380540fc6bbedf5b8c5e5b254f1 --- IGListKit.xcodeproj/project.pbxproj | 8 ++ Tests/IGListDiffDescriptionStringTests.m | 138 +++++++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 Tests/IGListDiffDescriptionStringTests.m diff --git a/IGListKit.xcodeproj/project.pbxproj b/IGListKit.xcodeproj/project.pbxproj index 93f90797..042a8ce4 100644 --- a/IGListKit.xcodeproj/project.pbxproj +++ b/IGListKit.xcodeproj/project.pbxproj @@ -426,6 +426,9 @@ E56B7B3420A9D7100071010C /* IGListCollectionScrollingTraitsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E56B7B3320A9D7100071010C /* IGListCollectionScrollingTraitsTests.m */; }; E56B7B3520A9D7100071010C /* IGListCollectionScrollingTraitsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E56B7B3320A9D7100071010C /* IGListCollectionScrollingTraitsTests.m */; }; E8D312E01FC472A60009FA2F /* IGListContentInsetTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E8D312DF1FC472A60009FA2F /* IGListContentInsetTests.m */; }; + F1855A4C29BC565600558D18 /* IGListDiffDescriptionStringTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F1855A4B29BC565600558D18 /* IGListDiffDescriptionStringTests.m */; }; + F1855A4D29BC565600558D18 /* IGListDiffDescriptionStringTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F1855A4B29BC565600558D18 /* IGListDiffDescriptionStringTests.m */; }; + F1855A4E29BC565600558D18 /* IGListDiffDescriptionStringTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F1855A4B29BC565600558D18 /* IGListDiffDescriptionStringTests.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -735,6 +738,7 @@ E56B7B3320A9D7100071010C /* IGListCollectionScrollingTraitsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGListCollectionScrollingTraitsTests.m; sourceTree = ""; }; E8D312DF1FC472A60009FA2F /* IGListContentInsetTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IGListContentInsetTests.m; sourceTree = ""; }; E980179F5E885E417EB20D55 /* Pods_IGListKit_tvOSTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_IGListKit_tvOSTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + F1855A4B29BC565600558D18 /* IGListDiffDescriptionStringTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGListDiffDescriptionStringTests.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -1147,6 +1151,7 @@ 298DDA231E3B15EE00F76F50 /* IGListCollectionViewLayoutTests.m */, E8D312DF1FC472A60009FA2F /* IGListContentInsetTests.m */, 290DF3761E9323E6009FE456 /* IGListDebuggerTests.m */, + F1855A4B29BC565600558D18 /* IGListDiffDescriptionStringTests.m */, 294AC6311DDE4C19002FCE5D /* IGListDiffResultTests.m */, 88144EE61D870EDC007C7F66 /* IGListDiffSwiftTests.swift */, 88144EE81D870EDC007C7F66 /* IGListDiffTests.m */, @@ -2005,6 +2010,7 @@ 298DD9CF1E3ADD1400F76F50 /* IGListBindingSectionControllerTests.m in Sources */, 885FE22F1DC51B76009CE2B4 /* IGListDiffSwiftTests.swift in Sources */, 885FE23F1DC51B86009CE2B4 /* IGTestObject.m in Sources */, + F1855A4D29BC565600558D18 /* IGListDiffDescriptionStringTests.m in Sources */, 828540511DE40D2D00118B94 /* IGListTestAdapterHorizontalDataSource.m in Sources */, 885FE2371DC51B76009CE2B4 /* IGListWorkingRangeHandlerTests.m in Sources */, 8285404D1DE40C6E00118B94 /* IGListTestHorizontalSection.m in Sources */, @@ -2121,6 +2127,7 @@ 29C5792E1DE0DA89003A149B /* IGTestNibSupplementaryView.m in Sources */, 88144F101D870EDC007C7F66 /* IGListSingleSectionControllerTests.m in Sources */, 88144F121D870EDC007C7F66 /* IGListWorkingRangeHandlerTests.m in Sources */, + F1855A4C29BC565600558D18 /* IGListDiffDescriptionStringTests.m in Sources */, 821BC4D31DB981AB00172ED0 /* IGTestSingleStoryboardItemDataSource.m in Sources */, 298DDA3D1E3B170400F76F50 /* IGLayoutTestSection.m in Sources */, 298DDA091E3AE31D00F76F50 /* IGTestDiffingSectionController.m in Sources */, @@ -2155,6 +2162,7 @@ 88DF89891E010F6500B1B9B4 /* IGListDiffSwiftTests.swift in Sources */, 882BC1321E0118CB0083B311 /* IGTestObject.m in Sources */, 0B3B93611E08E38C008390ED /* IGListBatchUpdateDataTests.m in Sources */, + F1855A4E29BC565600558D18 /* IGListDiffDescriptionStringTests.m in Sources */, 88DF89881E010F5C00B1B9B4 /* IGListDiffResultTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Tests/IGListDiffDescriptionStringTests.m b/Tests/IGListDiffDescriptionStringTests.m new file mode 100644 index 00000000..2b9f632f --- /dev/null +++ b/Tests/IGListDiffDescriptionStringTests.m @@ -0,0 +1,138 @@ +/* + * Copyright (c) Meta Platforms, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import + +#import +#import + +#import "IGListMoveIndexInternal.h" +#import "IGListMoveIndexPathInternal.h" +#import "IGListIndexSetResultInternal.h" +#import "IGListIndexPathResultInternal.h" + +@interface IGListDiffDescriptionStringTests : XCTestCase + +@end + +@implementation IGListDiffDescriptionStringTests + +- (void)test_withBatchUpdateData_thatDescriptionStringIsValid { + NSMutableIndexSet *insertSections = [NSMutableIndexSet indexSet]; + [insertSections addIndex:0]; + [insertSections addIndex:1]; + + NSIndexSet *deleteSections = [NSIndexSet indexSetWithIndex:5]; + IGListMoveIndex *moveSections = [[IGListMoveIndex alloc] initWithFrom:3 to:4]; + NSIndexPath *insertIndexPaths = [NSIndexPath indexPathForItem:0 inSection:0]; + NSIndexPath *deleteIndexPaths = [NSIndexPath indexPathForItem:0 inSection:0]; + IGListMoveIndexPath *moveIndexPaths = [[IGListMoveIndexPath alloc] initWithFrom:[NSIndexPath indexPathForItem:0 inSection:6] + to:[NSIndexPath indexPathForItem:1 inSection:6]]; + + IGListBatchUpdateData *result = [[IGListBatchUpdateData alloc] initWithInsertSections:insertSections + deleteSections:deleteSections + moveSections:[NSSet setWithObject:moveSections] + insertIndexPaths:@[insertIndexPaths] + deleteIndexPaths:@[deleteIndexPaths] + updateIndexPaths:@[] + moveIndexPaths:@[moveIndexPaths]]; + NSString *expectedDescription = [NSString stringWithFormat:@"", result]; + XCTAssertTrue([result.description isEqualToString:expectedDescription]); +} + +- (void)test_withIndexPathResult_thatDescriptionStringIsValid { + NSArray *inserts = @[[NSIndexPath indexPathForItem:0 inSection:0]]; + NSArray *deletes = @[ + [NSIndexPath indexPathForItem:0 inSection:1], + [NSIndexPath indexPathForItem:1 inSection:1] + ]; + NSArray *updates = @[ + [NSIndexPath indexPathForItem:1 inSection:0] + ]; + NSArray *moves = @[ + [[IGListMoveIndexPath alloc] initWithFrom:[NSIndexPath indexPathForItem:1 inSection:3] + to:[NSIndexPath indexPathForItem:2 inSection:3]], + [[IGListMoveIndexPath alloc] initWithFrom:[NSIndexPath indexPathForItem:4 inSection:3] + to:[NSIndexPath indexPathForItem:3 inSection:3]] + ]; + + IGListIndexPathResult *result = [[IGListIndexPathResult alloc] initWithInserts:inserts + deletes:deletes + updates:updates + moves:moves + oldIndexPathMap:[NSMapTable mapTableWithKeyOptions:0 valueOptions:0] + newIndexPathMap:[NSMapTable mapTableWithKeyOptions:0 valueOptions:0]]; + + NSString *expectedDescription = [NSString stringWithFormat:@"", result]; + XCTAssertTrue([result.description isEqualToString:expectedDescription]); +} + +- (void)test_withIndexSetResult_thatDescriptionStringIsValid { + NSMutableIndexSet *inserts = [NSMutableIndexSet indexSet]; + [inserts addIndex:0]; + [inserts addIndex:1]; + + NSMutableIndexSet *deletes = [NSMutableIndexSet indexSet]; + [deletes addIndex:3]; + + NSMutableIndexSet *updates = [NSMutableIndexSet indexSet]; + [updates addIndex:4]; + [updates addIndex:5]; + [updates addIndex:6]; + + NSArray *moves = @[ + [[IGListMoveIndex alloc] initWithFrom:9 to:10], + [[IGListMoveIndex alloc] initWithFrom:11 to:12] + ]; + + IGListIndexSetResult *result = [[IGListIndexSetResult alloc] initWithInserts:inserts + deletes:deletes + updates:updates + moves:moves + oldIndexMap:[NSMapTable mapTableWithKeyOptions:0 valueOptions:0] + newIndexMap:[NSMapTable mapTableWithKeyOptions:0 valueOptions:0]]; + + NSString *expectedDescription = [NSString stringWithFormat:@"", result]; + XCTAssertTrue([result.description isEqualToString:expectedDescription]); +} + +- (void)test_withMoveIndex_thatDescriptionStringIsValid { + IGListMoveIndex *moveIndex = [[IGListMoveIndex alloc] initWithFrom:3 to:4]; + + NSString *expectedDescription = [NSString stringWithFormat:@"", moveIndex]; + XCTAssertTrue([moveIndex.description isEqualToString:expectedDescription]); +} + +- (void)test_withMoveIndexPath_thatDescriptionStringIsValid { + NSIndexPath *from = [NSIndexPath indexPathForItem:1 inSection:1]; + NSIndexPath *to = [NSIndexPath indexPathForItem:3 inSection:1]; + IGListMoveIndexPath *moveIndexPath = [[IGListMoveIndexPath alloc] initWithFrom:from to:to]; + + NSString *expectedDescription = [NSString stringWithFormat:@" {length = 2, path = 1 - 1}; " + "to: {length = 2, path = 1 - 3};>", + moveIndexPath, from, to]; + XCTAssertTrue([moveIndexPath.description isEqualToString:expectedDescription]); +} + +@end