Default to the first message if name is empty
This commit is contained in:
parent
4c1fb0ec5a
commit
0f3e93e7d5
4
hello.go
4
hello.go
|
@ -5,6 +5,10 @@ import "fmt"
|
||||||
const englishHelloPrefix = "Hello, "
|
const englishHelloPrefix = "Hello, "
|
||||||
|
|
||||||
func Hello(name string) string {
|
func Hello(name string) string {
|
||||||
|
if name == "" {
|
||||||
|
name = "World"
|
||||||
|
}
|
||||||
|
|
||||||
return englishHelloPrefix + name
|
return englishHelloPrefix + name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,4 +11,13 @@ func TestHello(t *testing.T) {
|
||||||
t.Errorf("got %q want %q", got, want)
|
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)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue