Incomplete checkpoint, preserved after the implementing session hit a capacity limit partway through mutation verification. NOT reviewed and NOT gate-clean: make fmt has not been run, so fmt-check currently fails on ARCHITECTURE.md and TODO.md. Work still outstanding before this is fit for review: - run make fmt and fold the result in - finish mutation-proving each of the three behaviors - verify every message string byte-for-byte against the C sources - confirm TestSeedCompatItemTables passes with its golden untouched Refs #13.
65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
//nolint:testpackage // white-box tests reach unexported state (approved 2026-07-07)
|
|
package game
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestGreeting pins both wordings of main.c's pre-initscr printf byte for
|
|
// byte. The wizard one carries dnum, which main.c has just assigned to
|
|
// seed, so it is the seed the player sees. Neither ends in a newline: C
|
|
// printed, flushed, and handed the display to curses.
|
|
func TestGreeting(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
cases := []struct {
|
|
name string
|
|
params Params
|
|
want string
|
|
}{
|
|
{
|
|
name: "normal",
|
|
params: Params{Name: "conan", Seed: 4242},
|
|
want: "Hello conan, just a moment while I dig the dungeon...",
|
|
},
|
|
{
|
|
name: "wizard names the dungeon",
|
|
params: Params{Name: "conan", Seed: 4242, Wizard: true},
|
|
want: "Hello conan, welcome to dungeon #4242",
|
|
},
|
|
{
|
|
// parse_opts runs before the printf in main.c, and whoami
|
|
// falls back to the account name only when ROGUEOPTS left it
|
|
// empty, so the option is what the player is greeted by.
|
|
name: "ROGUEOPTS name wins over the account name",
|
|
params: Params{
|
|
Name: "conan", Seed: 7, RogueOpts: "name=Rodney",
|
|
},
|
|
want: "Hello Rodney, just a moment while I dig the dungeon...",
|
|
},
|
|
{
|
|
name: "ROGUEOPTS without a name keeps the account name",
|
|
params: Params{
|
|
Name: "conan", Seed: 7, RogueOpts: "terse,fruit=mango",
|
|
},
|
|
want: "Hello conan, just a moment while I dig the dungeon...",
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
got := Greeting(tc.params)
|
|
if got != tc.want {
|
|
t.Errorf("Greeting() = %q, want %q", got, tc.want)
|
|
}
|
|
|
|
if strings.HasSuffix(got, "\n") {
|
|
t.Error("greeting ends in a newline; C's printf did not")
|
|
}
|
|
})
|
|
}
|
|
}
|