Add pronunciation tests in spelling_test.go

Added "TestPronounce" function in spelling_test.go file to ensure pronunciation mechanism works as expected. The function tests various cases including no syllables, single syllable, multiple syllables, and non-Koremutake syllables.
This commit is contained in:
Winni Neessen 2024-03-12 18:43:51 +01:00
parent fefb2557fc
commit 4b0437d3b1
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D

View file

@ -110,3 +110,52 @@ func TestSpell(t *testing.T) {
}) })
} }
} }
func TestPronounce(t *testing.T) {
tests := []struct {
name string
syllables []string
want string
wantErr bool
}{
{
name: "Pronounce_NoSyllables",
syllables: []string{},
want: "",
wantErr: false,
},
{
name: "Pronounce_SingleSyllable",
syllables: []string{"me"},
want: "me",
wantErr: false,
},
{
name: "Pronounce_MultipleSyllables",
syllables: []string{"mu", "sa"},
want: "mu-sa",
wantErr: false,
},
{
name: "Pronounce_NonKoremutakeSyllable",
syllables: []string{"ä"},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
config := NewConfig()
g := New(config)
g.syllables = tt.syllables
got, err := g.Pronounce()
if (err != nil) != tt.wantErr {
t.Errorf("Generator.Pronounce() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("Generator.Pronounce() = %v, want %v", got, tt.want)
}
})
}
}