Skip to content

Commit b2efc81

Browse files
committed
Add tests that show failing duplicate identifier detection
1 parent e4ffaaf commit b2efc81

File tree

1 file changed

+100
-6
lines changed

1 file changed

+100
-6
lines changed

Tests/RxDataSourcesTests/AlgorithmTests.swift

+100-6
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,77 @@ extension AlgorithmTests {
320320

321321
// errors
322322
extension AlgorithmTests {
323-
func testThrowsErrorOnDuplicateItem() {
324-
let initial: [s] = [
323+
func testThrowsErrorOnDuplicateItem_inInitialSections() {
324+
let sections: [s] = [
325+
s(1, [
326+
i(1111, ""),
327+
i(1111, "")
328+
])
329+
]
330+
331+
do {
332+
_ = try Diff.differencesForSectionedView(initialSections: sections, finalSections: sections)
333+
XCTFail("Should throw exception")
334+
}
335+
catch let exception {
336+
guard case let .duplicateItem(item) = exception as! Diff.Error else {
337+
XCTFail("Not required error")
338+
return
339+
}
340+
341+
XCTAssertEqual(item as! i, i(1111, ""))
342+
}
343+
}
344+
345+
func testThrowsErrorOnDuplicateItem_inFinalSections() {
346+
let final: [s] = [
347+
s(1, [
348+
i(1111, ""),
349+
i(1111, "")
350+
])
351+
]
352+
353+
do {
354+
_ = try Diff.differencesForSectionedView(initialSections: [], finalSections: final)
355+
XCTFail("Should throw exception")
356+
}
357+
catch let exception {
358+
guard case let .duplicateItem(item) = exception as! Diff.Error else {
359+
XCTFail("Not required error")
360+
return
361+
}
362+
363+
XCTAssertEqual(item as! i, i(1111, ""))
364+
}
365+
}
366+
367+
func testThrowsErrorOnDuplicateItemInDifferentSection_inInitialSections() {
368+
let sections: [s] = [
369+
s(1, [
370+
i(1111, "")
371+
]),
372+
s(2, [
373+
i(1111, "")
374+
])
375+
376+
]
377+
378+
do {
379+
_ = try Diff.differencesForSectionedView(initialSections: sections, finalSections: sections)
380+
XCTFail("Should throw exception")
381+
}
382+
catch let exception {
383+
guard case let .duplicateItem(item) = exception as! Diff.Error else {
384+
XCTFail("Not required error")
385+
return
386+
}
387+
388+
XCTAssertEqual(item as! i, i(1111, ""))
389+
}
390+
}
391+
392+
func testThrowsErrorOnDuplicateItemInDifferentSection_inFinalSections() {
393+
let final: [s] = [
325394
s(1, [
326395
i(1111, "")
327396
]),
@@ -332,7 +401,7 @@ extension AlgorithmTests {
332401
]
333402

334403
do {
335-
_ = try Diff.differencesForSectionedView(initialSections: initial, finalSections: initial)
404+
_ = try Diff.differencesForSectionedView(initialSections: [], finalSections: final)
336405
XCTFail("Should throw exception")
337406
}
338407
catch let exception {
@@ -345,8 +414,33 @@ extension AlgorithmTests {
345414
}
346415
}
347416

348-
func testThrowsErrorOnDuplicateSection() {
349-
let initial: [s] = [
417+
func testThrowsErrorOnDuplicateSection_inInitialSections() {
418+
let sections: [s] = [
419+
s(1, [
420+
i(1111, "")
421+
]),
422+
s(1, [
423+
i(1112, "")
424+
])
425+
]
426+
427+
do {
428+
_ = try Diff.differencesForSectionedView(initialSections: sections, finalSections: sections)
429+
XCTFail("Should throw exception")
430+
}
431+
catch let exception {
432+
guard case let .duplicateSection(section) = exception as! Diff.Error else {
433+
XCTFail("Not required error")
434+
return
435+
}
436+
437+
XCTAssertEqual(section as! s, s(1, [
438+
i(1112, "")
439+
]))
440+
}
441+
}
442+
func testThrowsErrorOnDuplicateSection_inFinalSections() {
443+
let final: [s] = [
350444
s(1, [
351445
i(1111, "")
352446
]),
@@ -357,7 +451,7 @@ extension AlgorithmTests {
357451
]
358452

359453
do {
360-
_ = try Diff.differencesForSectionedView(initialSections: initial, finalSections: initial)
454+
_ = try Diff.differencesForSectionedView(initialSections: [], finalSections: final)
361455
XCTFail("Should throw exception")
362456
}
363457
catch let exception {

0 commit comments

Comments
 (0)