-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello_test.go
49 lines (40 loc) · 1.16 KB
/
hello_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import "testing"
func TestHello(t *testing.T) {
assertCorrectMessage := func (t *testing.T, got, want string) {
t.Helper()
if got != want {
t.Errorf("Got '%s'. Want '%s'", got, want)
}
}
t.Run("Saying hello to people", func(t *testing.T) {
got := Hello("Michael", "")
want := "Hello, Michael!"
assertCorrectMessage(t, got, want)
})
t.Run("Say 'Hello, world!' when an empty string is supplied", func(t *testing.T) {
got := Hello("", "")
want := "Hello, world!"
assertCorrectMessage(t, got, want)
})
t.Run("in spanish", func(t *testing.T) {
got := Hello("Jakob", "Spanish")
want := "Hola, Jakob!"
assertCorrectMessage(t, got, want)
})
t.Run("and french", func(t *testing.T) {
got := Hello("Jakob", "French")
want := "Bonjour, Jakob!"
assertCorrectMessage(t, got, want)
})
t.Run("and finally danish", func(t *testing.T) {
got := Hello("Åge", "Danish")
want := "Hejsa, Åge!"
assertCorrectMessage(t, got, want)
})
t.Run("Default to english if the language is not implemented", func(t *testing.T) {
got := Hello("Hansie", "SomeUnknownLanguage")
want := "Hello, Hansie!"
assertCorrectMessage(t, got, want)
})
}