feat(i18n): add CountString and fix FormalityString return type
- Add CountString() to return count as string - Fix FormalityString() to return string instead of Formality type - Both Int and String getters now available for count field Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
9645cea7d6
commit
e11b6dc2cf
2 changed files with 24 additions and 10 deletions
|
|
@ -126,6 +126,14 @@ func (s *Subject) CountInt() int {
|
||||||
return s.count
|
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.
|
// GenderString returns the grammatical gender.
|
||||||
func (s *Subject) GenderString() string {
|
func (s *Subject) GenderString() string {
|
||||||
if s == nil {
|
if s == nil {
|
||||||
|
|
@ -150,13 +158,13 @@ func (s *Subject) NounString() string {
|
||||||
return s.Noun
|
return s.Noun
|
||||||
}
|
}
|
||||||
|
|
||||||
// FormalityString returns the formality level.
|
// FormalityString returns the formality level as a string.
|
||||||
// Returns FormalityNeutral if not explicitly set.
|
// Returns "neutral" if not explicitly set.
|
||||||
func (s *Subject) FormalityString() Formality {
|
func (s *Subject) FormalityString() string {
|
||||||
if s == nil {
|
if s == nil {
|
||||||
return FormalityNeutral
|
return FormalityNeutral.String()
|
||||||
}
|
}
|
||||||
return s.formality
|
return s.formality.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsFormal returns true if formal address should be used.
|
// IsFormal returns true if formal address should be used.
|
||||||
|
|
|
||||||
|
|
@ -106,9 +106,15 @@ func TestSubject_Getters(t *testing.T) {
|
||||||
var s *Subject
|
var s *Subject
|
||||||
assert.Equal(t, "", s.NounString())
|
assert.Equal(t, "", s.NounString())
|
||||||
assert.Equal(t, 1, s.CountInt())
|
assert.Equal(t, 1, s.CountInt())
|
||||||
|
assert.Equal(t, "1", s.CountString())
|
||||||
assert.Equal(t, "", s.GenderString())
|
assert.Equal(t, "", s.GenderString())
|
||||||
assert.Equal(t, "", s.LocationString())
|
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) {
|
func TestIntentMeta(t *testing.T) {
|
||||||
|
|
@ -193,31 +199,31 @@ func TestNewTemplateData(t *testing.T) {
|
||||||
func TestSubject_Formality(t *testing.T) {
|
func TestSubject_Formality(t *testing.T) {
|
||||||
t.Run("default is neutral", func(t *testing.T) {
|
t.Run("default is neutral", func(t *testing.T) {
|
||||||
s := S("user", "name")
|
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.IsFormal())
|
||||||
assert.False(t, s.IsInformal())
|
assert.False(t, s.IsInformal())
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Formal()", func(t *testing.T) {
|
t.Run("Formal()", func(t *testing.T) {
|
||||||
s := S("user", "name").Formal()
|
s := S("user", "name").Formal()
|
||||||
assert.Equal(t, FormalityFormal, s.FormalityString())
|
assert.Equal(t, "formal", s.FormalityString())
|
||||||
assert.True(t, s.IsFormal())
|
assert.True(t, s.IsFormal())
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Informal()", func(t *testing.T) {
|
t.Run("Informal()", func(t *testing.T) {
|
||||||
s := S("user", "name").Informal()
|
s := S("user", "name").Informal()
|
||||||
assert.Equal(t, FormalityInformal, s.FormalityString())
|
assert.Equal(t, "informal", s.FormalityString())
|
||||||
assert.True(t, s.IsInformal())
|
assert.True(t, s.IsInformal())
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Formality() explicit", func(t *testing.T) {
|
t.Run("Formality() explicit", func(t *testing.T) {
|
||||||
s := S("user", "name").Formality(FormalityFormal)
|
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) {
|
t.Run("nil safety", func(t *testing.T) {
|
||||||
var s *Subject
|
var s *Subject
|
||||||
assert.Equal(t, FormalityNeutral, s.FormalityString())
|
assert.Equal(t, "neutral", s.FormalityString())
|
||||||
assert.False(t, s.IsFormal())
|
assert.False(t, s.IsFormal())
|
||||||
assert.False(t, s.IsInformal())
|
assert.False(t, s.IsInformal())
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue