#[macro_export]
macro_rules! frame {
() => ($crate::Frame::empty());
(-) => (frame!(0));
(--) => (frame!(0, 0));
(-/) => (frame!(0, /));
(-/-) => (frame!(0, /, 0));
(-/, $c:expr) => (frame!(0, /, $c));
(x) => ($crate::Frame::strike());
(xx) => ($crate::Frame::with_bonus($crate::Score::STRIKE, $crate::Score::STRIKE, $crate::Score::EMPTY));
(xxx) => ($crate::Frame::triple_strike());
(x-) => (frame!(x, 0));
(x--) => (frame!(x, 0, 0));
(x-/) => (frame!(x, 0, /));
(x-, $c:expr) => (frame!(x, 0, $c));
(x, $b:expr) => ($crate::Frame::with_bonus($crate::Score::STRIKE, $crate::Score::PINS($b), $crate::Score::EMPTY));
(x, $b:expr, /) => ($crate::Frame::with_bonus($crate::Score::STRIKE, $crate::Score::PINS($b), $crate::Score::SPARE));
(xx, $c:expr) => ($crate::Frame::with_bonus($crate::Score::STRIKE, $crate::Score::STRIKE, $crate::Score::PINS($c)));
($a:expr) => ($crate::Frame::new($crate::Score::PINS($a), $crate::Score::EMPTY));
($a:expr, $b:expr) => ($crate::Frame::new($crate::Score::PINS($a), $crate::Score::PINS($b)));
($a:expr, /) => ($crate::Frame::spare($a));
($a:expr, /x) => ($crate::Frame::with_bonus($crate::Score::PINS($a), $crate::Score::SPARE, $crate::Score::STRIKE));
($a:expr, /, $c:expr) => ($crate::Frame::with_bonus($crate::Score::PINS($a), $crate::Score::SPARE, $crate::Score::PINS($c)));
}
#[macro_export]
macro_rules! parse_score {
($($a:literal $($b:literal $($c:literal)?)?);*) => ({
let mut frames = vec![];
$({
frames.push(vec![$a, $($b, $($c)?)?]);
})*
$crate::parse_score(frames)
});
($($a:expr $(, $b:expr $(, $c:expr)?)?);*) => ({
let mut frames = vec![];
$({
frames.push(vec![$a, $($b, $($c)?)?]);
})*
$crate::parse_score(frames)
});
}
#[macro_export]
macro_rules! parse_raw_score {
(bonus $($a:expr)*) => ({
let mut shots = vec![];
$({
shots.push($a)
})*
$crate::parse_raw_score(shots, true)
});
(bonus $($a:expr),*) => ({
let mut shots = vec![];
$({
shots.push($a)
})*
$crate::parse_raw_score(shots, true)
});
($($a:expr)*) => ({
let mut shots = vec![];
$({
shots.push($a)
})*
$crate::parse_raw_score(shots, false)
});
($($a:expr),*) => ({
let mut shots = vec![];
$({
shots.push($a)
})*
$crate::parse_raw_score(shots, false)
});
}
#[cfg(test)]
mod tests {
#[test]
fn triple_strike() {
let game = parse_raw_score!(bonus 10 10 10);
assert_eq!(game.score(), 30);
}
}