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
|
package hello
import "testing"
func TestGreet(t *testing.T) {
cases := []struct {
why string
name string
want string
}{
{"a name is greeted as it is written", "Bob", "Hello, Bob!"},
{"surrounding whitespace is not part of a name", " Bob\t", "Hello, Bob!"},
{"an empty name still produces a whole greeting", "", "Hello, world!"},
{"a name of nothing but whitespace is an empty name", " ", "Hello, world!"},
{"the inside of a name is left alone", "Ada Lovelace", "Hello, Ada Lovelace!"},
{"a name is not assumed to be ASCII", "Émilie", "Hello, Émilie!"},
}
for _, c := range cases {
t.Run(c.why, func(t *testing.T) {
if got := Greet(c.name); got != c.want {
t.Errorf("Greet(%q) = %q, want %q", c.name, got, c.want)
}
})
}
}
|