Skip to content

Commit

Permalink
Conformance test fixes (#79)
Browse files Browse the repository at this point in the history
* Fix uint64 zero conformance test

* Fix more integer conformance test failures
  • Loading branch information
mydogisbox authored Aug 16, 2024
1 parent 292b78c commit a5c6c2d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
26 changes: 25 additions & 1 deletion interpreter/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,32 @@ mod tests {
use serde_bytes::Bytes;
use std::{collections::HashMap, iter::FromIterator, sync::Arc};

macro_rules! primitive_test {
($functionName:ident, $strValue: literal, $value: expr) => {
#[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
primitive_test!(test_bool_false, "false", false);
primitive_test!(test_bool_true, "true", true);
primitive_test!(test_string_empty, "\"\"", "");
primitive_test!(test_string_non_empty, "\"test\"", "test");
primitive_test!(test_byte_ones, r#"b"\001\001""#, vec!(1_u8, 1_u8));
// primitive_test!(test_triple_double_quoted_string, #"r"""""""#, "");
// primitive_test!(test_triple_single_quoted_string, "r''''''", "");
primitive_test!(test_utf8_character_as_bytes, "b'ÿ'", vec!(195_u8, 191_u8));

#[test]
fn test_primitives() {
fn test_json_data_conversion() {
#[derive(Serialize)]
struct TestPrimitives {
bool: bool,
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.chars().filter(|&x| x != 'x' && x != 'X').collect::<String>(), 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.chars().filter(|&x| x != 'x' && x != 'X' && x != 'u' && x != 'U').collect::<String>(), 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 a5c6c2d

Please sign in to comment.