Skip to content

Commit

Permalink
Fix failure diff output (#13)
Browse files Browse the repository at this point in the history
It read in the incorrect order.
  • Loading branch information
stephencelis authored Nov 14, 2023
1 parent b2640f4 commit 10dcef3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "5b356adceabff6ca027f6574aac79e9fee145d26",
"version" : "1.14.1"
"revision" : "4862d48562483d274a2ac7522d905c9237a31a48",
"version" : "1.15.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/apple/swift-syntax.git", from: "509.0.0"),
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.14.1"),
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.15.0"),
],
targets: [
.target(
Expand Down
44 changes: 22 additions & 22 deletions Sources/MacroTesting/AssertMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public func assertMacro(
of: diagnostics,
as: ._lines,
message: """
Diagnostic output (\(actualPrefix)) differed from expected output (\(expectedPrefix)). \
Diagnostic output (\(newPrefix)) differed from expected output (\(oldPrefix)). \
Difference: …
""",
syntaxDescriptor: InlineSnapshotSyntaxDescriptor(
Expand Down Expand Up @@ -259,7 +259,7 @@ public func assertMacro(
of: fixedSourceFile.description.trimmingCharacters(in: .newlines),
as: ._lines,
message: """
Fixed output (\(actualPrefix)) differed from expected output (\(expectedPrefix)). \
Fixed output (\(newPrefix)) differed from expected output (\(oldPrefix)). \
Difference: …
""",
syntaxDescriptor: InlineSnapshotSyntaxDescriptor(
Expand Down Expand Up @@ -303,7 +303,7 @@ public func assertMacro(
of: expandedSourceFile.description.trimmingCharacters(in: .newlines),
as: ._lines,
message: """
Expanded output (\(actualPrefix)) differed from expected output (\(expectedPrefix)). \
Expanded output (\(newPrefix)) differed from expected output (\(oldPrefix)). \
Difference: …
""",
syntaxDescriptor: InlineSnapshotSyntaxDescriptor(
Expand Down Expand Up @@ -497,13 +497,13 @@ extension Snapshotting where Value == String, Format == String {
diffing: Diffing(
toData: { Data($0.utf8) },
fromData: { String(decoding: $0, as: UTF8.self) }
) { actual, expected in
guard expected != actual else { return nil }
) { old, new in
guard old != new else { return nil }

let actualLines = actual.split(separator: "\n", omittingEmptySubsequences: false)
let newLines = new.split(separator: "\n", omittingEmptySubsequences: false)

let expectedLines = expected.split(separator: "\n", omittingEmptySubsequences: false)
let difference = actualLines.difference(from: expectedLines)
let oldLines = old.split(separator: "\n", omittingEmptySubsequences: false)
let difference = newLines.difference(from: oldLines)

var result = ""

Expand All @@ -519,20 +519,20 @@ extension Snapshotting where Value == String, Format == String {
}
}

var expectedLine = 0
var actualLine = 0
var oldLine = 0
var newLine = 0

while expectedLine < expectedLines.count || actualLine < actualLines.count {
if let removal = removals[expectedLine] {
result += "\(expectedPrefix) \(removal)\n"
expectedLine += 1
} else if let insertion = insertions[actualLine] {
result += "\(actualPrefix) \(insertion)\n"
actualLine += 1
while oldLine < oldLines.count || newLine < newLines.count {
if let removal = removals[oldLine] {
result += "\(oldPrefix) \(removal)\n"
oldLine += 1
} else if let insertion = insertions[newLine] {
result += "\(newPrefix) \(insertion)\n"
newLine += 1
} else {
result += "\(prefix) \(expectedLines[expectedLine])\n"
expectedLine += 1
actualLine += 1
result += "\(prefix) \(oldLines[oldLine])\n"
oldLine += 1
newLine += 1
}
}

Expand Down Expand Up @@ -644,6 +644,6 @@ private class FixItApplier: SyntaxRewriter {
}
}

private let expectedPrefix = "\u{2212}"
private let actualPrefix = "+"
private let oldPrefix = "\u{2212}"
private let newPrefix = "+"
private let prefix = "\u{2007}"

0 comments on commit 10dcef3

Please sign in to comment.