From fb653292612eddca5b088ed88466c546d1597107 Mon Sep 17 00:00:00 2001 From: Elizabeth Alexander Hunt Date: Sat, 20 Jun 2026 09:40:07 -0700 Subject: Initial commit --- api/minecraft/minecraft_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 api/minecraft/minecraft_test.go (limited to 'api/minecraft/minecraft_test.go') diff --git a/api/minecraft/minecraft_test.go b/api/minecraft/minecraft_test.go new file mode 100644 index 0000000..0c89fc5 --- /dev/null +++ b/api/minecraft/minecraft_test.go @@ -0,0 +1,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) + } + } +} -- cgit v1.3