refactor: the server says a count one way, words.Count, for notifications, a wanted match's reason and the duplicate resolver's activity line (M505 #5643)
release / govulncheck (push) Successful in 22s
release / web (push) Successful in 1m35s
release / go (push) Successful in 1m45s
release / integration (push) Successful in 5m41s
release / android (push) Successful in 6m7s
release / Build signed APK (releases and dev) (push) Successful in 6m26s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
release / govulncheck (push) Successful in 22s
release / web (push) Successful in 1m35s
release / go (push) Successful in 1m45s
release / integration (push) Successful in 5m41s
release / android (push) Successful in 6m7s
release / Build signed APK (releases and dev) (push) Successful in 6m26s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
// Package words says counts in English for what the server writes to people:
|
||||
// notifications, emails, the reasons a scan or a match gives.
|
||||
package words
|
||||
|
||||
import "strconv"
|
||||
|
||||
// Count says n with the noun that agrees with it: "1 track", "3 tracks". The
|
||||
// noun may carry its verb ("track went missing" / "tracks went missing").
|
||||
// The web app's plural() is the same thing on the other side (M505).
|
||||
func Count[N ~int | ~int32 | ~int64](n N, one, many string) string {
|
||||
if n == 1 {
|
||||
return "1 " + one
|
||||
}
|
||||
return strconv.FormatInt(int64(n), 10) + " " + many
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package words
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCount(t *testing.T) {
|
||||
cases := []struct {
|
||||
got, want string
|
||||
}{
|
||||
{Count(1, "track", "tracks"), "1 track"},
|
||||
{Count(0, "track", "tracks"), "0 tracks"},
|
||||
{Count(int64(3), "track went missing", "tracks went missing"), "3 tracks went missing"},
|
||||
{Count(int32(-1), "copy", "copies"), "-1 copies"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if c.got != c.want {
|
||||
t.Errorf("got %q, want %q", c.got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user