From 9c24d8c7c350c0dae9d3d0aac0e6350a76750a46 Mon Sep 17 00:00:00 2001 From: Taylor Bockman Date: Wed, 13 Dec 2017 21:22:08 -0800 Subject: [PATCH] implement and test ready function --- src/lib.rs | 3 ++- tests/lib.rs | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ef6286e..4557ee8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,7 +75,8 @@ where write!(&mut self.writer, "{}", commands::UCIOK).expect("failed to send `uciok` command"); } + /// Sends `readyok` to the GUI pub fn ready(&mut self) { - // TODO: TESTS TO MAKE SURE IT SENDS READYOK + write!(&mut self.writer, "{}", commands::ReADYOK).expect("failed to send `readyok` command"); } } diff --git a/tests/lib.rs b/tests/lib.rs index 333eba4..1321868 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -14,7 +14,7 @@ fn instantiate_new_engine() { } #[test] -fn send_indentification_data() { +fn send_identification_data() { let input = b"UNUSED"; let mut output = Vec::new(); @@ -27,6 +27,19 @@ fn send_indentification_data() { // NOTE: This looks weird bceause you'd think it would store each insertion into the output buffer // as a separate element of that buffer, but it really just appends the two strings since in reality // the buffer would be flushed after reading. - assert_eq!(str::from_utf8(&output).unwrap_or("Unwrapping output failed in test #2"), + assert_eq!(str::from_utf8(&output).unwrap_or("Unwrapping output failed in send_identification_data"), "id name test_name\nid author test\n"); } + +#[test] +fn send_readyok() { + let input = b"UNUSED"; + let mut output = Vec::new(); + { + let mut e = Engine::new("test_name", "test", &input[..], &mut output); + e.ready(); + } + + assert_eq!(str::from_utf8(&output).unwrap_or("Unwrapping output failed in send_readyok"), + "readyok\n"); +}