summaryrefslogtreecommitdiff
path: root/assert/equal_test.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2026-06-22 11:37:02 +0200
committerStefan Majewsky <majewsky@gmx.net>2026-06-22 11:38:31 +0200
commit8804729561d8e5edd7179f494d89c620459d319f (patch)
treea6d2979a13c04dff42c3d9874c171531dd30b081 /assert/equal_test.go
parent99fd6c3185e810eb8b18c5f3fe582a3e91463608 (diff)
downloadgo-gg-8804729561d8e5edd7179f494d89c620459d319f.tar.gz
assert: represent string literals with backticks when appropriate
Diffstat (limited to 'assert/equal_test.go')
-rw-r--r--assert/equal_test.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/assert/equal_test.go b/assert/equal_test.go
index df6fd70..3872ab7 100644
--- a/assert/equal_test.go
+++ b/assert/equal_test.go
@@ -31,6 +31,19 @@ func TestEqual(t *testing.T) {
assert.Equal(t, false, true)
}, `expected true, but got false`)
+ // scalars: check that string values are formatted with backticks when it makes the output nicer
+ expectErrors(t, func(t assert.TestingTB) {
+ assert.Equal(t, "bar", "foo")
+ assert.Equal(t, "Please run `rm -rf /`.", "Please run `echo hello`.")
+ assert.Equal(t, `{"foo":1,"bar":3}`, `{"foo":1,"bar":2}`)
+ assert.Equal(t, "\x1B[1;31mError\x1B[0m", "\x1B[1;32mSuccess\x1B[0m")
+ }, strings.Join([]string{
+ `expected "foo", but got "bar"`,
+ "expected \"Please run `echo hello`.\", but got \"Please run `rm -rf /`.\"",
+ "expected `{\"foo\":1,\"bar\":2}`, but got `{\"foo\":1,\"bar\":3}`",
+ `expected "\x1b[1;32mSuccess\x1b[0m", but got "\x1b[1;31mError\x1b[0m"`,
+ }, "\n"))
+
// basic test for slices
correctSlice := []int{1, 2, 3}
wrongSlice := []int{1, 42, 3}