diff --git a/pkg/i18n/compose.go b/pkg/i18n/compose.go index 46337d52..7b59196f 100644 --- a/pkg/i18n/compose.go +++ b/pkg/i18n/compose.go @@ -126,6 +126,14 @@ func (s *Subject) CountInt() int { return s.count } +// CountString returns the count as a string. +func (s *Subject) CountString() string { + if s == nil { + return "1" + } + return fmt.Sprint(s.count) +} + // GenderString returns the grammatical gender. func (s *Subject) GenderString() string { if s == nil { @@ -150,13 +158,13 @@ func (s *Subject) NounString() string { return s.Noun } -// FormalityString returns the formality level. -// Returns FormalityNeutral if not explicitly set. -func (s *Subject) FormalityString() Formality { +// FormalityString returns the formality level as a string. +// Returns "neutral" if not explicitly set. +func (s *Subject) FormalityString() string { if s == nil { - return FormalityNeutral + return FormalityNeutral.String() } - return s.formality + return s.formality.String() } // IsFormal returns true if formal address should be used. diff --git a/pkg/i18n/compose_test.go b/pkg/i18n/compose_test.go index 94e98400..25a7f4fb 100644 --- a/pkg/i18n/compose_test.go +++ b/pkg/i18n/compose_test.go @@ -106,9 +106,15 @@ func TestSubject_Getters(t *testing.T) { var s *Subject assert.Equal(t, "", s.NounString()) assert.Equal(t, 1, s.CountInt()) + assert.Equal(t, "1", s.CountString()) assert.Equal(t, "", s.GenderString()) assert.Equal(t, "", s.LocationString()) }) + + t.Run("CountString", func(t *testing.T) { + s := S("file", "test.go").Count(42) + assert.Equal(t, "42", s.CountString()) + }) } func TestIntentMeta(t *testing.T) { @@ -193,31 +199,31 @@ func TestNewTemplateData(t *testing.T) { func TestSubject_Formality(t *testing.T) { t.Run("default is neutral", func(t *testing.T) { s := S("user", "name") - assert.Equal(t, FormalityNeutral, s.FormalityString()) + assert.Equal(t, "neutral", s.FormalityString()) assert.False(t, s.IsFormal()) assert.False(t, s.IsInformal()) }) t.Run("Formal()", func(t *testing.T) { s := S("user", "name").Formal() - assert.Equal(t, FormalityFormal, s.FormalityString()) + assert.Equal(t, "formal", s.FormalityString()) assert.True(t, s.IsFormal()) }) t.Run("Informal()", func(t *testing.T) { s := S("user", "name").Informal() - assert.Equal(t, FormalityInformal, s.FormalityString()) + assert.Equal(t, "informal", s.FormalityString()) assert.True(t, s.IsInformal()) }) t.Run("Formality() explicit", func(t *testing.T) { s := S("user", "name").Formality(FormalityFormal) - assert.Equal(t, FormalityFormal, s.FormalityString()) + assert.Equal(t, "formal", s.FormalityString()) }) t.Run("nil safety", func(t *testing.T) { var s *Subject - assert.Equal(t, FormalityNeutral, s.FormalityString()) + assert.Equal(t, "neutral", s.FormalityString()) assert.False(t, s.IsFormal()) assert.False(t, s.IsInformal()) })