diff options
| author | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-06-20 09:40:07 -0700 |
|---|---|---|
| committer | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-06-20 09:40:07 -0700 |
| commit | fb653292612eddca5b088ed88466c546d1597107 (patch) | |
| tree | 900ed32e066812688858ed3bb15128c41bb78054 /api/minecraft/minecraft_test.go | |
| download | penguins.lan-fb653292612eddca5b088ed88466c546d1597107.tar.gz penguins.lan-fb653292612eddca5b088ed88466c546d1597107.zip | |
Initial commit
Diffstat (limited to 'api/minecraft/minecraft_test.go')
| -rw-r--r-- | api/minecraft/minecraft_test.go | 40 |
1 files changed, 40 insertions, 0 deletions
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) + } + } +} |
