|
|
|
// TODO: Write parser tests before implementing the parser.
|
|
|
|
// Start with setoption and branch out from there. The commands are finite so you should be able
|
|
|
|
// to write a test for each one. Take the time to do this right so that the rest of this project is
|
|
|
|
// a cakewalk
|
|
|
|
//
|
|
|
|
// // Also remember to fix the constant thing noted in the lib.rs for uci.... lol
|
|
|
|
//
|
|
|
|
|
|
|
|
extern crate uci;
|
|
|
|
|
|
|
|
use uci::parser;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_setoption() {
|
|
|
|
let s = "setoption name Hash value 32\n";
|
|
|
|
let expected = parser::TokenResult::new(
|
|
|
|
parser::Token::SETOPTION,
|
|
|
|
parser::Left(Some(
|
|
|
|
[
|
|
|
|
("name", parser::CommandValue::Text(String::from("Hash"))),
|
|
|
|
("value", parser::CommandValue::Int(32)),
|
|
|
|
].iter().cloned().collect())
|
|
|
|
));
|
|
|
|
|
|
|
|
let p = parser::Parser::new();
|
|
|
|
|
|
|
|
match p.parse(s) {
|
|
|
|
Ok(r) => {
|
|
|
|
assert_eq!(r, expected);
|
|
|
|
}
|
|
|
|
Err(_) => panic!("failed to parse setoption as expected")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_uci() {
|
|
|
|
let s = "uci\n";
|
|
|
|
let expected = parser::TokenResult::new(
|
|
|
|
parser::Token::UCI, parser::Left(None);
|
|
|
|
|
|
|
|
let p = parser::Parser::new();
|
|
|
|
|
|
|
|
match p.parse(s) {
|
|
|
|
Ok(r) => {
|
|
|
|
assert_eq!(r, expected);
|
|
|
|
}
|
|
|
|
Err(_) => panic!("failed to parse uci as expected")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_debug() {
|
|
|
|
let s = "debug on\n";
|
|
|
|
let expected = parser::TokenResult::new(
|
|
|
|
parser::Token::DEBUG, parser::Right("on")
|
|
|
|
);
|
|
|
|
|
|
|
|
let p = parser::Parser::new();
|
|
|
|
|
|
|
|
match p.parse(s) {
|
|
|
|
Ok(r) => {
|
|
|
|
assert_eq!(r, expected);
|
|
|
|
}
|
|
|
|
Err(_) => panic!("failed to parse uci as expected")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn bad_parse() {
|
|
|
|
assert_eq!(true, false);
|
|
|
|
}
|