learn-go-with-tests/hello-world/hello_test.go

33 lines
647 B
Go
Raw Normal View History

2025-02-02 02:18:14 +00:00
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)
}
}