learn-go-with-tests/hello-world/hello_test.go
2025-02-01 21:18:14 -05:00

32 lines
647 B
Go

package main
import "testing"
func TestHello(t *testing.T) {
t.Run("say hello to given name", func(t *testing.T) {
got := Hello("Judas", "")
want := "Hello, Judas"
assertCorrectMessage(t, got, want)
})
t.Run("hello world on empty string", func(t *testing.T) {
got := Hello("", "")
want := "Hello, world"
assertCorrectMessage(t, got, want)
})
t.Run("spanish", func(t *testing.T) {
got := Hello("Marjorie", "Spanish")
want := "Hola, Marjorie"
assertCorrectMessage(t, got, want)
})
}
func assertCorrectMessage(t testing.TB, got, want string) {
t.Helper()
if got != want {
t.Errorf("got %q want %q", got, want)
}
}