diff --git a/hello.go b/hello.go index e08a6cd..836bb32 100644 --- a/hello.go +++ b/hello.go @@ -5,6 +5,10 @@ import "fmt" const englishHelloPrefix = "Hello, " func Hello(name string) string { + if name == "" { + name = "World" + } + return englishHelloPrefix + name } diff --git a/hello_test.go b/hello_test.go index 7f64b7c..52753d4 100644 --- a/hello_test.go +++ b/hello_test.go @@ -11,4 +11,13 @@ func TestHello(t *testing.T) { t.Errorf("got %q want %q", got, want) } }) + + t.Run("say 'Hello, World' when an empty string is supplied", func (t *testing.T) { + got := Hello("") + want := "Hello, World" + + if got != want { + t.Errorf("got %q want %q", got, want) + } + }) }