test(i18n): assert exact Codes() slice instead of len + first entry

Per review feedback: len==3 + codes[0]==zh_cn still passes if Codes()
returns duplicates or drops en_us/ja_jp. Assert the full ordered slice
to lock the user-facing ordering contract.
This commit is contained in:
luozhixiong
2026-05-29 21:00:50 +08:00
parent 5d63d1e2e7
commit 28d37fe080

View File

@@ -3,7 +3,10 @@
package i18n
import "testing"
import (
"slices"
"testing"
)
func TestParse(t *testing.T) {
tests := []struct {
@@ -84,11 +87,9 @@ func TestBase(t *testing.T) {
func TestCodes(t *testing.T) {
codes := Codes()
if len(codes) != 3 {
t.Fatalf("len(Codes()) = %d, want 3", len(codes))
}
if codes[0] != "zh_cn" {
t.Errorf("Codes()[0] = %q, want %q (catalog order)", codes[0], "zh_cn")
want := []string{"zh_cn", "en_us", "ja_jp"}
if !slices.Equal(codes, want) {
t.Fatalf("Codes() = %v, want %v", codes, want)
}
// Every code must round-trip through Parse to itself (canonical).
for _, c := range codes {