diff --git a/DiffTests/DiffTests.swift b/DiffTests/DiffTests.swift index ddad642..0cb878b 100644 --- a/DiffTests/DiffTests.swift +++ b/DiffTests/DiffTests.swift @@ -86,6 +86,11 @@ class DiffTests: XCTestCase { } } + func testSingleElementArray() { + let changes = "a".diff(to: "a") + XCTAssertEqual(changes.elements.count, 0) + } + func duplicateTraces(from: String, to: String) -> Bool { let traces = from.characters.diffTraces(to: to.characters) let tracesSet = Set(traces) diff --git a/Sources/Diff.swift b/Sources/Diff.swift index 09911ce..7047889 100644 --- a/Sources/Diff.swift +++ b/Sources/Diff.swift @@ -294,13 +294,15 @@ public extension Collection where Iterator.Element: Equatable { var item = traces.last! array.append(item) - for trace in traces.reversed() { - if trace.to.x == item.from.x && trace.to.y == item.from.y { - array.insert(trace, at: 0) - item = trace - - if trace.from == Point(x: 0, y: 0) { - break + if item.from != Point(x: 0, y: 0) { + for trace in traces.reversed() { + if trace.to.x == item.from.x && trace.to.y == item.from.y { + array.insert(trace, at: 0) + item = trace + + if trace.from == Point(x: 0, y: 0) { + break + } } } }