feat(cli): add internal/{text,compat} packages and acceptance scaffold (PR-6)
text/ gh-style display-width string helpers (Truncate / FuzzyAgo / Pluralize)
compat/ server-CLI version skew probe (kubectl) + 24h TTL cache (gh internal/update)
acceptance/contract/ helpers_test.go for in-process cobra exec + golden assert
(uses iostreams.SetForTest singleton replacement; no t.Parallel)
cmdutil/errors.go: AllCodes() + ClassifyHTTPErrorOutputs() bridge for the
contract test suite (no behavior change in error handling)
go-runewidth promoted from indirect to direct (used by text.Truncate for
display-width-aware CJK truncation).
acceptance/contract/helpers_test.go forward-references cmd.NewRootCmd which
is exported in PR-7 — that file does not compile until then by design.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package text_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/cli/internal/text"
|
||||
)
|
||||
|
||||
func TestTruncate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
maxWidth int
|
||||
s string
|
||||
want string
|
||||
}{
|
||||
{"no truncate ASCII", 20, "hello", "hello"},
|
||||
{"truncate ASCII", 5, "hello world", "hell…"},
|
||||
{"no truncate CJK", 8, "中文测试", "中文测试"},
|
||||
{"truncate CJK", 5, "中文测试", "中文…"},
|
||||
{"empty", 5, "", ""},
|
||||
{"single char fits", 1, "a", "a"},
|
||||
{"truncate to width 1", 1, "abc", "…"},
|
||||
{"maxWidth zero", 0, "x", ""},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
got := text.Truncate(tt.maxWidth, tt.s)
|
||||
if got != tt.want {
|
||||
t.Errorf("Truncate(%d, %q) = %q, want %q", tt.maxWidth, tt.s, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user