diff --git a/hello/hello.go b/hello/hello.go deleted file mode 100644 index 64287a8..0000000 --- a/hello/hello.go +++ /dev/null @@ -1,16 +0,0 @@ -package main - -import "fmt" - -const englishHelloPrefix = "Hello, " - -func Hello(name string) string { - if name == "" { - name = "World" - } - return englishHelloPrefix + name -} - -func main() { - fmt.Println(Hello("world")) -} diff --git a/hello/go.mod b/helloworld/go.mod similarity index 100% rename from hello/go.mod rename to helloworld/go.mod diff --git a/helloworld/hello.go b/helloworld/hello.go new file mode 100644 index 0000000..f88f009 --- /dev/null +++ b/helloworld/hello.go @@ -0,0 +1,36 @@ +package main + +import "fmt" + +const ( + spanish = "Spanish" + french = "French" + + englishHelloPrefix = "Hello, " + spanishHelloPrefix = "Hola, " + frenchHelloPrefix = "Bonjour, " +) + +func Hello(name string, language string) string { + if name == "" { + name = "World" + } + + return greetingPrefix(language) + name +} + +func greetingPrefix(language string) (prefix string) { + switch language { + case spanish: + prefix = spanishHelloPrefix + case french: + prefix = frenchHelloPrefix + default: + prefix = englishHelloPrefix + } + return +} + +func main() { + fmt.Println(Hello("world", "")) +} diff --git a/hello/hello_test.go b/helloworld/hello_test.go similarity index 57% rename from hello/hello_test.go rename to helloworld/hello_test.go index 0e56664..49733fc 100644 --- a/hello/hello_test.go +++ b/helloworld/hello_test.go @@ -4,15 +4,25 @@ import "testing" func TestHello(t *testing.T) { t.Run("saying hello to people", func(t *testing.T) { - got := Hello("Chris") + got := Hello("Chris", "") want := "Hello, Chris" assertCorrectMessage(t, got, want) }) t.Run("say 'Hello, World' when an empty string is supplied", func(t *testing.T) { - got := Hello("") + got := Hello("", "") want := "Hello, World" assertCorrectMessage(t, got, want) }) + t.Run("in Spanish", func(t *testing.T) { + got := Hello("Elodie", "Spanish") + want := "Hola, Elodie" + assertCorrectMessage(t, got, want) + }) + t.Run("in French", func(t *testing.T) { + got := Hello("Michael", "French") + want := "Bonjour, Michael" + assertCorrectMessage(t, got, want) + }) } func assertCorrectMessage(t testing.TB, got, want string) {