mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-23 09:18:29 +00:00
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
This commit is contained in:
parent
a41026d93d
commit
501cccc6f0
2 changed files with 146 additions and 0 deletions
|
|
@ -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 = "<group>"; };
|
||||
E8D312DF1FC472A60009FA2F /* IGListContentInsetTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IGListContentInsetTests.m; sourceTree = "<group>"; };
|
||||
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 = "<group>"; };
|
||||
/* 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;
|
||||
|
|
|
|||
138
Tests/IGListDiffDescriptionStringTests.m
Normal file
138
Tests/IGListDiffDescriptionStringTests.m
Normal file
|
|
@ -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 <XCTest/XCTest.h>
|
||||
|
||||
#import <IGListDiffKit/IGListDiff.h>
|
||||
#import <IGListDiffKit/IGListBatchUpdateData.h>
|
||||
|
||||
#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:@"<IGListBatchUpdateData %p; "
|
||||
"deleteSections: 1; "
|
||||
"insertSections: 2; "
|
||||
"moveSections: 1; "
|
||||
"deleteIndexPaths: 1; "
|
||||
"insertIndexPaths: 1; "
|
||||
"updateIndexPaths: 0>", 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:@"<IGListIndexPathResult %p; "
|
||||
"1 inserts; "
|
||||
"2 deletes; "
|
||||
"1 updates; "
|
||||
"2 moves>", 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:@"<IGListIndexSetResult %p; "
|
||||
"2 inserts; "
|
||||
"1 deletes; "
|
||||
"3 updates; "
|
||||
"2 moves>", result];
|
||||
XCTAssertTrue([result.description isEqualToString:expectedDescription]);
|
||||
}
|
||||
|
||||
- (void)test_withMoveIndex_thatDescriptionStringIsValid {
|
||||
IGListMoveIndex *moveIndex = [[IGListMoveIndex alloc] initWithFrom:3 to:4];
|
||||
|
||||
NSString *expectedDescription = [NSString stringWithFormat:@"<IGListMoveIndex %p; "
|
||||
"from: 3; "
|
||||
"to: 4;>", 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:@"<IGListMoveIndexPath %p; "
|
||||
"from: <NSIndexPath: %p> {length = 2, path = 1 - 1}; "
|
||||
"to: <NSIndexPath: %p> {length = 2, path = 1 - 3};>",
|
||||
moveIndexPath, from, to];
|
||||
XCTAssertTrue([moveIndexPath.description isEqualToString:expectedDescription]);
|
||||
}
|
||||
|
||||
@end
|
||||
Loading…
Reference in a new issue