Three behaviors from 5.4.4 that the port dropped silently. Each is a few
lines; grouped because they are all "restore something C did".
1. sticks.c 237: the "otherwise" arm closing do_zap's switch printed
"what a bizarre schtick!", and doZap had turned it into doing nothing.
The arm is under #ifdef MASTER, not under a runtime wizard test, so in
the MASTER build this port is it printed for every player and must not
be gated on g.Wizard. WS_NOP is a case of that switch in its own right
("when WS_NOP: break;"), so "no handler ran" cannot be the trigger:
the wand of nothing does nothing quietly. C's switch covers all 14 WS_
values, so its otherwise is reachable only for an o_which outside the
table, which is what Object.hasValidWhich already screens for. All
three arms fall through to obj.Charges--, as C's do.
2. command.c 288-291: CTRL('R') is "after = FALSE; clearok(curscr, TRUE);
wrefresh(curscr);" — a forced full repaint. The port called
g.refresh(), the ordinary diffing blit, which cannot fix the only
situation the command exists for: a screen corrupted by another
program's output leaves the game's record of it still correct, so the
diff sends nothing. New Terminal.Repaint (tcell Screen.Sync, which
discards tcell's record of the terminal rather than diffing against
it), Screen.Repaint and g.repaint(), implemented in term.Tcell and in
both headless test terminals. Named for the curses operation: the
interface is the game's abstraction, not tcell's. It repaints what was
last rendered — C repainted curscr, not stdscr — so it takes no
window.
3. main.c 107-113: the startup greeting existed nowhere in the tree. New
game.Greeting, printed on stdout by cmd/rogue/main.go before
term.New(), the port's initscr(). Only the wizard wording is #ifdef
MASTER; the other is unconditional. The %d is dnum, which main.c has
just assigned to seed, so it is Params.Seed. Neither wording ends in a
newline. Two placement details the tests pin: the printf sits after
parse_opts, so a ROGUEOPTS name= is what the player is greeted by; and
it sits after the -s/-d handling and after restore(), which never
returns, so a resumed game does not announce that a dungeon is being
dug (digsNewDungeon).
Greeting parses ROGUEOPTS into a throwaway game built the way New builds
the real one, tables and home directory included: ParseOpts handles every
option, not just the one the greeting reads, and inven= is matched
against inv_t_name[], which lives on the game.
All three message strings verified byte-for-byte against origin/c-master
sticks.c and main.c. No RNG call is added on any path and nothing under
game/testdata/ changed; TestSeedCompatItemTables is green against the
untouched golden.
Mutation-proved, each behavior removed in turn with only its own test
failing: dropping the message arm fails
TestZapUnhandledWandSaysBizarreSchtick; extending the message to WS_NOP
fails TestZapWandOfNothingIsSilent; putting g.refresh() back fails
TestRedrawCommandForcesFullRepaint; swapping the two wordings, and
ignoring the ROGUEOPTS name, both fail TestGreeting; greeting on the
restore path fails TestDigsNewDungeon.
ARCHITECTURE.md 5.3 gains Repaint and why a blit cannot substitute for
it; nothing here is deliberately dropped, so section 9 is unchanged.
TODO.md gets a Completed Steps entry; Next Step deliberately not rotated,
this being out-of-band issue work.
81 lines
2.4 KiB
Go
81 lines
2.4 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()
|
|
|
|
// The account name main.c copies into whoami when ROGUEOPTS does not
|
|
// name the player itself.
|
|
const account = "conan"
|
|
|
|
cases := []struct {
|
|
name string
|
|
params Params
|
|
want string
|
|
}{
|
|
{
|
|
name: "normal",
|
|
params: Params{Name: account, Seed: 4242},
|
|
want: "Hello conan, just a moment while I dig the dungeon...",
|
|
},
|
|
{
|
|
name: "wizard names the dungeon",
|
|
params: Params{Name: account, 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: account, 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: account, Seed: 7, RogueOpts: "terse,fruit=mango",
|
|
},
|
|
want: "Hello conan, just a moment while I dig the dungeon...",
|
|
},
|
|
{
|
|
// ParseOpts reaches every option, not just name=, and the
|
|
// inventory style is matched against a table (options.c
|
|
// parse_opts, inv_t_name[]) that lives in the game data. A
|
|
// greeting parsed on a game without those tables faulted on
|
|
// this ROGUEOPTS before it could print anything at all.
|
|
name: "ROGUEOPTS inventory style parses without a fault",
|
|
params: Params{
|
|
Name: account, Seed: 7, RogueOpts: "inven=slow,name=Rodney",
|
|
},
|
|
want: "Hello Rodney, 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")
|
|
}
|
|
})
|
|
}
|
|
}
|