MCPcopy
hub / github.com/larksuite/cli / TestTruncateStr

Function TestTruncateStr

internal/util/strings_test.go:8–30  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6import "testing"
7
8func TestTruncateStr(t *testing.T) {
9 tests := []struct {
10 name string
11 s string
12 n int
13 want string
14 }{
15 {"short string", "hello", 10, "hello"},
16 {"exact length", "hello", 5, "hello"},
17 {"truncate", "hello world", 5, "hello"},
18 {"empty", "", 5, ""},
19 {"zero limit", "hello", 0, ""},
20 {"negative limit", "hello", -1, ""},
21 {"CJK characters", "你好世界测试", 4, "你好世界"},
22 }
23 for _, tt := range tests {
24 t.Run(tt.name, func(t *testing.T) {
25 if got := TruncateStr(tt.s, tt.n); got != tt.want {
26 t.Errorf("TruncateStr(%q, %d) = %q, want %q", tt.s, tt.n, got, tt.want)
27 }
28 })
29 }
30}
31
32func TestTruncateStrWithEllipsis(t *testing.T) {
33 tests := []struct {

Callers

nothing calls this directly

Calls 2

TruncateStrFunction · 0.70
RunMethod · 0.65

Tested by

no test coverage detected