summaryrefslogtreecommitdiffstats
path: root/tests/client_ui.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/client_ui.rs45
1 files changed, 16 insertions, 29 deletions
diff --git a/tests/client_ui.rs b/tests/client_ui.rs
index 7a1b675..44febde 100644
--- a/tests/client_ui.rs
+++ b/tests/client_ui.rs
@@ -1,9 +1,9 @@
1use std::time::Duration;
1use zagan_bet::client::ui::{ 2use zagan_bet::client::ui::{
2 command_names, completion_lines, display_width, first_contact_lines, format_pong, 3 command_names, completion_lines, display_width, first_contact_lines, format_pong, help_lines,
3 help_lines, 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,
4 visual_line_count, 5 visual_line_count,
5}; 6};
6use std::time::Duration;
7 7
8#[test] 8#[test]
9fn help_has_no_source_indentation() { 9fn help_has_no_source_indentation() {
@@ -27,13 +27,7 @@ fn help_documents_every_command() {
27fn completion_knows_every_command() { 27fn completion_knows_every_command() {
28 let commands = command_names(); 28 let commands = command_names();
29 for expected in [ 29 for expected in [
30 "connect", 30 "connect", "games", "play", "hosts", "send", "logout", "quit",
31 "games",
32 "play",
33 "hosts",
34 "send",
35 "logout",
36 "quit",
37 ] { 31 ] {
38 assert!( 32 assert!(
39 commands.contains(&expected), 33 commands.contains(&expected),
@@ -109,19 +103,12 @@ fn display_width_ignores_ansi_sequences() {
109fn visual_line_count_ignores_ansi_sequences() { 103fn visual_line_count_ignores_ansi_sequences() {
110 let styled = format!("\x1b[31m{}\x1b[0m", "x".repeat(75)); 104 let styled = format!("\x1b[31m{}\x1b[0m", "x".repeat(75));
111 assert_eq!(visual_line_count(&[styled], 72), 2); 105 assert_eq!(visual_line_count(&[styled], 72), 2);
112 assert_eq!( 106 assert_eq!(visual_line_count(&["\x1b[31m18\x1b[0m".to_string()], 80), 1);
113 visual_line_count(&["\x1b[31m18\x1b[0m".to_string()], 80),
114 1
115 );
116} 107}
117 108
118#[test] 109#[test]
119fn visual_line_count_accounts_for_terminal_wrapping() { 110fn visual_line_count_accounts_for_terminal_wrapping() {
120 let lines = vec![ 111 let lines = vec!["12345".to_string(), "123456".to_string(), String::new()];
121 "12345".to_string(),
122 "123456".to_string(),
123 String::new(),
124 ];
125 112
126 assert_eq!(visual_line_count(&lines, 5), 4); // 1 + 2 + 1 113 assert_eq!(visual_line_count(&lines, 5), 4); // 1 + 2 + 1
127 assert_eq!(visual_line_count(&lines, 6), 3); // 1 + 1 + 1 114 assert_eq!(visual_line_count(&lines, 6), 3); // 1 + 1 + 1
@@ -146,7 +133,10 @@ fn completions_wrap_within_the_requested_width() {
146 let commands = command_names(); 133 let commands = command_names();
147 let lines = completion_lines(&commands, 40); 134 let lines = completion_lines(&commands, 40);
148 135
149 assert_eq!(lines.first().map(String::as_str), Some("Possible completions:")); 136 assert_eq!(
137 lines.first().map(String::as_str),
138 Some("Possible completions:")
139 );
150 for line in &lines[1..] { 140 for line in &lines[1..] {
151 assert!( 141 assert!(
152 line.len() <= 40, 142 line.len() <= 40,
@@ -208,10 +198,7 @@ fn pong_is_formatted_to_one_decimal() {
208fn host_lines_fit_an_80_column_terminal() { 198fn host_lines_fit_an_80_column_terminal() {
209 let fingerprint = "a4d6f80784154c2cb739a1df61ab3e9038ed731ee2e05c7611457ac741b3834c"; 199 let fingerprint = "a4d6f80784154c2cb739a1df61ab3e9038ed731ee2e05c7611457ac741b3834c";
210 let lines = host_lines(&[ 200 let lines = host_lines(&[
211 ( 201 ("127.0.0.1:11525".to_string(), Some(fingerprint.to_string())),
212 "127.0.0.1:11525".to_string(),
213 Some(fingerprint.to_string()),
214 ),
215 ("unknown.example:443".to_string(), None), 202 ("unknown.example:443".to_string(), None),
216 ]); 203 ]);
217 204
@@ -233,10 +220,7 @@ fn hosts_sharing_a_fingerprint_are_shown_as_one_server() {
233 let lines = host_lines(&[ 220 let lines = host_lines(&[
234 ("10.0.0.100:11525".to_string(), Some(key.to_string())), 221 ("10.0.0.100:11525".to_string(), Some(key.to_string())),
235 ("127.0.0.1:11525".to_string(), Some(key.to_string())), 222 ("127.0.0.1:11525".to_string(), Some(key.to_string())),
236 ( 223 ("other.example:11525".to_string(), Some("ff".repeat(32))),
237 "other.example:11525".to_string(),
238 Some("ff".repeat(32)),
239 ),
240 ]); 224 ]);
241 225
242 assert_eq!( 226 assert_eq!(
@@ -264,7 +248,10 @@ fn hosts_without_a_fingerprint_are_never_merged() {
264 assert!(lines.contains(&" a.example:443".to_string())); 248 assert!(lines.contains(&" a.example:443".to_string()));
265 assert!(lines.contains(&" b.example:443".to_string())); 249 assert!(lines.contains(&" b.example:443".to_string()));
266 assert_eq!( 250 assert_eq!(
267 lines.iter().filter(|line| line.contains("no fingerprint")).count(), 251 lines
252 .iter()
253 .filter(|line| line.contains("no fingerprint"))
254 .count(),
268 2 255 2
269 ); 256 );
270} 257}