From 2164b0338c1e988c91ca9c4d99c6d2f39a0a5645 Mon Sep 17 00:00:00 2001 From: Michael Ciccotti Date: Tue, 13 Aug 2024 20:48:47 -0500 Subject: [PATCH] Fix uint64 zero conformance test --- interpreter/src/ser.rs | 16 ++++++++++++++++ parser/src/cel.lalrpop | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/interpreter/src/ser.rs b/interpreter/src/ser.rs index a81f2cf..a0f8772 100644 --- a/interpreter/src/ser.rs +++ b/interpreter/src/ser.rs @@ -568,6 +568,22 @@ mod tests { use serde_bytes::Bytes; use std::{collections::HashMap, iter::FromIterator, sync::Arc}; + macro_rules! primitive_test { + ($functionName:ident, $strValue: literal, $value: literal) => { + #[test] + fn $functionName() { + let program = Program::compile($strValue).unwrap(); + let result = program.execute(&Context::default()); + assert_eq!(Value::from($value), result.unwrap()); + } + }; + } + + primitive_test!(test_u64_zero, "0u", 0_u64); + primitive_test!(test_i64_zero, "0", 0_i64); + primitive_test!(test_f64_zero, "0.0", 0_f64); + //primitive_test!(test_f64_zero, "0.", 0_f64); this test fails + #[test] fn test_primitives() { #[derive(Serialize)] diff --git a/parser/src/cel.lalrpop b/parser/src/cel.lalrpop index 44343d5..c28fd15 100644 --- a/parser/src/cel.lalrpop +++ b/parser/src/cel.lalrpop @@ -122,9 +122,9 @@ RelationOp: RelationOp = { Atom: Atom = { // Integer literals. Annoying to parse :/ r"-?[0-9]+" => Atom::Int(<>.parse().unwrap()), - r"-?0[xX]([0-9a-fA-F]+)" => Atom::Int(i64::from_str_radix(<>, 16).unwrap()), - r"-?[0-9]+ [uU]" => Atom::UInt(<>.parse().unwrap()), - r"-?0[xX]([0-9a-fA-F]+) [uU]" => Atom::UInt(u64::from_str_radix(<>, 16).unwrap()), + => Atom::Int(i64::from_str_radix(&s[1..], 16).unwrap()), + => Atom::UInt(s[..s.len()-1].parse().unwrap()), + => Atom::UInt(u64::from_str_radix(&s[1..s.len()-1], 16).unwrap()), // Float with decimals and optional exponent r"([-+]?[0-9]*\.[0-9]+([eE][-+]?[0-9]+)?)" => Atom::Float(<>.parse().unwrap()),