diff --git a/hello.go b/hello.go index c72c826..aafd837 100644 --- a/hello.go +++ b/hello.go @@ -2,8 +2,13 @@ package main import "fmt" +const englishHelloPrefix = "Hello, " + func Hello(name string) string { - return "Hello, " + name + if name == "" { + name = "World" + } + return englishHelloPrefix + name } func main() { diff --git a/hello_test.go b/hello_test.go index 957b469..c8a873a 100644 --- a/hello_test.go +++ b/hello_test.go @@ -3,10 +3,20 @@ package main import "testing" func TestHello(t *testing.T) { - got := Hello("Hoborg") - want := "Hello, Hoborg" + t.Run("saying hello to people", func(t *testing.T) { + got := Hello("Hoborg") + want := "Hello, Hoborg" - if got != want { - t.Errorf("got %q want %q", got, want) - } + if got != want { + t.Errorf("got %q want %q", got, want) + } + }) + t.Run("say 'Hello, World' when an empty string is given", func(t *testing.T) { + got := Hello("") + want := "Hello, World" + + if got != want { + t.Errorf("got %q want %q", got, want) + } + }) }