2022-01-26 13:12:15 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestHello(t *testing.T) {
|
2022-01-27 18:00:00 +00:00
|
|
|
assertCorrectMessage := func(t testing.TB, got string, want string) {
|
|
|
|
t.Helper()
|
2022-01-26 13:12:15 +00:00
|
|
|
|
2022-01-26 18:00:00 +00:00
|
|
|
if got != want {
|
|
|
|
t.Errorf("got %q want %q", got, want)
|
|
|
|
}
|
2022-01-27 18:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("saying hello to people", func (t *testing.T) {
|
2022-01-27 00:11:38 +00:00
|
|
|
got := Hello("Oliver", "")
|
2022-01-27 18:00:00 +00:00
|
|
|
want := "Hello, Oliver"
|
|
|
|
|
|
|
|
assertCorrectMessage(t, got, want)
|
2022-01-26 18:00:00 +00:00
|
|
|
})
|
2022-01-26 18:00:00 +00:00
|
|
|
|
|
|
|
t.Run("say 'Hello, World' when an empty string is supplied", func (t *testing.T) {
|
2022-01-27 00:11:38 +00:00
|
|
|
got := Hello("", "")
|
2022-01-26 18:00:00 +00:00
|
|
|
want := "Hello, World"
|
|
|
|
|
2022-01-27 18:00:00 +00:00
|
|
|
assertCorrectMessage(t, got, want)
|
2022-01-26 18:00:00 +00:00
|
|
|
})
|
2022-01-27 00:11:38 +00:00
|
|
|
|
|
|
|
t.Run("in Welsh", func (t *testing.T) {
|
|
|
|
got := Hello("Oliver", "Welsh")
|
|
|
|
want := "Helo, Oliver"
|
|
|
|
|
|
|
|
assertCorrectMessage(t, got, want)
|
|
|
|
})
|
2022-01-26 13:12:15 +00:00
|
|
|
}
|