-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello_test.go
41 lines (35 loc) · 972 Bytes
/
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
package main
import "testing"
func TestHello(t *testing.T) {
// Assert on correct message function declaration
assertCorrectMessage := func(t *testing.T, got, want string) {
t.Helper()
if got != want {
t.Errorf("got '%s' want '%s'", got, want)
}
}
// Test saying hello to people
t.Run("saying hello to people", func(t *testing.T) {
got := Hello("Chris", English)
want := "Hello, Chris"
assertCorrectMessage(t, got, want)
})
// Test empty string default to 'World'
t.Run("empty string defaults to 'World'", func(t *testing.T) {
got := Hello("", English)
want := "Hello, World"
assertCorrectMessage(t, got, want)
})
// Test Spanish'
t.Run("in Spanish", func(t *testing.T) {
got := Hello("Elodie", Spanish)
want := "Hola, Elodie"
assertCorrectMessage(t, got, want)
})
// Test French'
t.Run("in Frensh", func(t *testing.T) {
got := Hello("Robert", French)
want := "Bonjour, Robert"
assertCorrectMessage(t, got, want)
})
}