MCPcopy
hub / github.com/docker/compose / TestTruncateLongestTaskID_PreservesValidUTF8

Function TestTruncateLongestTaskID_PreservesValidUTF8

cmd/display/tty_test.go:296–306  ·  view source on GitHub ↗

TestTruncateLongestTaskID_PreservesValidUTF8 verifies that when truncation of a multi-byte UTF-8 taskID is genuinely required, the resulting string remains valid UTF-8. Byte-indexed slicing can land mid-rune and emit replacement characters (�) into the rendered output.

(t *testing.T)

Source from the content-addressed store, hash-verified

294// remains valid UTF-8. Byte-indexed slicing can land mid-rune and emit
295// replacement characters (�) into the rendered output.
296func TestTruncateLongestTaskID_PreservesValidUTF8(t *testing.T) {
297 taskID := "Image 测试测试测试测试" // 14 runes, 30 bytes
298 lines := []lineData{{taskID: taskID}}
299
300 truncateLongestTaskID(lines, 8, 10)
301
302 assert.Assert(t, utf8.ValidString(lines[0].taskID),
303 "truncated taskID must remain valid UTF-8, got %q", lines[0].taskID)
304 assert.Assert(t, strings.HasSuffix(lines[0].taskID, "..."),
305 "truncated taskID should end with ..., got %q", lines[0].taskID)
306}
307
308// TestTruncateProgressSize_PicksWidestLine verifies that dropping the size
309// suffix targets the line currently driving maxBeforeStatusWidth (the only

Callers

nothing calls this directly

Calls 1

truncateLongestTaskIDFunction · 0.85

Tested by

no test coverage detected