Skip to content

Commit 6ecff9d

Browse files
committed
opaque color
1 parent f55ae3c commit 6ecff9d

20 files changed

Lines changed: 54 additions & 4 deletions

Tests/TextDiffTests/NSTextDiffSnapshotTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import XCTest
55

66
final class NSTextDiffSnapshotTests: XCTestCase {
77
override func invokeTest() {
8-
withSnapshotTesting(record: .missing) {
8+
withSnapshotTesting(record: snapshotRecordMode()) {
99
super.invokeTest()
1010
}
1111
}

Tests/TextDiffTests/SnapshotTestSupport.swift

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ import TextDiff
66
private let snapshotPrecision: Float = 0.995
77
private let snapshotPerceptualPrecision: Float = 0.98
88

9+
func snapshotRecordMode(
10+
default defaultMode: SnapshotTestingConfiguration.Record = .missing
11+
) -> SnapshotTestingConfiguration.Record {
12+
guard
13+
let rawValue = ProcessInfo.processInfo.environment["SNAPSHOT_TESTING_RECORD"],
14+
let recordMode = SnapshotTestingConfiguration.Record(rawValue: rawValue)
15+
else {
16+
return defaultMode
17+
}
18+
19+
return recordMode
20+
}
21+
922
@MainActor
1023
func assertTextDiffSnapshot(
1124
original: String,
@@ -21,11 +34,12 @@ func assertTextDiffSnapshot(
2134
column: UInt = #column
2235
) {
2336
configureSnapshotArtifactsDirectory(filePath: filePath)
37+
let snapshotStyle = stableSnapshotStyle(from: style)
2438

2539
let rootView = TextDiffView(
2640
original: original,
2741
updated: updated,
28-
style: style,
42+
style: snapshotStyle,
2943
mode: mode
3044
)
3145
.frame(width: size.width, height: size.height, alignment: .topLeading)
@@ -71,11 +85,12 @@ func assertNSTextDiffSnapshot(
7185
column: UInt = #column
7286
) {
7387
configureSnapshotArtifactsDirectory(filePath: filePath)
88+
let snapshotStyle = stableSnapshotStyle(from: style)
7489

7590
let diffView = NSTextDiffView(
7691
original: original,
7792
updated: updated,
78-
style: style,
93+
style: snapshotStyle,
7994
mode: mode
8095
)
8196

@@ -124,6 +139,41 @@ private func configureSnapshotArtifactsDirectory(filePath: StaticString) {
124139
setenv("SNAPSHOT_ARTIFACTS", artifactsPath, 1)
125140
}
126141

142+
private func stableSnapshotStyle(from base: TextDiffStyle) -> TextDiffStyle {
143+
var style = base
144+
145+
style.additionsStyle = stableSnapshotChangeStyle(
146+
from: base.additionsStyle,
147+
fillColor: NSColor(
148+
srgbRed: 0.29,
149+
green: 0.73,
150+
blue: 0.37,
151+
alpha: 1
152+
)
153+
)
154+
style.removalsStyle = stableSnapshotChangeStyle(
155+
from: base.removalsStyle,
156+
fillColor: NSColor(
157+
srgbRed: 0.96,
158+
green: 0.42,
159+
blue: 0.42,
160+
alpha: 1
161+
)
162+
)
163+
164+
return style
165+
}
166+
167+
private func stableSnapshotChangeStyle(
168+
from base: TextDiffChangeStyle,
169+
fillColor: NSColor
170+
) -> TextDiffChangeStyle {
171+
var style = base
172+
style.fillColor = fillColor
173+
style.strokeColor = fillColor
174+
return style
175+
}
176+
127177
@MainActor
128178
private func renderSnapshotImage1x(view: NSView, size: CGSize) -> NSImage {
129179
let rep = NSBitmapImageRep(

Tests/TextDiffTests/TextDiffSnapshotTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import XCTest
55

66
final class TextDiffSnapshotTests: XCTestCase {
77
override func invokeTest() {
8-
withSnapshotTesting(record: .missing) {
8+
withSnapshotTesting(record: snapshotRecordMode()) {
99
super.invokeTest()
1010
}
1111
}
-171 Bytes
Loading
-171 Bytes
Loading
-159 Bytes
Loading
-58 Bytes
Loading
-141 Bytes
Loading
-98 Bytes
Loading
26 Bytes
Loading

0 commit comments

Comments
 (0)