diff --git a/handler_test.go b/handler_test.go index ba65042..bfe2e39 100644 --- a/handler_test.go +++ b/handler_test.go @@ -133,6 +133,11 @@ func TestCountHandler(t *testing.T) { t.Errorf("CountHandler.Handle(file, TranslationContext.Count=3) = %q, want %q", got, "3 files") } + got = h.Handle("i18n.count.file", []any{C("file")}, nil) + if got != "1 file" { + t.Errorf("CountHandler.Handle(file, TranslationContext default count) = %q, want %q", got, "1 file") + } + got = h.Handle("i18n.count.", nil, func() string { return "fallback" }) if got != "fallback" { t.Errorf("CountHandler.Handle(empty) = %q, want %q", got, "fallback") diff --git a/transform.go b/transform.go index 22fb3d0..173a970 100644 --- a/transform.go +++ b/transform.go @@ -31,7 +31,7 @@ func getCount(data any) int { return toInt(c) } } - return 0 + return d.count case map[string]any: if c, ok := d["Count"]; ok { return toInt(c) diff --git a/transform_test.go b/transform_test.go index 15d1cc5..9bed6d8 100644 --- a/transform_test.go +++ b/transform_test.go @@ -30,6 +30,16 @@ func TestGetCount_Good(t *testing.T) { } } +func TestGetCount_Good_TranslationContextDefault(t *testing.T) { + ctx := C("test") + assert.Equal(t, 1, getCount(ctx)) +} + +func TestGetCount_Good_TranslationContextExtraCount(t *testing.T) { + ctx := C("test").Set("Count", 3) + assert.Equal(t, 3, getCount(ctx)) +} + // --- toInt --- func TestToInt_Good(t *testing.T) {