From 810e212b4b255914cfa73e85b52ec23db281c0e3 Mon Sep 17 00:00:00 2001 From: salmonik Date: Thu, 29 Oct 2026 23:06:22 +0100 Subject: v3.1.0: warn on shrink, but let a live round finish --- tests/client_core.rs | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/client_ui.rs | 12 ++++++++- 2 files changed, 86 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/client_core.rs b/tests/client_core.rs index dea6808..a7c5716 100644 --- a/tests/client_core.rs +++ b/tests/client_core.rs @@ -1060,3 +1060,78 @@ fn a_forfeit_that_arrives_after_the_bust_still_leaves_cleanly() { assert!(h.screen.lines.iter().any(|line| line == "Game exited.")); assert!(!h.screen.lines.iter().any(|line| line.contains("PLN lost"))); } + +#[test] +fn a_round_is_live_only_while_money_is_reserved() { + let mut h = Harness::new(); + + // Placed chips are not a live round: nothing is debited until the spin. + h.enter_roulette(); + h.key(Key::Enter); + assert!(h.board()[9].contains("1 10")); + assert!(!h.core.is_live_game()); + h.key(Key::Char('q')); + + // Blackjack is live while the player owes an action. + h.enter_blackjack(); + assert!(!h.core.is_live_game()); + h.key(Key::Char(' ')); + assert!(!h.core.is_live_game(), "not live until the server deals"); + let player = bj_state( + "bj1", + "player", + &["10S", "6H"], + &["9D", "?"], + 16, + 9, + 10, + 10, + 990, + &["hit", "stand"], + "playing", + 0, + ); + h.reply(&format!( + "BLACKJACK_STATE {}", + serde_json::to_string(&player).unwrap() + )); + assert!(h.core.is_live_game()); + + h.key(Key::Char('s')); + assert_eq!( + h.sent.last().map(String::as_str), + Some("BLACKJACK_ACTION bj1 stand") + ); + let done = bj_state( + "bj1", + "done", + &["10S", "6H"], + &["9D", "8C"], + 16, + 17, + 10, + 10, + 990, + &[], + "lose", + 0, + ); + h.reply(&format!( + "BLACKJACK_STATE {}", + serde_json::to_string(&done).unwrap() + )); + assert!(!h.core.is_live_game()); + h.key(Key::Char('q')); + + // Crash is live while the multiplier runs. + h.enter_crash(); + h.key(Key::Char(' ')); + assert!(!h.core.is_live_game(), "not live until the round starts"); + let running = crash_state("running", 1.0, None, 0, 990); + h.reply(&crash_line("CRASH_START", &running)); + assert!(h.core.is_live_game()); + + let busted = crash_state("crashed", 1.2, Some(1.2), 0, 990); + h.push(&crash_line("CRASH_BUSTED", &busted)); + assert!(!h.core.is_live_game()); +} diff --git a/tests/client_ui.rs b/tests/client_ui.rs index 7969139..6e00903 100644 --- a/tests/client_ui.rs +++ b/tests/client_ui.rs @@ -2,7 +2,7 @@ use std::time::Duration; use zagan_bet::client::ui::{ command_names, completion_lines, display_width, first_contact_lines, format_pong, help_lines, host_lines, input_cursor_column, lines_to_move_up, parse_bet_arg, record_history, - terminal_too_small, visual_line_count, MIN_COLUMNS, MIN_ROWS, + terminal_size_warning, terminal_too_small, visual_line_count, MIN_COLUMNS, MIN_ROWS, }; #[test] @@ -305,3 +305,13 @@ fn the_roulette_felt_fits_the_minimum_terminal() { "the board must leave room for the prompt and a few transcript lines" ); } + +#[test] +fn a_shrunk_terminal_gets_a_one_line_warning() { + assert!(terminal_size_warning(80, 24).is_none()); + let warning = terminal_size_warning(60, 20).unwrap(); + assert!(warning.starts_with("WARNING:")); + assert!(warning.contains("60x20")); + assert!(warning.contains("80x24")); + assert!(!warning.contains('\n'), "the board warning must be one line"); +} -- cgit v1.2.3