@@ -17,6 +17,7 @@ package com.diffplug.selfie
1717
1818import com.diffplug.selfie.guts.CallStack
1919import com.diffplug.selfie.guts.CommentTracker
20+ import com.diffplug.selfie.guts.SnapshotNotEqualErrorMsg
2021import com.diffplug.selfie.guts.SnapshotSystem
2122import com.diffplug.selfie.guts.TypedPath
2223
@@ -42,13 +43,26 @@ enum class Mode {
4243 internal fun msgSnapshotNotFound () = msg(" Snapshot not found" )
4344 internal fun msgSnapshotNotFoundNoSuchFile (file : TypedPath ) =
4445 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))
4648 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+ }
4862 private fun msg (headline : String ) =
4963 when (this ) {
5064 interactive ->
51- " $headline \n " +
65+ " $headline \n " + ( if (headline.any { it == ' \n ' }) " ──────────────────── \n " else " " ) +
5266 " - update this snapshot by adding `_TODO` to the function name\n " +
5367 " - update all snapshots in this file by adding `//selfieonce` or `//SELFIEWRITE`"
5468 readonly -> headline
0 commit comments