go-i18n/language_test.go
Claude 97f9c758d1
chore(ax): AX compliance sweep — banned imports, naming, Good/Bad/Ugly tests
- compose.go: remove fmt import, use local stringer interface + core.Sprint
- hooks.go: replace stdlib log with dappco.re/go/core/log
- localise.go: replace os.Getenv with core.Env
- loader.go: replace strings.CutPrefix with core.HasPrefix/TrimPrefix
- reversal/tokeniser.go: replace strings.Fields with local splitFields helper
- validate.go: rename sb → builder (AX naming)
- calibrate.go, classify.go: rename cfg → configuration (AX naming)
- numbers.go: rename local fmt variable → numberFormat
- All test files: add Good/Bad/Ugly triads per AX test naming convention

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-31 08:42:40 +01:00

110 lines
2.6 KiB
Go

package i18n
import "testing"
func TestGetPluralCategory(t *testing.T) {
tests := []struct {
lang string
n int
want PluralCategory
}{
// English
{"en", 0, PluralOther},
{"en", 1, PluralOne},
{"en", 2, PluralOther},
// French (0 and 1 are singular)
{"fr", 0, PluralOne},
{"fr", 1, PluralOne},
{"fr", 2, PluralOther},
// Russian
{"ru", 1, PluralOne},
{"ru", 2, PluralFew},
{"ru", 5, PluralMany},
{"ru", 11, PluralMany},
{"ru", 21, PluralOne},
{"ru", 22, PluralFew},
// Polish
{"pl", 1, PluralOne},
{"pl", 2, PluralFew},
{"pl", 5, PluralMany},
// Arabic
{"ar", 0, PluralZero},
{"ar", 1, PluralOne},
{"ar", 2, PluralTwo},
{"ar", 5, PluralFew},
{"ar", 11, PluralMany},
{"ar", 100, PluralOther},
// Chinese (always other)
{"zh", 0, PluralOther},
{"zh", 1, PluralOther},
{"zh", 100, PluralOther},
// Fallback for unknown language uses English rules
{"xx", 1, PluralOne},
{"xx", 5, PluralOther},
}
for _, tt := range tests {
t.Run(tt.lang, func(t *testing.T) {
got := GetPluralCategory(tt.lang, tt.n)
if got != tt.want {
t.Errorf("GetPluralCategory(%q, %d) = %v, want %v", tt.lang, tt.n, got, tt.want)
}
})
}
}
func TestGetPluralRule(t *testing.T) {
// Known language
rule := GetPluralRule("en")
if rule == nil {
t.Fatal("GetPluralRule(en) returned nil")
}
if rule(1) != PluralOne {
t.Error("English rule(1) should be PluralOne")
}
// Base language extraction
rule = GetPluralRule("en-US")
if rule(1) != PluralOne {
t.Error("English-US rule(1) should be PluralOne")
}
// Unknown falls back to English
rule = GetPluralRule("xx-YY")
if rule(1) != PluralOne {
t.Error("Unknown rule(1) should fallback to English PluralOne")
}
}
// TestGetPluralCategory_Good verifies German singular follows English rules.
//
// GetPluralCategory("de", 1) // PluralOne
func TestGetPluralCategory_Good(t *testing.T) {
if got := GetPluralCategory("de", 1); got != PluralOne {
t.Errorf("GetPluralCategory(de, 1) = %v, want PluralOne", got)
}
}
// TestGetPluralCategory_Bad verifies an unknown language code uses English rules.
//
// GetPluralCategory("zz", 2) // PluralOther
func TestGetPluralCategory_Bad(t *testing.T) {
if got := GetPluralCategory("zz", 2); got != PluralOther {
t.Errorf("GetPluralCategory(zz, 2) = %v, want PluralOther", got)
}
}
// TestGetPluralCategory_Ugly verifies negative counts don't panic.
//
// GetPluralCategory("en", -1) // PluralOther (falls through)
func TestGetPluralCategory_Ugly(t *testing.T) {
// Negative counts are unusual but must not panic.
got := GetPluralCategory("en", -1)
_ = got // result is implementation-defined; just verify no panic
}