Skip to content

Commit

Permalink
Revert "work around for suffix"
Browse files Browse the repository at this point in the history
This reverts commit 489d50a.
  • Loading branch information
mbrandonw committed Nov 12, 2017
1 parent 489d50a commit 85ec24c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
12 changes: 4 additions & 8 deletions Sources/Diff/Diff.swift
Expand Up @@ -7,10 +7,6 @@ public enum DiffType {
public struct Diff<A> {
public let type: DiffType
public let elements: [A]

public func map<B>(_ f: (A) -> B) -> Diff<B> {
return .init(type: self.type, elements: self.elements.map(f))
}
}

public func diff<A: Hashable>(_ fst: [A], _ snd: [A]) -> [Diff<A>] {
Expand Down Expand Up @@ -87,8 +83,8 @@ public struct Hunk {
}
}

public func chunk(diff diffs: [Diff<String>], context ctx: Int = 4) -> [Hunk] {
func prepending(_ prefix: String) -> (String) -> String {
public func chunk<S: StringProtocol>(diff diffs: [Diff<S>], context ctx: Int = 4) -> [Hunk] {
func prepending(_ prefix: String) -> (S) -> String {
return { prefix + $0 + ($0.hasSuffix(" ") ? "¬" : "") }
}
let changed: (Hunk) -> Bool = { $0.lines.contains(where: { $0.hasPrefix(minus) || $0.hasPrefix(plus) }) }
Expand All @@ -106,11 +102,11 @@ public func chunk(diff diffs: [Diff<String>], context ctx: Int = 4) -> [Hunk] {
fstLen: ctx,
sndIdx: current.sndIdx + current.sndLen + len - ctx,
sndLen: ctx,
lines: (diff.elements.suffix(ctx) as ArraySlice<String>).map(prepending(figureSpace))
lines: (diff.elements.suffix(ctx) as ArraySlice<S>).map(prepending(figureSpace))
)
return (next, changed(hunk) ? hunks + [hunk] : hunks)
case .both where current.lines.isEmpty:
let lines = (diff.elements.suffix(ctx) as ArraySlice<String>).map(prepending(figureSpace))
let lines = (diff.elements.suffix(ctx) as ArraySlice<S>).map(prepending(figureSpace))
let count = lines.count
return (current + Hunk(idx: len - count, len: count, lines: lines), hunks)
case .both:
Expand Down
4 changes: 2 additions & 2 deletions Sources/SnapshotTesting/Diffable.swift
Expand Up @@ -39,8 +39,8 @@ extension String: Diffable {
guard fst != snd else { return nil }

let hunks = chunk(diff: diff(
fst.split(separator: "\n", omittingEmptySubsequences: false).map(String.init),
snd.split(separator: "\n", omittingEmptySubsequences: false).map(String.init)
fst.split(separator: "\n", omittingEmptySubsequences: false),
snd.split(separator: "\n", omittingEmptySubsequences: false)
))
let failure = hunks.flatMap { [$0.patchMark] + $0.lines }.joined(separator: "\n")

Expand Down

0 comments on commit 85ec24c

Please sign in to comment.