From 8b50273b43be4c76012dccc6ba65f00ed41c83bb Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Thu, 20 Mar 2025 02:10:12 -0400 Subject: [PATCH] Board: add test for formatting --- src/repr/board.rs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/repr/board.rs b/src/repr/board.rs index 616340f..6d1cc21 100644 --- a/src/repr/board.rs +++ b/src/repr/board.rs @@ -96,9 +96,9 @@ impl fmt::Display for Board { const SPACE_PADDING: &str = const_str::repeat!(" ", PADDING); // Print numbers at top so the board can be read more easier - write!(f, "{} ", SPACE_PADDING)?; + write!(f, "{}", SPACE_PADDING)?; for j in (0..Self::SIZE).rev() { - write!(f, "{:0PADDING$} ", j)?; + write!(f, " {:0PADDING$}", j)?; } writeln!(f)?; @@ -530,4 +530,31 @@ mod test { assert_eq!(board.get((6, 0).into()), Some(Piece::Black), "\n{}", board); } + + #[test] + fn format_test() { + assert_eq!( + Board::new().starting_pos().to_string().as_str(), + " 7 6 5 4 3 2 1 0 + ----------------- +7| | | | | | | | | + ----------------- +6| | | | | | | | | + ----------------- +5| | | | | | | | | + ----------------- +4| | | |■|□| | | | + ----------------- +3| | | |□|■| | | | + ----------------- +2| | | | | | | | | + ----------------- +1| | | | | | | | | + ----------------- +0| | | | | | | | | + ----------------- +White Score: 2 +Black Score: 2\n" + ); + } }