Skip to content

Commit 10dcef3

Browse files
authored
Fix failure diff output (#13)
It read in the incorrect order.
1 parent b2640f4 commit 10dcef3

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let package = Package(
1818
],
1919
dependencies: [
2020
.package(url: "https://github.com/apple/swift-syntax.git", from: "509.0.0"),
21-
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.14.1"),
21+
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.15.0"),
2222
],
2323
targets: [
2424
.target(

Sources/MacroTesting/AssertMacro.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public func assertMacro(
211211
of: diagnostics,
212212
as: ._lines,
213213
message: """
214-
Diagnostic output (\(actualPrefix)) differed from expected output (\(expectedPrefix)). \
214+
Diagnostic output (\(newPrefix)) differed from expected output (\(oldPrefix)). \
215215
Difference: …
216216
""",
217217
syntaxDescriptor: InlineSnapshotSyntaxDescriptor(
@@ -259,7 +259,7 @@ public func assertMacro(
259259
of: fixedSourceFile.description.trimmingCharacters(in: .newlines),
260260
as: ._lines,
261261
message: """
262-
Fixed output (\(actualPrefix)) differed from expected output (\(expectedPrefix)). \
262+
Fixed output (\(newPrefix)) differed from expected output (\(oldPrefix)). \
263263
Difference: …
264264
""",
265265
syntaxDescriptor: InlineSnapshotSyntaxDescriptor(
@@ -303,7 +303,7 @@ public func assertMacro(
303303
of: expandedSourceFile.description.trimmingCharacters(in: .newlines),
304304
as: ._lines,
305305
message: """
306-
Expanded output (\(actualPrefix)) differed from expected output (\(expectedPrefix)). \
306+
Expanded output (\(newPrefix)) differed from expected output (\(oldPrefix)). \
307307
Difference: …
308308
""",
309309
syntaxDescriptor: InlineSnapshotSyntaxDescriptor(
@@ -497,13 +497,13 @@ extension Snapshotting where Value == String, Format == String {
497497
diffing: Diffing(
498498
toData: { Data($0.utf8) },
499499
fromData: { String(decoding: $0, as: UTF8.self) }
500-
) { actual, expected in
501-
guard expected != actual else { return nil }
500+
) { old, new in
501+
guard old != new else { return nil }
502502

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

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

508508
var result = ""
509509

@@ -519,20 +519,20 @@ extension Snapshotting where Value == String, Format == String {
519519
}
520520
}
521521

522-
var expectedLine = 0
523-
var actualLine = 0
522+
var oldLine = 0
523+
var newLine = 0
524524

525-
while expectedLine < expectedLines.count || actualLine < actualLines.count {
526-
if let removal = removals[expectedLine] {
527-
result += "\(expectedPrefix) \(removal)\n"
528-
expectedLine += 1
529-
} else if let insertion = insertions[actualLine] {
530-
result += "\(actualPrefix) \(insertion)\n"
531-
actualLine += 1
525+
while oldLine < oldLines.count || newLine < newLines.count {
526+
if let removal = removals[oldLine] {
527+
result += "\(oldPrefix) \(removal)\n"
528+
oldLine += 1
529+
} else if let insertion = insertions[newLine] {
530+
result += "\(newPrefix) \(insertion)\n"
531+
newLine += 1
532532
} else {
533-
result += "\(prefix) \(expectedLines[expectedLine])\n"
534-
expectedLine += 1
535-
actualLine += 1
533+
result += "\(prefix) \(oldLines[oldLine])\n"
534+
oldLine += 1
535+
newLine += 1
536536
}
537537
}
538538

@@ -644,6 +644,6 @@ private class FixItApplier: SyntaxRewriter {
644644
}
645645
}
646646

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

0 commit comments

Comments
 (0)