From 504815c05de776db590278ee113114411f8c2046 Mon Sep 17 00:00:00 2001 From: Pedro Correa Date: Mon, 4 Mar 2024 16:29:35 -0300 Subject: [PATCH] :sparkles: (Go) hello in french --- Go/hello.go | 21 ++++++++++++++------- Go/hello_test.go | 7 +++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Go/hello.go b/Go/hello.go index 81e0490..c6b372e 100644 --- a/Go/hello.go +++ b/Go/hello.go @@ -3,19 +3,26 @@ package main import "fmt" const spanish = "Spanish" +const french = "French" const englishHelloPrefix = "Hello, " const spanishHelloPrefix = "Hola, " +const frenchHelloPrefix = "Bonjour, " func Hello(name string, language string) string { - if name == "" { - name = "world" - } + if name == "" { + name = "world" + } - if language == spanish { - return spanishHelloPrefix + name - } + prefix := englishHelloPrefix - return englishHelloPrefix + name + switch language { + case french: + prefix = frenchHelloPrefix + case spanish: + prefix = spanishHelloPrefix + } + + return prefix + name } func main() { diff --git a/Go/hello_test.go b/Go/hello_test.go index 5c11047..63a269b 100644 --- a/Go/hello_test.go +++ b/Go/hello_test.go @@ -23,6 +23,13 @@ func TestHello(t *testing.T) { assertCorrectMessage(t, got, want) }) + + t.Run("in French", func(t *testing.T) { + got := Hello("Elodie", "French") + want := "Bonjour, Elodie" + + assertCorrectMessage(t, got, want) + }) } func assertCorrectMessage(t testing.TB, got, want string) { -- 2.51.2