From 474d648ae4139cd6726bd9bdc0c0b45858aa6dc3 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Sun, 31 Mar 2024 18:08:19 -0400 Subject: [PATCH] Write some tests to handle date parsing with a range of days --- sgf/src/game.rs | 36 ++++++++++++++++++++++++++++++++++++ sgf/src/go.rs | 11 +++++++++++ sgf/src/parser.rs | 9 +++++++++ 3 files changed, 56 insertions(+) diff --git a/sgf/src/game.rs b/sgf/src/game.rs index d11b677..b6febf0 100644 --- a/sgf/src/game.rs +++ b/sgf/src/game.rs @@ -911,4 +911,40 @@ mod file_test { }, ); } + + #[ignore] + #[test] + fn it_handles_shuwa_genan_file() { + with_file( + std::path::Path::new("test_data/2019.02.15_shuwa_genan_annotated.sgf"), + |trees| { + assert_eq!(trees.len(), 1); + let game = &trees[0]; + assert_eq!(game.game_type, GameType::Go); + assert_eq!( + game.board_size, + Size { + width: 19, + height: 19 + } + ); + assert_eq!( + game.black_player, + Player { + name: Some("Honinbo Shuwa".to_owned()), + rank: Some("7P".to_owned()), + team: None + } + ); + assert_eq!( + game.white_player, + Player { + name: Some("Inoue(Genan)Inseki".to_owned()), + rank: Some("8P".to_owned()), + team: None + } + ); + }, + ) + } } diff --git a/sgf/src/go.rs b/sgf/src/go.rs index 2a605e0..5340ef3 100644 --- a/sgf/src/go.rs +++ b/sgf/src/go.rs @@ -463,4 +463,15 @@ mod tests { }, ); } + + // This is a file + #[test] + fn it_handles_shuwa_genan_file() { + with_file( + std::path::Path::new("test_data/2020 USGO DDK, Round 1.sgf"), + |trees| { + assert_eq!(trees.len(), 2); + }, + ) + } } diff --git a/sgf/src/parser.rs b/sgf/src/parser.rs index d395dd1..ec7bb8b 100644 --- a/sgf/src/parser.rs +++ b/sgf/src/parser.rs @@ -1252,6 +1252,15 @@ mod date_test { Date::Date(NaiveDate::from_ymd_opt(1996, 12, 28).unwrap()) ]) ); + + assert_matches!( + parse_date_field::>().parse("1842-5-16-18"), + Ok((_, date)) => assert_eq!(date, vec![ + Date::Date(NaiveDate::from_ymd_opt(1842, 5, 16).unwrap()), + Date::Date(NaiveDate::from_ymd_opt(1842, 5, 17).unwrap()), + Date::Date(NaiveDate::from_ymd_opt(1842, 5, 18).unwrap()), + ]) + ); } #[test]