+7
-2
Go/hello.go
+7
-2
Go/hello.go
···
4
4
5
5
const englishHelloPrefix = "Hello, "
6
6
7
-
func Hello(name string) string {
7
+
func Hello(name string, language string) string {
8
8
if name == "" {
9
9
name = "world"
10
10
}
11
+
12
+
if language == "Spanish" {
13
+
return "Hola, " + name
14
+
}
15
+
11
16
return englishHelloPrefix + name
12
17
}
13
18
14
19
func main() {
15
-
fmt.Println(Hello("world"))
20
+
fmt.Println(Hello("world", ""))
16
21
}
+9
-2
Go/hello_test.go
+9
-2
Go/hello_test.go
···
4
4
5
5
func TestHello(t *testing.T) {
6
6
t.Run("saying hello to people", func(t *testing.T) {
7
-
got := Hello("Pedro")
7
+
got := Hello("Pedro", "")
8
8
want := "Hello, Pedro"
9
9
10
10
assertCorrectMessage(t, got, want)
11
11
})
12
12
13
13
t.Run("say 'Hello, world' when an empty string is supplied", func(t *testing.T) {
14
-
got := Hello("")
14
+
got := Hello("", "")
15
15
want := "Hello, world"
16
+
17
+
assertCorrectMessage(t, got, want)
18
+
})
19
+
20
+
t.Run("in Spanish", func(t *testing.T) {
21
+
got := Hello("Elodie", "Spanish")
22
+
want := "Hola, Elodie"
16
23
17
24
assertCorrectMessage(t, got, want)
18
25
})