From 64f097b0ffee0b0ffdabe5e983640027ba4a1d1a Mon Sep 17 00:00:00 2001 From: Raymon Zutekouw <40148684+Raymonzut@users.noreply.github.com> Date: Fri, 14 Jan 2022 22:41:19 +0100 Subject: [PATCH] Test parse_constant --- src/main.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main.rs b/src/main.rs index ea5ae19..5cf6497 100644 --- a/src/main.rs +++ b/src/main.rs @@ -249,3 +249,23 @@ fn main() -> Result<(), Box> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_parse_constant() { + assert_eq!(parse_constant(&"42"), Ok(42)); + assert_eq!(parse_constant(&"0x2A"), Ok(42)); + assert_eq!(parse_constant(&"\"*\""), Ok(42)); + + assert!( + matches!( + parse_constant(&"\'*\'"), + Err(std::num::ParseIntError { .. }) + ), + "Char literals are declared with \"_\", not \'_\'" + ); + } +}