Skip to content

Commit b33d44a

Browse files
authored
Merge pull request #23 from wokalski/bugfix/#22-identical-arrays
Fixes non-empty diff for identical single item arrays
2 parents 7b621dc + c8e10a0 commit b33d44a

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

Diff for: DiffTests/DiffTests.swift

+5
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ class DiffTests: XCTestCase {
8686
}
8787
}
8888

89+
func testSingleElementArray() {
90+
let changes = "a".diff(to: "a")
91+
XCTAssertEqual(changes.elements.count, 0)
92+
}
93+
8994
func duplicateTraces(from: String, to: String) -> Bool {
9095
let traces = from.characters.diffTraces(to: to.characters)
9196
let tracesSet = Set(traces)

Diff for: Sources/Diff.swift

+9-7
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,15 @@ public extension Collection where Iterator.Element: Equatable {
294294
var item = traces.last!
295295
array.append(item)
296296

297-
for trace in traces.reversed() {
298-
if trace.to.x == item.from.x && trace.to.y == item.from.y {
299-
array.insert(trace, at: 0)
300-
item = trace
301-
302-
if trace.from == Point(x: 0, y: 0) {
303-
break
297+
if item.from != Point(x: 0, y: 0) {
298+
for trace in traces.reversed() {
299+
if trace.to.x == item.from.x && trace.to.y == item.from.y {
300+
array.insert(trace, at: 0)
301+
item = trace
302+
303+
if trace.from == Point(x: 0, y: 0) {
304+
break
305+
}
304306
}
305307
}
306308
}

0 commit comments

Comments
 (0)