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

Function TestTruncateString

pkg/cli/audit_report_helpers_test.go:70–135  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

68}
69
70func TestTruncateString(t *testing.T) {
71 tests := []struct {
72 name string
73 input string
74 maxLen int
75 expected string
76 }{
77 {
78 name: "string shorter than max length",
79 input: "hello",
80 maxLen: 10,
81 expected: "hello",
82 },
83 {
84 name: "string equal to max length",
85 input: "hello",
86 maxLen: 5,
87 expected: "hello",
88 },
89 {
90 name: "string longer than max length",
91 input: "hello world",
92 maxLen: 8,
93 expected: "hello...",
94 },
95 {
96 name: "max length 3 or less",
97 input: "hello",
98 maxLen: 3,
99 expected: "hel",
100 },
101 {
102 name: "max length 2",
103 input: "hello",
104 maxLen: 2,
105 expected: "he",
106 },
107 {
108 name: "max length 1",
109 input: "hello",
110 maxLen: 1,
111 expected: "h",
112 },
113 {
114 name: "empty string",
115 input: "",
116 maxLen: 10,
117 expected: "",
118 },
119 {
120 name: "unicode string",
121 input: "Hello 世界",
122 maxLen: 9,
123 expected: "Hello ...",
124 },
125 }
126
127 for _, tt := range tests {

Callers

nothing calls this directly

Calls 3

TruncateFunction · 0.92
RunMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected