From 3eb729653aafd1b576b217755cf8e5507d42b259 Mon Sep 17 00:00:00 2001 From: Taylor Bockman Date: Tue, 12 Dec 2017 10:21:58 -0800 Subject: [PATCH] lol --- src/lib.rs | 13 ++++++++++--- tests/lib.rs | 26 ++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 452512f..46621cf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,8 @@ mod commands; +use std::io::{BufRead, Write}; + #[derive(Debug)] pub struct Engine<'a, R, W> { @@ -31,11 +33,16 @@ pub struct Engine<'a, R, W> { /// Additionally this code should have a parser. You call it with the reader supplied and it waits for a command /// and parses it into a tuple of some kind for the user. -impl<'a, R, W> Engine<'a, R, W> { +impl<'a, R, W> Engine<'a, R, W> +where + R: BufRead, + W: Write, +{ pub fn new(name: &'a str, author: &'a str, reader: R, writer: W) -> Engine<'a, R, W> { // TODO: This should also take an EngineOptions thing that indicates which options are supported // so that when called it can send them easily. + // Engine options are all optional and appeared to be fixed by the UCI standard. Engine { name: name, @@ -47,8 +54,8 @@ impl<'a, R, W> Engine<'a, R, W> { /// Sends identification messages to the writer for the GUI to pick up pub fn identify(&mut self) { - let name_id: String = format!("{} {} {}", commands::ID, commands::NAME, self.name); - let author_id: String = format!("{} {} {}", commands::ID, commands::AUTHOR, self.author); + let name_id: String = format!("{} {} {}\n", commands::ID, commands::NAME, self.name); + let author_id: String = format!("{} {} {}\n", commands::ID, commands::AUTHOR, self.author); // For these two writes we can panic - there's no possibility of recovery if the engine fails at this stage write!(&mut self.writer, "{}", name_id).expect("failed to send name identification to writer"); diff --git a/tests/lib.rs b/tests/lib.rs index 77c9bb2..221ea68 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -4,8 +4,30 @@ use uci::Engine; #[test] fn instantiate_new_engine() { - let e: Engine; - e = Engine::new("test_name", "test"); + let input = b"UNUSED"; + let mut output = Vec::new(); + + let e = Engine::new("test_name", "test", &input[..], &mut output); assert_eq!(e.name, "test_name"); assert_eq!(e.author, "test"); } + +#[test] +fn send_indentification_data() { + let input = b"UNUSED"; + let mut output = Vec::new(); + + // We need to scope this so that the mutable borrow ends and we can test it safely + { + let mut e = Engine::new("test_name", "test", &input[..], &mut output); + e.identify(); + } + + println!("HERE!!!!!!!"); + println!("{:?}") + + + // To get this to play nicely the vector needs to be converted to utf-8 string(s) for comparison + + //assert_eq!(output, [b"id name test_name\n", b"id author test\n"]); +}