Move tests from no_visuals into simulation tests (#4367)
Now you can properly inspect program memory for the no_visuals tests, instead of relying on a lot of KCL asserts.
This commit is contained in:
@ -1,107 +0,0 @@
|
||||
fn f = (i) => {
|
||||
return i * 2
|
||||
}
|
||||
|
||||
let x = f(0)
|
||||
+ f(1)
|
||||
+ f(2)
|
||||
+ f(3)
|
||||
+ f(4)
|
||||
+ f(5)
|
||||
+ f(6)
|
||||
+ f(7)
|
||||
+ f(8)
|
||||
+ f(9)
|
||||
+ f(10)
|
||||
+ f(11)
|
||||
+ f(12)
|
||||
+ f(13)
|
||||
+ f(14)
|
||||
+ f(15)
|
||||
+ f(16)
|
||||
+ f(17)
|
||||
+ f(18)
|
||||
+ f(19)
|
||||
+ f(20)
|
||||
+ f(21)
|
||||
+ f(22)
|
||||
+ f(23)
|
||||
+ f(24)
|
||||
+ f(25)
|
||||
+ f(26)
|
||||
+ f(27)
|
||||
+ f(28)
|
||||
+ f(29)
|
||||
+ f(30)
|
||||
+ f(31)
|
||||
+ f(32)
|
||||
+ f(33)
|
||||
+ f(34)
|
||||
+ f(35)
|
||||
+ f(36)
|
||||
+ f(37)
|
||||
+ f(38)
|
||||
+ f(39)
|
||||
+ f(40)
|
||||
+ f(41)
|
||||
+ f(42)
|
||||
+ f(43)
|
||||
+ f(44)
|
||||
+ f(45)
|
||||
+ f(46)
|
||||
+ f(47)
|
||||
+ f(48)
|
||||
+ f(49)
|
||||
+ f(50)
|
||||
+ f(51)
|
||||
+ f(52)
|
||||
+ f(53)
|
||||
+ f(54)
|
||||
+ f(55)
|
||||
+ f(56)
|
||||
+ f(57)
|
||||
+ f(58)
|
||||
+ f(59)
|
||||
+ f(60)
|
||||
+ f(61)
|
||||
+ f(62)
|
||||
+ f(63)
|
||||
+ f(64)
|
||||
+ f(65)
|
||||
+ f(66)
|
||||
+ f(67)
|
||||
+ f(68)
|
||||
+ f(69)
|
||||
+ f(70)
|
||||
+ f(71)
|
||||
+ f(72)
|
||||
+ f(73)
|
||||
+ f(74)
|
||||
+ f(75)
|
||||
+ f(76)
|
||||
+ f(77)
|
||||
+ f(78)
|
||||
+ f(79)
|
||||
+ f(80)
|
||||
+ f(81)
|
||||
+ f(82)
|
||||
+ f(83)
|
||||
+ f(84)
|
||||
+ f(85)
|
||||
+ f(86)
|
||||
+ f(87)
|
||||
+ f(88)
|
||||
+ f(89)
|
||||
+ f(90)
|
||||
+ f(91)
|
||||
+ f(92)
|
||||
+ f(93)
|
||||
+ f(94)
|
||||
+ f(95)
|
||||
+ f(96)
|
||||
+ f(97)
|
||||
+ f(98)
|
||||
+ f(99)
|
||||
+ f(100)
|
||||
|
||||
assertEqual(x, 10100, 0.1, "Big sum")
|
@ -1,12 +0,0 @@
|
||||
arr = [1, 2, 3]
|
||||
new_arr1 = push(arr, 4)
|
||||
new_arr2 = push(new_arr1, 5)
|
||||
assertEqual(new_arr1[0], 1, 0.00001, "element 0 should not have changed")
|
||||
assertEqual(new_arr1[1], 2, 0.00001, "element 1 should not have changed")
|
||||
assertEqual(new_arr1[2], 3, 0.00001, "element 2 should not have changed")
|
||||
assertEqual(new_arr1[3], 4, 0.00001, "4 was added to the end of the array")
|
||||
assertEqual(new_arr2[0], 1, 0.00001, "element 0 should not have changed")
|
||||
assertEqual(new_arr2[1], 2, 0.00001, "element 1 should not have changed")
|
||||
assertEqual(new_arr2[2], 3, 0.00001, "element 2 should not have changed")
|
||||
assertEqual(new_arr2[3], 4, 0.00001, "4 was added to the end of the array")
|
||||
assertEqual(new_arr2[4], 5, 0.00001, "5 was added to the end of the array")
|
@ -1,17 +0,0 @@
|
||||
r1 = [0..4]
|
||||
assertEqual(r1[4], 4, 0.00001, "last element is included")
|
||||
|
||||
four = 4
|
||||
zero = 0
|
||||
r2 = [zero..four]
|
||||
assertEqual(r2[4], 4, 0.00001, "last element is included")
|
||||
|
||||
five = int(four + 1)
|
||||
r3 = [zero..five]
|
||||
assertEqual(r3[4], 4, 0.00001, "second-to-last element is included")
|
||||
assertEqual(r3[5], 5, 0.00001, "last element is included")
|
||||
|
||||
r4 = [int(zero + 1) .. int(five - 1)]
|
||||
assertEqual(r4[0], 1, 0.00001, "first element is 1")
|
||||
assertEqual(r4[2], 3, 0.00001, "second-to-last element is 3")
|
||||
assertEqual(r4[3], 4, 0.00001, "last element is 4")
|
@ -1,2 +0,0 @@
|
||||
xs = [int(-5)..5]
|
||||
assertEqual(xs[0], -5, 0.001, "first element is -5")
|
@ -1,13 +0,0 @@
|
||||
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")
|
@ -1,28 +0,0 @@
|
||||
// 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")
|
@ -1,18 +0,0 @@
|
||||
// This tests indexing an array.
|
||||
|
||||
const array = [90, 91, 92]
|
||||
|
||||
// Test: literal index.
|
||||
|
||||
const result0 = array[1]
|
||||
|
||||
assertLessThanOrEq(result0, 91, "Literal property lookup")
|
||||
assertGreaterThanOrEq(result0, 91, "Literal property lookup")
|
||||
|
||||
// Test: computed index.
|
||||
|
||||
const i = int(1 + 0)
|
||||
const result1 = array[i]
|
||||
|
||||
assertLessThanOrEq(result1, 91, "Computed property lookup")
|
||||
assertGreaterThanOrEq(result1, 91, "Computed property lookup")
|
@ -1,40 +0,0 @@
|
||||
// This tests evaluating properties of objects.
|
||||
|
||||
const obj = {
|
||||
foo: 1,
|
||||
bar: 0,
|
||||
}
|
||||
|
||||
// Test: the property is a literal.
|
||||
|
||||
const one_a = obj["foo"]
|
||||
|
||||
assertLessThanOrEq(one_a, 1, "Literal property lookup")
|
||||
assertGreaterThanOrEq(one_a, 1, "Literal property lookup")
|
||||
|
||||
// Test: the property is a variable,
|
||||
// which must be evaluated before looking it up.
|
||||
|
||||
const p = "foo"
|
||||
const one_b = obj[p]
|
||||
|
||||
assertLessThanOrEq(one_b, 1, "Computed property lookup")
|
||||
assertGreaterThanOrEq(one_b, 1, "Computed property lookup")
|
||||
|
||||
// Test: multiple literal properties.
|
||||
|
||||
const obj2 = {
|
||||
inner: obj,
|
||||
}
|
||||
|
||||
const one_c = obj2.inner["foo"]
|
||||
|
||||
assertLessThanOrEq(one_c, 1, "Literal property lookup")
|
||||
assertGreaterThanOrEq(one_c, 1, "Literal property lookup")
|
||||
|
||||
// Test: multiple properties, mix of literal and computed.
|
||||
|
||||
const one_d = obj2.inner[p]
|
||||
|
||||
assertLessThanOrEq(one_d, 1, "Computed property lookup")
|
||||
assertGreaterThanOrEq(one_d, 1, "Computed property lookup")
|
@ -1,29 +0,0 @@
|
||||
fn test = () => {
|
||||
return startSketchOn('XY')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> line([0, 1], %)
|
||||
|> line([1, 0], %)
|
||||
|> line([0, -1], %)
|
||||
|> close(%)
|
||||
}
|
||||
|
||||
fn test2 = () => {
|
||||
return {
|
||||
thing1: {
|
||||
thing2: startSketchOn('XY')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> line([0, 1], %)
|
||||
|> line([1, 0], %)
|
||||
|> line([0, -1], %)
|
||||
|> close(%)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const x = test()
|
||||
x
|
||||
|> extrude(-10, %)
|
||||
|
||||
const x2 = test2()
|
||||
x2.thing1.thing2
|
||||
|> extrude(10, %)
|
@ -5,16 +5,6 @@ use kcl_lib::{
|
||||
parser,
|
||||
};
|
||||
|
||||
macro_rules! gen_test {
|
||||
($file:ident) => {
|
||||
#[tokio::test]
|
||||
async fn $file() {
|
||||
let code = include_str!(concat!("inputs/no_visuals/", stringify!($file), ".kcl"));
|
||||
run(&code).await;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! gen_test_fail {
|
||||
($file:ident, $expected:literal) => {
|
||||
#[tokio::test]
|
||||
@ -37,27 +27,6 @@ macro_rules! gen_test_parse_fail {
|
||||
};
|
||||
}
|
||||
|
||||
async fn run(code: &str) {
|
||||
let (ctx, program, id_generator) = setup(code).await;
|
||||
|
||||
let res = ctx
|
||||
.run(
|
||||
&program,
|
||||
None,
|
||||
id_generator,
|
||||
Some("tests/executor/inputs/no_visuals/".to_owned()),
|
||||
)
|
||||
.await;
|
||||
match res {
|
||||
Ok(state) => {
|
||||
println!("{:#?}", state.memory);
|
||||
}
|
||||
Err(e) => {
|
||||
panic!("{e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn setup(program: &str) -> (ExecutorContext, Node<Program>, IdGenerator) {
|
||||
let tokens = kcl_lib::token::lexer(program).unwrap();
|
||||
let parser = kcl_lib::parser::Parser::new(tokens);
|
||||
@ -97,11 +66,6 @@ async fn run_parse_fail(code: &str) -> KclError {
|
||||
e
|
||||
}
|
||||
|
||||
gen_test!(property_of_object);
|
||||
gen_test!(index_of_array);
|
||||
gen_test!(comparisons);
|
||||
gen_test!(array_range_expr);
|
||||
gen_test!(array_range_negative_expr);
|
||||
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"
|
||||
@ -138,14 +102,11 @@ gen_test_fail!(
|
||||
pipe_substitution_inside_function_called_from_pipeline,
|
||||
"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_fail!(comparisons_multiple, "syntax: Invalid number: true");
|
||||
gen_test!(import_simple);
|
||||
gen_test_fail!(
|
||||
import_cycle1,
|
||||
"import cycle: circular import of modules is not allowed: tests/executor/inputs/no_visuals/import_cycle2.kcl -> tests/executor/inputs/no_visuals/import_cycle3.kcl -> tests/executor/inputs/no_visuals/import_cycle1.kcl -> tests/executor/inputs/no_visuals/import_cycle2.kcl"
|
||||
@ -171,8 +132,6 @@ gen_test_parse_fail!(
|
||||
// import_in_function,
|
||||
// "syntax: Can import only import at the top level"
|
||||
// );
|
||||
gen_test!(add_lots);
|
||||
gen_test!(array_elem_push);
|
||||
gen_test_fail!(
|
||||
array_elem_push_fail,
|
||||
"undefined value: The array doesn't have any item at index 3"
|
||||
|
Reference in New Issue
Block a user