From 78db585b02e0880b6b4b2f8ce273dfc2bbb21d20 Mon Sep 17 00:00:00 2001 From: Bijan Veyssi Date: Wed, 3 Jan 2024 14:41:43 +0100 Subject: [PATCH] Fix precedence value of array Array must have the same precedence as const since they are --- src/operator/mod.rs | 2 +- tests/integration.rs | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/operator/mod.rs b/src/operator/mod.rs index 663bb78..b5ea642 100644 --- a/src/operator/mod.rs +++ b/src/operator/mod.rs @@ -131,7 +131,7 @@ impl Operator { | AndAssign | OrAssign => 50, Tuple => 40, - Array => 45, + Array => 200, Chain => 0, Const { .. } => 200, diff --git a/tests/integration.rs b/tests/integration.rs index 9297e3d..0a19ac9 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -1565,6 +1565,29 @@ fn test_array_definitions() { ); } +#[test] +fn test_array_invalid_computation() { + assert_eq!( + eval("{}+"), + Err(EvalexprError::WrongOperatorArgumentAmount { + expected: 2, + actual: 1 + }) + ); + assert_eq!( + eval("1+{}"), + Err(EvalexprError::ExpectedNumberOrString { + actual: Value::Array(vec![]) + }) + ); + assert_eq!( + eval("{1, 2, 3}+2"), + Err(EvalexprError::ExpectedNumberOrString { + actual: Value::Array(vec![1.into(), 2.into(), 3.into()]) + }) + ); +} + #[test] fn test_tuple_definitions() { assert_eq!(eval_empty("()"), Ok(()));