Skip to content

Commit

Permalink
fix when more than one line instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
nbittich committed Aug 20, 2024
1 parent 8a48cb0 commit f05f68a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion adana-script/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ fn parse_simple_instruction(s: &str) -> Res<Value> {
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]),
),
Expand Down
16 changes: 16 additions & 0 deletions adana-script/src/tests/struc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
);
}
22 changes: 22 additions & 0 deletions adana-script/src/tests/test_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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())
);
}

0 comments on commit f05f68a

Please sign in to comment.