diff options
| author | salmonik <salmonik@tuta.io> | 2026-10-28 22:36:07 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-10-28 22:36:07 +0100 |
| commit | 25f9abeb4c69024f8d9dceb472ba33c03e00daa0 (patch) | |
| tree | a02a78f04b5afa2e3fbebffb524f1568df8f00d8 /tests/client_ui.rs | |
| parent | v0.2.4: fix command UX, completion wrapping and auth prompt cancellation (diff) | |
| download | zagan-bet-25f9abeb4c69024f8d9dceb472ba33c03e00daa0.tar.gz zagan-bet-25f9abeb4c69024f8d9dceb472ba33c03e00daa0.zip | |
v0.2.5: fix terminal width, ping timing and output formatting
Diffstat (limited to '')
| -rw-r--r-- | tests/client_ui.rs | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/tests/client_ui.rs b/tests/client_ui.rs index 78faed0..a22fbe7 100644 --- a/tests/client_ui.rs +++ b/tests/client_ui.rs | |||
| @@ -1,7 +1,8 @@ | |||
| 1 | use zagan_bet::client::ui::{ | 1 | use zagan_bet::client::ui::{ |
| 2 | command_names, completion_lines, help_lines, input_cursor_column, lines_to_move_up, | 2 | command_names, completion_lines, display_width, first_contact_lines, format_pong, |
| 3 | parse_bet_arg, record_history, | 3 | help_lines, host_lines, input_cursor_column, lines_to_move_up, parse_bet_arg, record_history, |
| 4 | }; | 4 | }; |
| 5 | use std::time::Duration; | ||
| 5 | 6 | ||
| 6 | #[test] | 7 | #[test] |
| 7 | fn help_has_no_source_indentation() { | 8 | fn help_has_no_source_indentation() { |
| @@ -129,3 +130,63 @@ fn completions_wrap_within_the_requested_width() { | |||
| 129 | ); | 130 | ); |
| 130 | } | 131 | } |
| 131 | } | 132 | } |
| 133 | |||
| 134 | #[test] | ||
| 135 | fn display_width_counts_terminal_columns_not_bytes() { | ||
| 136 | assert_eq!(display_width("abc"), 3); | ||
| 137 | assert_eq!(display_width("ąćęłńóśźż"), 9); | ||
| 138 | assert_eq!(display_width("中"), 2); | ||
| 139 | assert_eq!(display_width("🎉"), 2); | ||
| 140 | assert_eq!(display_width("e\u{0301}"), 1); | ||
| 141 | } | ||
| 142 | |||
| 143 | #[test] | ||
| 144 | fn cursor_column_uses_display_width() { | ||
| 145 | assert_eq!(input_cursor_column(2, display_width("ąć")), 4); | ||
| 146 | assert_eq!(input_cursor_column(2, display_width("中")), 4); | ||
| 147 | } | ||
| 148 | |||
| 149 | #[test] | ||
| 150 | fn first_contact_message_stays_within_80_columns() { | ||
| 151 | let fingerprint = "a4d6f80784154c2cb739a1df61ab3e9038ed731ee2e05c7611457ac741b3834c"; | ||
| 152 | let lines = first_contact_lines("127.0.0.1:11525", fingerprint); | ||
| 153 | |||
| 154 | assert!(lines.iter().any(|line| line.contains("127.0.0.1:11525"))); | ||
| 155 | assert!(lines.iter().any(|line| line.contains(fingerprint))); | ||
| 156 | for line in lines { | ||
| 157 | assert!( | ||
| 158 | line.len() <= 80, | ||
| 159 | "first-contact line is too wide ({}): {line:?}", | ||
| 160 | line.len() | ||
| 161 | ); | ||
| 162 | } | ||
| 163 | } | ||
| 164 | |||
| 165 | #[test] | ||
| 166 | fn pong_is_formatted_to_one_decimal() { | ||
| 167 | assert_eq!(format_pong(Duration::from_micros(144)), "Pong (0.1ms)"); | ||
| 168 | assert_eq!(format_pong(Duration::from_millis(41)), "Pong (41.0ms)"); | ||
| 169 | } | ||
| 170 | |||
| 171 | #[test] | ||
| 172 | fn host_lines_fit_an_80_column_terminal() { | ||
| 173 | let fingerprint = "a4d6f80784154c2cb739a1df61ab3e9038ed731ee2e05c7611457ac741b3834c"; | ||
| 174 | let lines = host_lines(&[ | ||
| 175 | ( | ||
| 176 | "127.0.0.1:11525".to_string(), | ||
| 177 | Some(fingerprint.to_string()), | ||
| 178 | ), | ||
| 179 | ("unknown.example:443".to_string(), None), | ||
| 180 | ]); | ||
| 181 | |||
| 182 | assert!(lines.iter().any(|line| line.contains("127.0.0.1:11525"))); | ||
| 183 | assert!(lines.iter().any(|line| line.contains(fingerprint))); | ||
| 184 | assert!(lines.iter().any(|line| line.contains("no fingerprint"))); | ||
| 185 | for line in lines { | ||
| 186 | assert!( | ||
| 187 | line.len() <= 80, | ||
| 188 | "host line is too wide ({}): {line:?}", | ||
| 189 | line.len() | ||
| 190 | ); | ||
| 191 | } | ||
| 192 | } | ||
