From f05f68a0b67317ff74589919874ab64b954f84c3 Mon Sep 17 00:00:00 2001 From: Nordine Bittich Date: Tue, 20 Aug 2024 23:41:48 +0200 Subject: [PATCH] fix when more than one line instruction --- adana-script/src/parser.rs | 2 +- adana-script/src/tests/struc.rs | 16 ++++++++++++++++ adana-script/src/tests/test_array.rs | 22 ++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/adana-script/src/parser.rs b/adana-script/src/parser.rs index 2f96c87..a3cdac8 100644 --- a/adana-script/src/parser.rs +++ b/adana-script/src/parser.rs @@ -817,7 +817,7 @@ fn parse_simple_instruction(s: &str) -> Res { tuple(( alt((parse_multidepth_access, parse_fn_call)), parse_operation, - parse_block_paren_opt, + parse_expression, )), |(k, o, v)| Value::Expression(vec![k, o, v]), ), diff --git a/adana-script/src/tests/struc.rs b/adana-script/src/tests/struc.rs index 7ce60b8..05007dd 100644 --- a/adana-script/src/tests/struc.rs +++ b/adana-script/src/tests/struc.rs @@ -386,3 +386,19 @@ fn test_struc_access_key9() { Primitive::String("hello world".to_string()) ); } +#[test] +fn test_struc_access_key10() { + let mut ctx = BTreeMap::new(); + let expr = r#"x= struct{x:"hello"}.x + " world" + "!" + z = "whatever" + 9 + "#; + let _ = compute(expr, &mut ctx, "N/A").unwrap(); + assert_eq!( + ctx["x"].read().unwrap().clone(), + Primitive::String("hello world!".to_string()) + ); + assert_eq!( + ctx["z"].read().unwrap().clone(), + Primitive::String("whatever9".to_string()) + ); +} diff --git a/adana-script/src/tests/test_array.rs b/adana-script/src/tests/test_array.rs index afdd4e3..4c3938b 100644 --- a/adana-script/src/tests/test_array.rs +++ b/adana-script/src/tests/test_array.rs @@ -239,6 +239,14 @@ fn test_array_access_from_fn_return() { Primitive::U8(4), ]) ); + let expr = r#"x = ()=> {[1,2,7,8,9]}() + 4 + z="whatever" + "#; + let _ = compute(expr, &mut ctx, "N/A").unwrap(); + assert_eq!( + ctx["z"].read().unwrap().clone(), + Primitive::String("whatever".to_string()) + ); } #[test] #[serial] @@ -247,4 +255,18 @@ fn test_array_access_key_index() { let expr = r#"x = ()=> {[1,2,7,8,9]}()[3] + 4"#; let _ = compute(expr, &mut ctx, "N/A").unwrap(); assert_eq!(ctx["x"].read().unwrap().clone(), Primitive::Int(12)); + let expr = r#"x = ()=> {[1,2,7,8,9]}()[3] + 4 + z="whatever" + "!" + ":)" + if z == "whatever!:)" { + z = "my test " + z + }else { + z = "no test" + } + "#; + let _ = compute(expr, &mut ctx, "N/A").unwrap(); + + assert_eq!( + ctx["z"].read().unwrap().clone(), + Primitive::String("my test whatever!:)".to_string()) + ); }