package forgekey import ( "strings" "testing" ) // git's own words survive as the reason: a bare "error:" or "fatal:" line is never the whole reason (the mirror of // jschoubben/car-hunter "is not used: git -C: error:", 2026-10-26), every line that says something is kept, and the // words are bounded. func TestSaidKeepsTheCauseBehindABarePrefix(t *testing.T) { forge := "error: \nerror: User: 22:nox-builder with Key: 30:mesh:ace.mesh-build-go is not authorized to read jschoubben/car-hunter.\nerror: \nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n" for _, c := range []struct{ name, in, want string }{ {"forge refusal", forge, "error: User: 22:nox-builder with Key: 30:mesh:ace.mesh-build-go is not authorized to read jschoubben/car-hunter.; fatal: Could not read from remote repository.; Please make sure you have the correct access rights; and the repository exists."}, {"one line", "fatal: couldn't find remote ref x\n", "fatal: couldn't find remote ref x"}, {"bare prefixes only", "error:\nremote:\n", ""}, {"a colon inside stays", " ENOENT \nfatal: bad: thing\n", "ENOENT; fatal: bad: thing"}, {"empty", "", ""}, } { if got := Said(c.in); got != c.want { t.Errorf("%s: Said = %q, want %q", c.name, got, c.want) } } long := Said(strings.Repeat("é", SaidBound)) if !strings.HasSuffix(long, " …") || len(long) > SaidBound+len(" …") || !strings.HasPrefix(long, "é") { t.Errorf("long: %d bytes, ends %q", len(long), long[len(long)-6:]) } }