MCPcopy Create free account
hub / github.com/github/gh-aw / TestSpec_PublicAPI_Truncate

Function TestSpec_PublicAPI_Truncate

pkg/stringutil/spec_test.go:19–65  ·  view source on GitHub ↗

TestSpec_PublicAPI_Truncate validates the documented behavior of Truncate as described in the package README.md. Specification: - Truncates s to at most maxLen characters, appending "..." when truncation occurs. - For maxLen ≤ 3 the string is truncated without ellipsis.

(t *testing.T)

Source from the content-addressed store, hash-verified

17// - Truncates s to at most maxLen characters, appending "..." when truncation occurs.
18// - For maxLen ≤ 3 the string is truncated without ellipsis.
19func TestSpec_PublicAPI_Truncate(t *testing.T) {
20 tests := []struct {
21 name string
22 input string
23 maxLen int
24 expected string
25 }{
26 {
27 name: "truncates with ellipsis for maxLen > 3 (documented example)",
28 input: "hello world",
29 maxLen: 8,
30 expected: "hello...",
31 },
32 {
33 name: "no truncation when string fits within maxLen (documented example)",
34 input: "hi",
35 maxLen: 8,
36 expected: "hi",
37 },
38 {
39 name: "maxLen <= 3 truncates without ellipsis",
40 input: "hello world",
41 maxLen: 3,
42 expected: "hel",
43 },
44 {
45 name: "maxLen = 1 truncates without ellipsis",
46 input: "hello",
47 maxLen: 1,
48 expected: "h",
49 },
50 {
51 name: "maxLen = 2 truncates without ellipsis",
52 input: "hello",
53 maxLen: 2,
54 expected: "he",
55 },
56 }
57
58 for _, tt := range tests {
59 t.Run(tt.name, func(t *testing.T) {
60 result := Truncate(tt.input, tt.maxLen)
61 assert.Equal(t, tt.expected, result,
62 "Truncate(%q, %d) should match documented output", tt.input, tt.maxLen)
63 })
64 }
65}
66
67// TestSpec_PublicAPI_NormalizeWhitespace validates the documented behavior of
68// NormalizeWhitespace as described in the package README.md.

Callers

nothing calls this directly

Calls 2

TruncateFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected