92d78dea72
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.
28 lines
498 B
Go
28 lines
498 B
Go
package text_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/Tencent/WeKnora/cli/internal/text"
|
|
)
|
|
|
|
func TestPluralize(t *testing.T) {
|
|
tests := []struct {
|
|
n int
|
|
thing string
|
|
want string
|
|
}{
|
|
{0, "doc", "0 docs"},
|
|
{1, "doc", "1 doc"},
|
|
{2, "doc", "2 docs"},
|
|
{5, "chunk", "5 chunks"},
|
|
{1, "chunk", "1 chunk"},
|
|
}
|
|
for _, tt := range tests {
|
|
got := text.Pluralize(tt.n, tt.thing)
|
|
if got != tt.want {
|
|
t.Errorf("Pluralize(%d, %q) = %q, want %q", tt.n, tt.thing, got, tt.want)
|
|
}
|
|
}
|
|
}
|