You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.0 KiB
Go

package main
import "testing"
func TestHello(t *testing.T) {
t.Run("saying hello to people", func(t *testing.T) {
got := Hello("Drew", "")
expected := "Hello, Drew"
assertCorrectMessage(t, got, expected)
})
t.Run("say 'Hello, world' when an empty string is supplied", func(t *testing.T) {
got := Hello("", "")
expected := "Hello, World"
assertCorrectMessage(t, got, expected)
})
t.Run("in Spanish", func(t *testing.T) {
got := Hello("Elodie", "Spanish")
expected := "Hola, Elodie"
assertCorrectMessage(t, got, expected)
})
t.Run("in French", func(t *testing.T) {
got := Hello("Drew", "French")
expected := "Bonjour, Drew"
assertCorrectMessage(t, got, expected)
})
}
func assertCorrectMessage(t testing.TB, got, expected string) {
// Needed to tell the test suite that this method is a helper.
// By doing this when it fails the line number reported will be in
// our function call rather than inside our test helper.
t.Helper()
if got != expected {
t.Errorf("got %q, expected %q", got, expected)
}
}