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
|
package minecraft
import (
"reflect"
"testing"
)
func TestParseList(t *testing.T) {
cases := []struct {
out string
want Status
}{
{
"There are 2 of a max of 20 players online: Alice, Bob",
Status{Online: true, Count: 2, Max: 20, Players: []string{"Alice", "Bob"}},
},
{
"There are 0 of a max of 20 players online:",
Status{Online: true, Count: 0, Max: 20, Players: []string{}},
},
{
"There are 1 of a max of 20 players online: Steve\n",
Status{Online: true, Count: 1, Max: 20, Players: []string{"Steve"}},
},
{
"some unexpected response",
Status{Online: true, Count: 0, Max: 0, Players: []string{}},
},
}
for _, c := range cases {
got := parseList(c.out)
if got.Players == nil {
got.Players = []string{}
}
if !reflect.DeepEqual(got, c.want) {
t.Errorf("parseList(%q) = %+v, want %+v", c.out, got, c.want)
}
}
}
|