Skip to content

Commit

Permalink
Fix uint64 zero conformance test
Browse files Browse the repository at this point in the history
  • Loading branch information
mydogisbox committed Aug 14, 2024
1 parent a58e4e5 commit 2164b03
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
16 changes: 16 additions & 0 deletions interpreter/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
6 changes: 3 additions & 3 deletions parser/src/cel.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
<s:r"-?0[xX][0-9a-fA-F]+"> => Atom::Int(i64::from_str_radix(&s[1..], 16).unwrap()),
<s:r"[0-9]+[uU]"> => Atom::UInt(s[..s.len()-1].parse().unwrap()),
<s:r"-?0[xX][0-9a-fA-F]+[uU]"> => 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()),
Expand Down

0 comments on commit 2164b03

Please sign in to comment.