-
Notifications
You must be signed in to change notification settings - Fork 26
/
hello_test.go
46 lines (38 loc) · 1.12 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
package main
import "testing"
func TestHello(t *testing.T) {
assertCorrectMessage := func(t *testing.T, got, want string) {
// is needed to tell the test suite that this method is a helper.
// By doing this when it fails the line number reported will be in our function
// call rather than inside our test helper.
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("Chris", "")
want := "Hello, Chris"
assertCorrectMessage(t, got, want)
})
t.Run("empty string defaults to 'World'", func(t *testing.T) {
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("Elodie", "French")
want := "Bonjour, Elodie"
assertCorrectMessage(t, got, want)
})
t.Run("in Arabic", func(t *testing.T) {
got := Hello("Elodie", "Arabic")
want := "أهلا, Elodie"
assertCorrectMessage(t, got, want)
})
}