KCL: Comparison operators (#4025)
Add `==, !=, >, >=, <, <=` to the language parser, executor and tests. Closes https://github.com/KittyCAD/modeling-app/issues/4020 Currently these comparison operators are associative, allowing users to chain them, e.g. (x <= y <= z). This should not be allowed, will do in a follow-up. See https://github.com/KittyCAD/modeling-app/issues/4155
This commit is contained in:
@ -0,0 +1,13 @@
|
||||
assert(3 == 3, "equality")
|
||||
assert(3.0 == 3.0, "equality of floats")
|
||||
assert(3 != 4, "non-equality")
|
||||
assert(3.0 != 4.0, "non-equality of floats")
|
||||
assert(3 < 4, "lt")
|
||||
assert(3 <= 4, "lte but actually lt")
|
||||
assert(4 <= 4, "lte but actually eq")
|
||||
assert(4 > 3, "gt")
|
||||
assert(4 >= 3, "gte but actually gt")
|
||||
assert(3 >= 3, "gte but actually eq")
|
||||
|
||||
assert(0.0 == 0.0, "equality of zero")
|
||||
assert(0.0 == -0.0, "equality of zero and neg zero")
|
||||
@ -0,0 +1 @@
|
||||
assert(3 == 3 == 3, "this should not compile")
|
||||
@ -57,6 +57,7 @@ async fn run_fail(code: &str) -> KclError {
|
||||
|
||||
gen_test!(property_of_object);
|
||||
gen_test!(index_of_array);
|
||||
gen_test!(comparisons);
|
||||
gen_test_fail!(
|
||||
invalid_index_str,
|
||||
"semantic: Only integers >= 0 can be used as the index of an array, but you're using a string"
|
||||
@ -99,4 +100,5 @@ gen_test!(if_else);
|
||||
// if_else_no_expr,
|
||||
// "syntax: blocks inside an if/else expression must end in an expression"
|
||||
// );
|
||||
gen_test_fail!(comparisons_multiple, "syntax: Invalid number: true");
|
||||
gen_test!(add_lots);
|
||||
|
||||
Reference in New Issue
Block a user