diff --git a/sgf/src/go.rs b/sgf/src/go.rs index ea6faa4..3f24992 100644 --- a/sgf/src/go.rs +++ b/sgf/src/go.rs @@ -395,7 +395,7 @@ mod tests { } #[test] - fn it_presents_a_mainline() { + fn it_presents_the_mainline_of_game_without_branches() { with_file( std::path::Path::new("test_data/2020 USGO DDK, Round 1.sgf"), |trees| { @@ -403,21 +403,112 @@ mod tests { let tree = &trees[0]; let node = &tree.root; - println!("{:?}", node); + assert_eq!(node.properties.len(), 16); + let expected_properties = vec![ + Property { + ident: "GM".to_owned(), + values: vec!["1".to_owned()], + }, + Property { + ident: "FF".to_owned(), + values: vec!["4".to_owned()], + }, + Property { + ident: "CA".to_owned(), + values: vec!["UTF-8".to_owned()], + }, + Property { + ident: "AP".to_owned(), + values: vec!["CGoban:3".to_owned()], + }, + Property { + ident: "ST".to_owned(), + values: vec!["2".to_owned()], + }, + Property { + ident: "RU".to_owned(), + values: vec!["AGA".to_owned()], + }, + Property { + ident: "SZ".to_owned(), + values: vec!["19".to_owned()], + }, + Property { + ident: "KM".to_owned(), + values: vec!["7.50".to_owned()], + }, + Property { + ident: "TM".to_owned(), + values: vec!["1800".to_owned()], + }, + Property { + ident: "OT".to_owned(), + values: vec!["5x30 byo-yomi".to_owned()], + }, + Property { + ident: "PW".to_owned(), + values: vec!["Geckoz".to_owned()], + }, + Property { + ident: "PB".to_owned(), + values: vec!["savanni".to_owned()], + }, + Property { + ident: "BR".to_owned(), + values: vec!["23k".to_owned()], + }, + Property { + ident: "DT".to_owned(), + values: vec!["2020-08-05".to_owned()], + }, + Property { + ident: "PC".to_owned(), + values: vec!["The KGS Go Server at http://www.gokgs.com/".to_owned()], + }, + Property { + ident: "RE".to_owned(), + values: vec!["W+17.50".to_owned()], + }, + ]; - let node = node.next(); - println!("{:?}", node); + for i in 0..16 { + assert_eq!(node.properties[i], expected_properties[i]); + } - /* - assert_eq!( - node.find_prop("B"), - Some(Property { + let node = node.next().unwrap(); + let expected_properties = vec![ + Property { ident: "B".to_owned(), - values: vec!["dp".to_owned()] - }) - ); - */ - assert!(false); + values: vec!["pp".to_owned()], + }, + Property { + ident: "BL".to_owned(), + values: vec!["1795.449".to_owned()], + }, + Property { + ident: "C".to_owned(), + values: vec!["Geckoz [?]: Good game\nsavanni [23k?]: There we go! This UI is... tough.\nsavanni [23k?]: Have fun! Talk to you at the end.\nGeckoz [?]: Yeah, OGS is much better; I'm a UX professional\n".to_owned()], + } + ]; + + for i in 0..3 { + assert_eq!(node.properties[i], expected_properties[i]); + } + + let node = node.next().unwrap(); + let expected_properties = vec![ + Property { + ident: "W".to_owned(), + values: vec!["dp".to_owned()], + }, + Property { + ident: "WL".to_owned(), + values: vec!["1765.099".to_owned()], + }, + ]; + for i in 0..2 { + assert_eq!(node.properties[i], expected_properties[i]); + } }, ); } diff --git a/sgf/src/lib.rs b/sgf/src/lib.rs index d30fa13..bd2937c 100644 --- a/sgf/src/lib.rs +++ b/sgf/src/lib.rs @@ -61,12 +61,11 @@ pub enum Game { Unsupported(tree::Tree), } -/* pub fn parse_sgf(input: &str) -> Result, Error> { let (_, trees) = parse_collection::>(input)?; Ok(trees .into_iter() - .map(|t| match t.sequence[0].find_prop("GM") { + .map(|t| match t.root.find_prop("GM") { Some(prop) if prop.values == vec!["1".to_owned()] => { Game::Go(go::Game::try_from(t).expect("properly structured game tree")) } @@ -74,7 +73,6 @@ pub fn parse_sgf(input: &str) -> Result, Error> { }) .collect::>()) } -*/ /* impl From<(&str, VerboseErrorKind)> for diff --git a/sgf/src/tree.rs b/sgf/src/tree.rs index 1d9a804..e1340a2 100644 --- a/sgf/src/tree.rs +++ b/sgf/src/tree.rs @@ -5,7 +5,6 @@ use nom::{ character::complete::{alpha1, digit1, multispace0, multispace1, none_of}, combinator::{opt, value}, multi::{many0, many1, separated_list1}, - sequence::delimited, IResult, }; use std::num::ParseIntError; @@ -228,7 +227,6 @@ pub fn parse_size<'a, E: nom::error::ParseError<&'a str>>( #[cfg(test)] mod test { use super::*; - use cool_asserts::assert_matches; const EXAMPLE: &'static str = "(;FF[4]C[root](;C[a];C[b](;C[c]) (;C[d];C[e]))