diff options
| author | salmonik <salmonik@tuta.io> | 2026-10-29 23:06:22 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-10-29 23:06:22 +0100 |
| commit | 810e212b4b255914cfa73e85b52ec23db281c0e3 (patch) | |
| tree | 01e8035ce2945112af5ef41ef8959890bb0ef722 /tests | |
| parent | v3.0.0: cursor-driven roulette felt with splits and corners; drop schema migr... (diff) | |
| download | zagan-bet-810e212b4b255914cfa73e85b52ec23db281c0e3.tar.gz zagan-bet-810e212b4b255914cfa73e85b52ec23db281c0e3.zip | |
v3.1.0: warn on shrink, but let a live round finish
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/client_core.rs | 75 | ||||
| -rw-r--r-- | tests/client_ui.rs | 12 |
2 files changed, 86 insertions, 1 deletions
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() { | |||
| 1060 | assert!(h.screen.lines.iter().any(|line| line == "Game exited.")); | 1060 | assert!(h.screen.lines.iter().any(|line| line == "Game exited.")); |
| 1061 | assert!(!h.screen.lines.iter().any(|line| line.contains("PLN lost"))); | 1061 | assert!(!h.screen.lines.iter().any(|line| line.contains("PLN lost"))); |
| 1062 | } | 1062 | } |
| 1063 | |||
| 1064 | #[test] | ||
| 1065 | fn a_round_is_live_only_while_money_is_reserved() { | ||
| 1066 | let mut h = Harness::new(); | ||
| 1067 | |||
| 1068 | // Placed chips are not a live round: nothing is debited until the spin. | ||
| 1069 | h.enter_roulette(); | ||
| 1070 | h.key(Key::Enter); | ||
| 1071 | assert!(h.board()[9].contains("1 10")); | ||
| 1072 | assert!(!h.core.is_live_game()); | ||
| 1073 | h.key(Key::Char('q')); | ||
| 1074 | |||
| 1075 | // Blackjack is live while the player owes an action. | ||
| 1076 | h.enter_blackjack(); | ||
| 1077 | assert!(!h.core.is_live_game()); | ||
| 1078 | h.key(Key::Char(' ')); | ||
| 1079 | assert!(!h.core.is_live_game(), "not live until the server deals"); | ||
| 1080 | let player = bj_state( | ||
| 1081 | "bj1", | ||
| 1082 | "player", | ||
| 1083 | &["10S", "6H"], | ||
| 1084 | &["9D", "?"], | ||
| 1085 | 16, | ||
| 1086 | 9, | ||
| 1087 | 10, | ||
| 1088 | 10, | ||
| 1089 | 990, | ||
| 1090 | &["hit", "stand"], | ||
| 1091 | "playing", | ||
| 1092 | 0, | ||
| 1093 | ); | ||
| 1094 | h.reply(&format!( | ||
| 1095 | "BLACKJACK_STATE {}", | ||
| 1096 | serde_json::to_string(&player).unwrap() | ||
| 1097 | )); | ||
| 1098 | assert!(h.core.is_live_game()); | ||
| 1099 | |||
| 1100 | h.key(Key::Char('s')); | ||
| 1101 | assert_eq!( | ||
| 1102 | h.sent.last().map(String::as_str), | ||
| 1103 | Some("BLACKJACK_ACTION bj1 stand") | ||
| 1104 | ); | ||
| 1105 | let done = bj_state( | ||
| 1106 | "bj1", | ||
| 1107 | "done", | ||
| 1108 | &["10S", "6H"], | ||
| 1109 | &["9D", "8C"], | ||
| 1110 | 16, | ||
| 1111 | 17, | ||
| 1112 | 10, | ||
| 1113 | 10, | ||
| 1114 | 990, | ||
| 1115 | &[], | ||
| 1116 | "lose", | ||
| 1117 | 0, | ||
| 1118 | ); | ||
| 1119 | h.reply(&format!( | ||
| 1120 | "BLACKJACK_STATE {}", | ||
| 1121 | serde_json::to_string(&done).unwrap() | ||
| 1122 | )); | ||
| 1123 | assert!(!h.core.is_live_game()); | ||
| 1124 | h.key(Key::Char('q')); | ||
| 1125 | |||
| 1126 | // Crash is live while the multiplier runs. | ||
| 1127 | h.enter_crash(); | ||
| 1128 | h.key(Key::Char(' ')); | ||
| 1129 | assert!(!h.core.is_live_game(), "not live until the round starts"); | ||
| 1130 | let running = crash_state("running", 1.0, None, 0, 990); | ||
| 1131 | h.reply(&crash_line("CRASH_START", &running)); | ||
| 1132 | assert!(h.core.is_live_game()); | ||
| 1133 | |||
| 1134 | let busted = crash_state("crashed", 1.2, Some(1.2), 0, 990); | ||
| 1135 | h.push(&crash_line("CRASH_BUSTED", &busted)); | ||
| 1136 | assert!(!h.core.is_live_game()); | ||
| 1137 | } | ||
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; | |||
| 2 | use zagan_bet::client::ui::{ | 2 | use zagan_bet::client::ui::{ |
| 3 | command_names, completion_lines, display_width, first_contact_lines, format_pong, help_lines, | 3 | command_names, completion_lines, display_width, first_contact_lines, format_pong, help_lines, |
| 4 | host_lines, input_cursor_column, lines_to_move_up, parse_bet_arg, record_history, | 4 | host_lines, input_cursor_column, lines_to_move_up, parse_bet_arg, record_history, |
| 5 | terminal_too_small, visual_line_count, MIN_COLUMNS, MIN_ROWS, | 5 | terminal_size_warning, terminal_too_small, visual_line_count, MIN_COLUMNS, MIN_ROWS, |
| 6 | }; | 6 | }; |
| 7 | 7 | ||
| 8 | #[test] | 8 | #[test] |
| @@ -305,3 +305,13 @@ fn the_roulette_felt_fits_the_minimum_terminal() { | |||
| 305 | "the board must leave room for the prompt and a few transcript lines" | 305 | "the board must leave room for the prompt and a few transcript lines" |
| 306 | ); | 306 | ); |
| 307 | } | 307 | } |
| 308 | |||
| 309 | #[test] | ||
| 310 | fn a_shrunk_terminal_gets_a_one_line_warning() { | ||
| 311 | assert!(terminal_size_warning(80, 24).is_none()); | ||
| 312 | let warning = terminal_size_warning(60, 20).unwrap(); | ||
| 313 | assert!(warning.starts_with("WARNING:")); | ||
| 314 | assert!(warning.contains("60x20")); | ||
| 315 | assert!(warning.contains("80x24")); | ||
| 316 | assert!(!warning.contains('\n'), "the board warning must be one line"); | ||
| 317 | } | ||
