diff options
| author | historia <[not public]> | 2026-09-15 16:26:23 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-09-15 16:26:23 -0400 |
| commit | d89504c3df74706b387b8fa829dd291e31ca01c7 (patch) | |
| tree | 8924164ed1b061cca04aaa79f283d1ab0995486e /internal/game/render_help_test.go | |
| parent | 0b0b25222b3131ada79ff78c28eb8bf07d977deb (diff) | |
| download | thehouseoficarus-d89504c3df74706b387b8fa829dd291e31ca01c7.tar.gz | |
fix: help topics (newplayer, title/body files), help aliases, and table width rebalancing
Diffstat (limited to 'internal/game/render_help_test.go')
| -rw-r--r-- | internal/game/render_help_test.go | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/internal/game/render_help_test.go b/internal/game/render_help_test.go new file mode 100644 index 0000000..b8ad614 --- /dev/null +++ b/internal/game/render_help_test.go @@ -0,0 +1,81 @@ +package game + +import ( + "strings" + "testing" +) + +func loadHelpOrSkip(t *testing.T) []HelpDef { + t.Helper() + helps, err := LoadHelp("../../data") + if err != nil { + t.Fatal(err) + } + if len(helps) == 0 { + t.Fatal("no help topics loaded") + } + return helps +} + +func TestLoadHelpAllFilesParse(t *testing.T) { + helps := loadHelpOrSkip(t) + seen := map[string]bool{} + for _, h := range helps { + if strings.TrimSpace(h.Name) == "" { + t.Errorf("help entry with empty name: %q", h.Content) + } + if seen[h.Name] { + t.Errorf("duplicate help topic %q", h.Name) + } + seen[h.Name] = true + } +} + +func TestNewPlayerHelpExists(t *testing.T) { + helps := loadHelpOrSkip(t) + found := false + for _, h := range helps { + if h.Name == "newplayer" { + found = true + } + } + if !found { + t.Fatal("help topic 'newplayer' missing (referenced by intro room)") + } +} + +func TestHelpAliasesResolveWithoutCollision(t *testing.T) { + helps := loadHelpOrSkip(t) + owner := map[string]string{} + for _, h := range helps { + for _, a := range h.Aliases { + a = strings.ToLower(strings.TrimSpace(a)) + if a == "" { + continue + } + if prev, dup := owner[a]; dup { + t.Errorf("alias %q claimed by both %q and %q", a, prev, h.Name) + } + owner[a] = h.Name + } + } + for topic, want := range map[string]string{ + "mine": "mining", + "chop": "woodcutting", + "fish": "fishing", + "fletch": "fletch", + "newplayer": "newplayer", + "new player": "newplayer", + } { + resolved := "" + for _, h := range helps { + if matchesHelpTopic(h, topic) { + resolved = h.Name + break + } + } + if resolved != want { + t.Errorf("help %q resolved to %q, want %q", topic, resolved, want) + } + } +} |
