| 📦 Hello 0368b85 k33g 4h ago | 1 | package hello |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestGreet(t *testing.T) { |
| 6 | cases := []struct { |
| 7 | why string |
| 8 | name string |
| 9 | want string |
| 10 | }{ |
| 11 | {"a name is greeted as it is written", "Bob", "Hello, Bob!"}, |
| 12 | {"surrounding whitespace is not part of a name", " Bob\t", "Hello, Bob!"}, |
| 13 | {"an empty name still produces a whole greeting", "", "Hello, world!"}, |
| 14 | {"a name of nothing but whitespace is an empty name", " ", "Hello, world!"}, |
| 15 | {"the inside of a name is left alone", "Ada Lovelace", "Hello, Ada Lovelace!"}, |
| 16 | {"a name is not assumed to be ASCII", "Émilie", "Hello, Émilie!"}, |
| 17 | } |
| 18 | |
| 19 | for _, c := range cases { |
| 20 | t.Run(c.why, func(t *testing.T) { |
| 21 | if got := Greet(c.name); got != c.want { |
| 22 | t.Errorf("Greet(%q) = %q, want %q", c.name, got, c.want) |
| 23 | } |
| 24 | }) |
| 25 | } |
| 26 | } |