Skip to content

Commit

Permalink
Merge pull request #23 from wokalski/bugfix/#22-identical-arrays
Browse files Browse the repository at this point in the history
Fixes non-empty diff for identical single item arrays
  • Loading branch information
wokalski authored Nov 28, 2016
2 parents 7b621dc + c8e10a0 commit b33d44a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions DiffTests/DiffTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 9 additions & 7 deletions Sources/Diff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
Expand Down

0 comments on commit b33d44a

Please sign in to comment.