2023-09-29 10:07:31 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestHello(t *testing.T) {
|
2023-09-29 10:15:35 -04:00
|
|
|
t.Run("saying hello to people", func(t *testing.T) {
|
2023-09-29 10:25:17 -04:00
|
|
|
got := Hello("Chris", "")
|
2023-09-29 10:15:35 -04:00
|
|
|
want := "Hello, Chris"
|
|
|
|
assertCorrectMessage(t, got, want)
|
|
|
|
})
|
|
|
|
t.Run("say 'Hello, World' when an empty string is supplied", func(t *testing.T) {
|
2023-09-29 10:25:17 -04:00
|
|
|
got := Hello("", "")
|
2023-09-29 10:15:35 -04:00
|
|
|
want := "Hello, World"
|
|
|
|
assertCorrectMessage(t, got, want)
|
|
|
|
})
|
2023-09-29 10:25:17 -04:00
|
|
|
t.Run("in Spanish", func(t *testing.T) {
|
|
|
|
got := Hello("Elodie", "Spanish")
|
|
|
|
want := "Hola, Elodie"
|
|
|
|
assertCorrectMessage(t, got, want)
|
|
|
|
})
|
|
|
|
t.Run("in French", func(t *testing.T) {
|
|
|
|
got := Hello("Elise", "French")
|
|
|
|
want := "Bonjour, Elise"
|
|
|
|
assertCorrectMessage(t, got, want)
|
|
|
|
})
|
2023-09-29 10:15:35 -04:00
|
|
|
}
|
2023-09-29 10:07:31 -04:00
|
|
|
|
2023-09-29 10:15:35 -04:00
|
|
|
func assertCorrectMessage(t testing.TB, got, want string) {
|
|
|
|
t.Helper()
|
2023-09-29 10:07:31 -04:00
|
|
|
if got != want {
|
|
|
|
t.Errorf("got %q want %q", got, want)
|
|
|
|
}
|
|
|
|
}
|