Test parse_constant

This commit is contained in:
2022-01-14 22:56:47 +01:00
committed by Raymon Zutekouw
parent c8126f2891
commit b7cc02a2c1
+20
View File
@@ -249,3 +249,23 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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 \'_\'"
);
}
}