go-by-test/helloworld/hello_test.go
2024-09-10 11:50:18 +02:00

32 lines
635 B
Go

package helloworld
import "testing"
func TestHello(t *testing.T) {
initDefaults()
t.Run("Hello someone", func(t *testing.T) {
got := Hello("Jason", "English")
exp := "Hello Jason"
assertCorrectMsg(t, got, exp)
})
t.Run("Hello default", func(t *testing.T) {
got := Hello("", "English")
exp := "Hello world"
assertCorrectMsg(t, got, exp)
})
t.Run("Hello default", func(t *testing.T) {
got := Hello("Elodie", "Spanish")
exp := "Hola Elodie"
assertCorrectMsg(t, got, exp)
})
}
func assertCorrectMsg(t testing.TB, got, exp string) {
t.Helper()
if got != exp {
t.Errorf("got %q expected %q", got, exp)
}
}