KCL: If-else expressions (#4022)
Closes https://github.com/KittyCAD/modeling-app/issues/3677 You can review each commit separately, they're neat commits with logical purpose in each. Future enhancements: - https://github.com/KittyCAD/modeling-app/issues/4015 - https://github.com/KittyCAD/modeling-app/issues/4020 - Right now the parser errors are not very good, especially if you forget to put an expression in the end of an if/else block
This commit is contained in:
28
src/wasm-lib/tests/executor/inputs/no_visuals/if_else.kcl
Normal file
28
src/wasm-lib/tests/executor/inputs/no_visuals/if_else.kcl
Normal file
@ -0,0 +1,28 @@
|
||||
// This tests evaluating if-else expressions.
|
||||
|
||||
let a = if true {
|
||||
3
|
||||
} else if true {
|
||||
4
|
||||
} else {
|
||||
5
|
||||
}
|
||||
assertEqual(a, 3, 0.001, "the 'if' branch gets returned")
|
||||
|
||||
let b = if false {
|
||||
3
|
||||
} else if true {
|
||||
4
|
||||
} else {
|
||||
5
|
||||
}
|
||||
assertEqual(b, 4, 0.001, "the 'else if' branch gets returned")
|
||||
|
||||
let c = if false {
|
||||
3
|
||||
} else if false {
|
||||
4
|
||||
} else {
|
||||
5
|
||||
}
|
||||
assertEqual(c, 5, 0.001, "the 'else' branch gets returned")
|
@ -0,0 +1,5 @@
|
||||
let x = if true {
|
||||
let y = 1
|
||||
} else {
|
||||
let z = 1
|
||||
}
|
@ -90,4 +90,9 @@ gen_test_fail!(
|
||||
"semantic: cannot use % outside a pipe expression"
|
||||
);
|
||||
gen_test!(sketch_in_object);
|
||||
gen_test!(if_else);
|
||||
// gen_test_fail!(
|
||||
// if_else_no_expr,
|
||||
// "syntax: blocks inside an if/else expression must end in an expression"
|
||||
// );
|
||||
gen_test!(add_lots);
|
||||
|
Reference in New Issue
Block a user