From 8b5973475faf944f6462996cec455700e5356be8 Mon Sep 17 00:00:00 2001 From: Matthew Sparks Date: Fri, 17 Sep 2021 22:18:23 -0400 Subject: [PATCH] Forgot to fix tests, fixing keep/drop Err case --- dicebot/src/basic/parser.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dicebot/src/basic/parser.rs b/dicebot/src/basic/parser.rs index e8d4ad0..3702c98 100644 --- a/dicebot/src/basic/parser.rs +++ b/dicebot/src/basic/parser.rs @@ -41,7 +41,7 @@ fn parse_dice(input: &str) -> IResult<&str, Dice> { // if ok, keep expression is present Ok(r) => (r.1.1, r.0), // otherwise absent and keep all dice - Err(_) => (input, "") + Err(_) => (count, input) }; // check for drop expression to drop highest dice (2d20dh1) @@ -49,7 +49,7 @@ fn parse_dice(input: &str) -> IResult<&str, Dice> { // if ok, keep expression is present Ok(r) => (r.1.1, r.0), // otherwise absent and keep all dice - Err(_) => (input, "") + Err(_) => ("0", input) }; let count: u32 = count.parse().unwrap(); @@ -149,9 +149,9 @@ mod tests { assert_eq!(parse_dice("12d10k11"), Ok(("", Dice::new(12, 10, 11, 0)))); assert_eq!(parse_dice("12d10k13"), Ok(("", Dice::new(12, 10, 12, 0)))); assert_eq!(parse_dice("12d10k0"), Ok(("", Dice::new(12, 10, 12, 0)))); - assert_eq!(parse_dice("20d40d5"), Ok(("", Dice::new(20, 40, 20, 5)))); - assert_eq!(parse_dice("8d7d9"), Ok(("", Dice::new(8, 7, 8, 0)))); - assert_eq!(parse_dice("8d7d8"), Ok(("", Dice::new(8, 7, 8, 0)))); + assert_eq!(parse_dice("20d40dh5"), Ok(("", Dice::new(20, 40, 20, 5)))); + assert_eq!(parse_dice("8d7dh9"), Ok(("", Dice::new(8, 7, 8, 0)))); + assert_eq!(parse_dice("8d7dh8"), Ok(("", Dice::new(8, 7, 8, 0)))); } #[test] @@ -234,7 +234,7 @@ mod tests { )) ); assert_eq!( - parse_element_expression("\t3d4k2 + 7 - 5 - 6d12d3 + 1d1 + 53 1d5 "), + parse_element_expression("\t3d4k2 + 7 - 5 - 6d12dh3 + 1d1 + 53 1d5 "), Ok(( " 1d5 ", ElementExpression(vec![