Skip to content

Commit 814ab7c

Browse files
committed
Adds basic tests.
1 parent 80dd2a5 commit 814ab7c

File tree

12 files changed

+1112
-47
lines changed

12 files changed

+1112
-47
lines changed

Podfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ target 'RxDataSources' do
1010
common
1111
end
1212

13+
target 'Tests' do
14+
common
15+
end
16+
1317
target 'Example' do
1418
common
1519
end

Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ SPEC CHECKSUMS:
2727
RxCocoa: 5dc35c1bbda792ce1b78544ec293a45a59008781
2828
RxSwift: 00ffe5e4bc528e93765ccf04ab6408e39dd2a602
2929

30-
PODFILE CHECKSUM: 43bd333b10d7dfc5029b1ff3167bbf181e4f3f65
30+
PODFILE CHECKSUM: 1b0f7075764ff8e3c7b3d06fc4b91da00c8f3bcd
3131

32-
COCOAPODS: 1.1.0.rc.2
32+
COCOAPODS: 1.1.1

RxDataSources.xcodeproj/project.pbxproj

Lines changed: 83 additions & 4 deletions
Large diffs are not rendered by default.

Sources/DataSources/Differentiator.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func indexSections<S: AnimatableSectionModelType>(_ sections: [S]) throws -> [S.
113113
print("Section \(section) has already been indexed at \(indexedSections[section.identity]!)")
114114
}
115115
#endif
116-
throw DifferentiatorError.duplicateItem(item: section)
116+
throw DifferentiatorError.duplicateSection(section: section)
117117
}
118118
indexedSections[section.identity] = i
119119
}
@@ -282,9 +282,9 @@ public func differencesForSectionedView<S: AnimatableSectionModelType>(
282282

283283
var sectionCommands = try CommandGenerator<S>.generatorForInitialSections(initialSections, finalSections: finalSections)
284284

285-
result.append(contentsOf: try sectionCommands.generateDeleteSections())
285+
result.append(contentsOf: try sectionCommands.generateDeleteSectionsDeletedItemsAndUpdatedItems())
286286
result.append(contentsOf: try sectionCommands.generateInsertAndMoveSections())
287-
result.append(contentsOf: try sectionCommands.generateNewAndMovedItems())
287+
result.append(contentsOf: try sectionCommands.generateInsertAndMovedItems())
288288

289289
return result
290290
}
@@ -522,7 +522,7 @@ struct CommandGenerator<S: AnimatableSectionModelType> {
522522
return (initialSectionData, finalSectionData)
523523
}
524524

525-
mutating func generateDeleteSections() throws -> [Changeset<S>] {
525+
mutating func generateDeleteSectionsDeletedItemsAndUpdatedItems() throws -> [Changeset<S>] {
526526
var deletedSections = [Int]()
527527
var deletedItems = [ItemPath]()
528528
var updatedItems = [ItemPath]()
@@ -652,7 +652,7 @@ struct CommandGenerator<S: AnimatableSectionModelType> {
652652
)]
653653
}
654654

655-
mutating func generateNewAndMovedItems() throws -> [Changeset<S>] {
655+
mutating func generateInsertAndMovedItems() throws -> [Changeset<S>] {
656656
var insertedItems = [ItemPath]()
657657
var movedItems = [(from: ItemPath, to: ItemPath)]()
658658

Sources/DataSources/ItemPath.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import Foundation
1111
public struct ItemPath {
1212
public let sectionIndex: Int
1313
public let itemIndex: Int
14+
15+
public init(sectionIndex: Int, itemIndex: Int) {
16+
self.sectionIndex = sectionIndex
17+
self.itemIndex = itemIndex
18+
}
1419
}
1520

1621
extension ItemPath : Equatable {
@@ -19,4 +24,12 @@ extension ItemPath : Equatable {
1924

2025
public func == (lhs: ItemPath, rhs: ItemPath) -> Bool {
2126
return lhs.sectionIndex == rhs.sectionIndex && lhs.itemIndex == rhs.itemIndex
22-
}
27+
}
28+
29+
extension ItemPath: Hashable {
30+
31+
public var hashValue: Int {
32+
return sectionIndex.byteSwapped.hashValue ^ itemIndex.hashValue
33+
}
34+
35+
}

0 commit comments

Comments
 (0)