[position] Add a fen! macro

This commit is contained in:
Eryn Wells 2024-01-30 08:35:02 -08:00
parent 8cdb9f13b4
commit 357b811518

View file

@ -4,6 +4,12 @@ use crate::{r#move::Castle, Position, PositionBuilder};
use chessfriend_core::{piece, Color, File, Piece, PlacedPiece, Rank, Square};
use std::fmt::Write;
macro_rules! fen {
($fen_string:literal) => {
Position::from_fen_str($fen_string)
};
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ToFenError {
FmtError(std::fmt::Error),
@ -270,11 +276,8 @@ mod tests {
#[test]
fn from_starting_fen() {
let pos =
Position::from_fen_str("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1")
.unwrap();
let pos = fen!("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1").unwrap();
let expected = Position::starting();
assert_eq!(pos, expected, "{pos:#?}\n{expected:#?}");
}
}