(t *testing.T)
| 6 | import "testing" |
| 7 | |
| 8 | func 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 | |
| 32 | func TestTruncateStrWithEllipsis(t *testing.T) { |
| 33 | tests := []struct { |
nothing calls this directly
no test coverage detected