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) } } }