fixes negative args in function (#707)
* updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
@ -620,6 +620,22 @@ pub async fn execute(
|
||||
let result = call_expr.execute(memory, &mut pipe_info, engine).await?;
|
||||
args.push(result);
|
||||
}
|
||||
Value::BinaryExpression(binary_expression) => {
|
||||
let result = binary_expression.get_result(memory, &mut pipe_info, engine).await?;
|
||||
args.push(result);
|
||||
}
|
||||
Value::UnaryExpression(unary_expression) => {
|
||||
let result = unary_expression.get_result(memory, &mut pipe_info, engine).await?;
|
||||
args.push(result);
|
||||
}
|
||||
Value::ObjectExpression(object_expression) => {
|
||||
let result = object_expression.execute(memory, &mut pipe_info, engine).await?;
|
||||
args.push(result);
|
||||
}
|
||||
Value::ArrayExpression(array_expression) => {
|
||||
let result = array_expression.execute(memory, &mut pipe_info, engine).await?;
|
||||
args.push(result);
|
||||
}
|
||||
// We do nothing for the rest.
|
||||
_ => (),
|
||||
}
|
||||
@ -679,7 +695,7 @@ pub async fn execute(
|
||||
message: format!(
|
||||
"Expected {} arguments, got {}",
|
||||
function_expression.params.len(),
|
||||
args.len()
|
||||
args.len(),
|
||||
),
|
||||
source_ranges: vec![(&function_expression).into()],
|
||||
}));
|
||||
|
@ -3484,7 +3484,6 @@ let other_thing = 2 * cos(3)"#;
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore] // ignore until more stack fixes
|
||||
fn test_parse_pipes_on_pipes() {
|
||||
let code = include_str!("../../tests/executor/inputs/pipes_on_pipes.kcl");
|
||||
|
||||
@ -3492,4 +3491,23 @@ let other_thing = 2 * cos(3)"#;
|
||||
let parser = Parser::new(tokens);
|
||||
parser.ast().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_negative_arguments() {
|
||||
let some_program_string = r#"fn box = (p, h, l, w) => {
|
||||
const myBox = startSketchAt(p)
|
||||
|> line([0, l], %)
|
||||
|> line([w, 0], %)
|
||||
|> line([0, -l], %)
|
||||
|> close(%)
|
||||
|> extrude(h, %)
|
||||
|
||||
return myBox
|
||||
}
|
||||
let myBox = box([0,0], -3, -16, -10)
|
||||
show(myBox)"#;
|
||||
let tokens = crate::token::lexer(some_program_string);
|
||||
let parser = Parser::new(tokens);
|
||||
parser.ast().unwrap();
|
||||
}
|
||||
}
|
||||
|
@ -227,3 +227,28 @@ show(body)"#;
|
||||
let result = execute_and_snapshot(code).await.unwrap();
|
||||
twenty_twenty::assert_image("tests/executor/outputs/close_arc.png", &result, 1.0);
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn test_negative_args() {
|
||||
let code = r#"const width = 5
|
||||
const height = 10
|
||||
const length = 12
|
||||
|
||||
fn box = (sk1, sk2, scale) => {
|
||||
const boxSketch = startSketchAt([sk1, sk2])
|
||||
|> line([0, scale], %)
|
||||
|> line([scale, 0], %)
|
||||
|> line([0, -scale], %)
|
||||
|> close(%)
|
||||
|> extrude(scale, %)
|
||||
return boxSketch
|
||||
}
|
||||
|
||||
box(0, 0, 5)
|
||||
box(10, 23, 8)
|
||||
let thing = box(-12, -15, 10)
|
||||
box(-20, -5, 10)"#;
|
||||
|
||||
let result = execute_and_snapshot(code).await.unwrap();
|
||||
twenty_twenty::assert_image("tests/executor/outputs/negative_args.png", &result, 1.0);
|
||||
}
|
||||
|
BIN
src/wasm-lib/tests/executor/outputs/negative_args.png
Normal file
BIN
src/wasm-lib/tests/executor/outputs/negative_args.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 78 KiB |
Reference in New Issue
Block a user