@@ -17,6 +17,7 @@ package com.diffplug.selfie
17
17
18
18
import com.diffplug.selfie.guts.CallStack
19
19
import com.diffplug.selfie.guts.CommentTracker
20
+ import com.diffplug.selfie.guts.SnapshotNotEqualErrorMsg
20
21
import com.diffplug.selfie.guts.SnapshotSystem
21
22
import com.diffplug.selfie.guts.TypedPath
22
23
@@ -42,13 +43,26 @@ enum class Mode {
42
43
internal fun msgSnapshotNotFound () = msg(" Snapshot not found" )
43
44
internal fun msgSnapshotNotFoundNoSuchFile (file : TypedPath ) =
44
45
msg(" Snapshot not found: no such file $file " )
45
- internal fun msgSnapshotMismatch (expected : String , actual : String ) = msg(" Snapshot mismatch" )
46
+ internal fun msgSnapshotMismatch (expected : String , actual : String ) =
47
+ msg(SnapshotNotEqualErrorMsg .forUnequalStrings(expected, actual))
46
48
internal fun msgSnapshotMismatchBinary (expected : ByteArray , actual : ByteArray ) =
47
- msg(" Snapshot mismatch" )
49
+ msgSnapshotMismatch(expected.toQuotedPrintable(), actual.toQuotedPrintable())
50
+ private fun ByteArray.toQuotedPrintable (): String {
51
+ val sb = StringBuilder ()
52
+ for (byte in this ) {
53
+ val b = byte.toInt() and 0xFF // Make sure byte is treated as unsigned
54
+ if (b in 33 .. 126 && b != 61 ) { // Printable ASCII, except '='
55
+ sb.append(b.toChar())
56
+ } else {
57
+ sb.append(" =" ).append(b.toString(16 ).uppercase().padStart(2 , ' 0' )) // Convert to hex and pad
58
+ }
59
+ }
60
+ return sb.toString()
61
+ }
48
62
private fun msg (headline : String ) =
49
63
when (this ) {
50
64
interactive ->
51
- " $headline \n " +
65
+ " $headline \n " + ( if (headline.any { it == ' \n ' }) " ──────────────────── \n " else " " ) +
52
66
" - update this snapshot by adding `_TODO` to the function name\n " +
53
67
" - update all snapshots in this file by adding `//selfieonce` or `//SELFIEWRITE`"
54
68
readonly -> headline
0 commit comments