package game import ( "strings" "testing" "thehouseoficarus/internal/casino" "thehouseoficarus/internal/color" "thehouseoficarus/internal/net" ) func TestRouletteSpinOutputHasNoPromptOrBlankLines(t *testing.T) { g, sess, conn := uxCasinoGame(t) g.Hub = net.NewHub() g.Hub.EnterRoom(sess, 1) sess.Player.Options = map[string]any{"color": "none", "unicode": true} g.emitCasinoEvents(g.Casino.Join(1, casino.TableConfig{ID: "roulette", Game: casino.GameRoulette}, sess.Player.Name)) sess.ClearPrompt() conn.data = nil g.executeBet(sess, []string{"2", "on", "2"}, "bet 2 on 2") g.writePrompt(sess) // the command queue's post-command prompt text := strings.ReplaceAll(string(conn.data), "\r\n", "\n") if !strings.HasSuffix(text, "The roulette wheel spins...\n") { t.Fatalf("prompt after spin announcement: %q", text) } before := len(conn.data) g.reprompt(sess) if len(conn.data) != before { t.Fatal("reprompt interrupted animation") } for tick := 1; tick <= 5; tick++ { conn.data = nil g.CasinoTick() text = strings.ReplaceAll(string(conn.data), "\r\n", "\n") if strings.Count(text, "\n") != 1 || !strings.HasSuffix(text, "\n") || color.VisibleLen(strings.TrimSuffix(text, "\n")) != 10 { t.Fatalf("tick %d: expected exactly one strip: %q", tick, text) } if tick == 5 && strings.Count(text, ".") != 1 { t.Fatal("final strip missing ball") } } for tick := 6; tick <= 7; tick++ { conn.data = nil g.CasinoTick() if len(conn.data) != 0 { t.Fatalf("tick %d: expected silence: %q", tick, conn.data) } } g.CasinoTick() result := strings.ReplaceAll(string(conn.data), "\r\n", "\n") if !strings.HasPrefix(result, "\nThe ball lands in") || g.casinoAnimationBusy(sess) { t.Fatalf("result did not start on a blank line or end animation: %q", result) } // A resolved spin shows the result and the next-spin menu, but not the // tracker, racetrack, and history again. if strings.Contains(result, "History: last") { t.Fatalf("settlement redrew the table board: %q", result) } sess.ClearPrompt() conn.data = nil g.writePrompt(sess) if len(conn.data) == 0 { t.Fatal("prompt did not resume") } } func TestRouletteSpinStrip(t *testing.T) { for _, mode := range []string{"none", "ansi", "xterm256"} { for _, unicode := range []bool{false, true} { for _, ball := range []int{-1, 5} { s := &casino.RouletteSnapshot{Phase: "playing", SpinFrame: 1, BallPosition: ball, SpinPockets: [10]string{"1", "2", "1", "2", "1", "26", "0", "32", "15", "19"}} art := renderRouletteSnapshot(s, mode, unicode, 7) plain := plainRoulette(art) dots := 0 if ball >= 0 { dots = 1 } if color.VisibleLen(art) != 10 || strings.Count(plain, ".") != dots || strings.Contains(plain, "\n") { t.Fatalf("bad strip: %q", art) } block := "█" if !unicode { block = "#" } if strings.Count(plain, block) != 10-dots { t.Fatalf("bad blocks: %q", plain) } if mode != "none" && ball >= 0 && !strings.Contains(art, roulettePaint(mode, ".", 8)) { t.Fatalf("26 ball is not black: %q", art) } } for _, pocket := range []string{"0", "00", "26", "32"} { s := &casino.RouletteSnapshot{Phase: "playing", SpinFrame: 5, BallPosition: 4} s.SpinPockets[4] = pocket art := renderRouletteSnapshot(s, mode, unicode, 7) fg, _ := roulettePocketColor(pocket) if fg == 0 { fg = 8 } if !strings.Contains(art, roulettePaint(mode, ".", fg)) { t.Fatalf("wrong ball color for %s: %q", pocket, art) } } } } if got := renderRouletteSnapshot(&casino.RouletteSnapshot{Phase: "playing"}, "none", true, 7); got != "" { t.Fatalf("old wheel still shown: %q", got) } }