mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Fix static analyzer issue with common indexes algorithm in _asdk_commonIndexesWithArray:
The issue was: The left operand of '>=' is a garbage value in else if check for lengths[i+1][j] ... I had to rewrite the algorithm to quiet the static analyzer.
This commit is contained in:
@@ -10,13 +10,58 @@
|
||||
|
||||
#import "NSArray+Diffing.h"
|
||||
|
||||
@interface NSArray (ArrayDiffingTests)
|
||||
- (NSIndexSet *)_asdk_commonIndexesWithArray:(NSArray *)array compareBlock:(BOOL (^)(id lhs, id rhs))comparison;
|
||||
@end
|
||||
|
||||
@interface ArrayDiffingTests : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation ArrayDiffingTests
|
||||
|
||||
- (void)testDiffing {
|
||||
- (void)testDiffingCommonIndexes
|
||||
{
|
||||
NSArray<NSArray *> *tests = @[
|
||||
@[
|
||||
@[@"bob", @"alice", @"dave"],
|
||||
@[@"bob", @"alice", @"dave", @"gary"],
|
||||
@[@0, @1, @2]
|
||||
],
|
||||
@[
|
||||
@[@"bob", @"alice", @"dave"],
|
||||
@[@"bob", @"gary", @"dave"],
|
||||
@[@0, @2]
|
||||
],
|
||||
@[
|
||||
@[@"bob", @"alice"],
|
||||
@[@"gary", @"dave"],
|
||||
@[],
|
||||
],
|
||||
@[
|
||||
@[@"bob", @"alice", @"dave"],
|
||||
@[],
|
||||
@[],
|
||||
],
|
||||
@[
|
||||
@[],
|
||||
@[@"bob", @"alice", @"dave"],
|
||||
@[],
|
||||
],
|
||||
];
|
||||
|
||||
for (NSArray *test in tests) {
|
||||
NSIndexSet *indexSet = [test[0] _asdk_commonIndexesWithArray:test[1] compareBlock:^BOOL(id lhs, id rhs) {
|
||||
return [lhs isEqual:rhs];
|
||||
}];
|
||||
|
||||
for (NSNumber *index in (NSArray *)test[2]) {
|
||||
XCTAssert([indexSet containsIndex:[index integerValue]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testDiffingInsertionsAndDeletions {
|
||||
NSArray<NSArray *> *tests = @[
|
||||
@[
|
||||
@[@"bob", @"alice", @"dave"],
|
||||
|
||||
Reference in New Issue
Block a user