diff --git a/src/wasm-lib/tests/executor/inputs/angled_line.kcl b/src/wasm-lib/tests/executor/inputs/angled_line.kcl new file mode 100644 index 000000000..94fb2b859 --- /dev/null +++ b/src/wasm-lib/tests/executor/inputs/angled_line.kcl @@ -0,0 +1,9 @@ +const part001 = startSketchOn('XY') + |> startProfileAt([4.83, 12.56], %) + |> line([15.1, 2.48], %) + |> line([3.15, -9.85], %, $seg01) + |> line([-15.17, -4.1], %) + |> angledLine([segAng(seg01), 12.35], %) + |> line([-13.02, 10.03], %) + |> close(%) + |> extrude(4, %) diff --git a/src/wasm-lib/tests/executor/inputs/close_arc.kcl b/src/wasm-lib/tests/executor/inputs/close_arc.kcl new file mode 100644 index 000000000..ecd867c07 --- /dev/null +++ b/src/wasm-lib/tests/executor/inputs/close_arc.kcl @@ -0,0 +1,9 @@ +const center = [0,0] +const radius = 40 +const height = 3 + +const body = startSketchOn('XY') + |> startProfileAt([center[0]+radius, center[1]], %) + |> arc({angle_end: 360, angle_start: 0, radius: radius}, %) + |> close(%) + |> extrude(height, %) diff --git a/src/wasm-lib/tests/executor/inputs/dimensions_match.kcl b/src/wasm-lib/tests/executor/inputs/dimensions_match.kcl new file mode 100644 index 000000000..4c1f3a9a6 --- /dev/null +++ b/src/wasm-lib/tests/executor/inputs/dimensions_match.kcl @@ -0,0 +1,7 @@ +const part001 = startSketchOn('XY') + |> startProfileAt([-10, -10], %) + |> line([20, 0], %) + |> line([0, 20], %) + |> line([-20, 0], %) + |> close(%) + |> extrude(10, %) diff --git a/src/wasm-lib/tests/executor/inputs/helix_ccw.kcl b/src/wasm-lib/tests/executor/inputs/helix_ccw.kcl new file mode 100644 index 000000000..6975ab7b9 --- /dev/null +++ b/src/wasm-lib/tests/executor/inputs/helix_ccw.kcl @@ -0,0 +1,4 @@ +const part001 = startSketchOn('XY') + |> circle([5, 5], 10, %) + |> extrude(10, %) + |> helix({revolutions: 16, angle_start: 0, ccw: true}, %) diff --git a/src/wasm-lib/tests/executor/inputs/helix_defaults.kcl b/src/wasm-lib/tests/executor/inputs/helix_defaults.kcl new file mode 100644 index 000000000..e85eab8de --- /dev/null +++ b/src/wasm-lib/tests/executor/inputs/helix_defaults.kcl @@ -0,0 +1,4 @@ +const part001 = startSketchOn('XY') + |> circle([5, 5], 10, %) + |> extrude(10, %) + |> helix({revolutions: 16, angle_start: 0}, %) diff --git a/src/wasm-lib/tests/executor/inputs/helix_defaults_negative_extrude.kcl b/src/wasm-lib/tests/executor/inputs/helix_defaults_negative_extrude.kcl new file mode 100644 index 000000000..9a2f3efc1 --- /dev/null +++ b/src/wasm-lib/tests/executor/inputs/helix_defaults_negative_extrude.kcl @@ -0,0 +1,4 @@ +const part001 = startSketchOn('XY') + |> circle([5, 5], 10, %) + |> extrude(-10, %) + |> helix({revolutions: 16, angle_start: 0}, %) diff --git a/src/wasm-lib/tests/executor/inputs/helix_with_length.kcl b/src/wasm-lib/tests/executor/inputs/helix_with_length.kcl new file mode 100644 index 000000000..1847d4ad0 --- /dev/null +++ b/src/wasm-lib/tests/executor/inputs/helix_with_length.kcl @@ -0,0 +1,4 @@ +const part001 = startSketchOn('XY') + |> circle([5, 5], 10, %) + |> extrude(10, %) + |> helix({revolutions: 16, angle_start: 0, length: 3}, %) diff --git a/src/wasm-lib/tests/executor/inputs/member_expression_sketch_group.kcl b/src/wasm-lib/tests/executor/inputs/member_expression_sketch_group.kcl new file mode 100644 index 000000000..f02e76a00 --- /dev/null +++ b/src/wasm-lib/tests/executor/inputs/member_expression_sketch_group.kcl @@ -0,0 +1,17 @@ +fn cube = (pos, scale) => { + const sg = startSketchOn('XY') + |> startProfileAt(pos, %) + |> line([0, scale], %) + |> line([scale, 0], %) + |> line([0, -scale], %) + |> close(%) + + return sg +} + +const b1 = cube([0,0], 10) +const b2 = cube([3,3], 4) + |> extrude(10, %) + +const pt1 = b1.value[0] +const pt2 = b2.value[0] diff --git a/src/wasm-lib/tests/executor/inputs/negative_args.kcl b/src/wasm-lib/tests/executor/inputs/negative_args.kcl new file mode 100644 index 000000000..1983ef07e --- /dev/null +++ b/src/wasm-lib/tests/executor/inputs/negative_args.kcl @@ -0,0 +1,19 @@ +const width = 5 +const height = 10 +const length = 12 + +fn box = (sk1, sk2, scale) => { + const boxSketch = startSketchOn('XY') + |> startProfileAt([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) diff --git a/src/wasm-lib/tests/executor/inputs/parametric.kcl b/src/wasm-lib/tests/executor/inputs/parametric.kcl new file mode 100644 index 000000000..688095315 --- /dev/null +++ b/src/wasm-lib/tests/executor/inputs/parametric.kcl @@ -0,0 +1,18 @@ +const sigmaAllow = 35000 // psi +const width = 9 // inch +const p = 150 // Force on shelf - lbs +const distance = 6 // inches +const FOS = 2 + +const leg1 = 5 // inches +const leg2 = 8 // inches +const thickness = sqrt(distance * p * FOS * 6 / sigmaAllow / width) // inches +const bracket = startSketchOn('XY') + |> startProfileAt([0, 0], %) + |> line([0, leg1], %) + |> line([leg2, 0], %) + |> line([0, -thickness], %) + |> line([-leg2 + thickness, 0], %) + |> line([0, -leg1 + thickness], %) + |> close(%) + |> extrude(width, %) diff --git a/src/wasm-lib/tests/executor/inputs/parametric_with_tan_arc.kcl b/src/wasm-lib/tests/executor/inputs/parametric_with_tan_arc.kcl new file mode 100644 index 000000000..f6c085837 --- /dev/null +++ b/src/wasm-lib/tests/executor/inputs/parametric_with_tan_arc.kcl @@ -0,0 +1,26 @@ +const sigmaAllow = 15000 // psi +const width = 11 // inch +const p = 150 // Force on shelf - lbs +const distance = 12 // inches +const FOS = 2 +const thickness = sqrt(distance * p * FOS * 6 / ( sigmaAllow * width )) +const filletR = thickness * 2 +const shelfMountL = 9 +const wallMountL = 8 + +const bracket = startSketchAt([0, 0]) + |> line([0, wallMountL], %) + |> tangentialArc({ + radius: filletR, + offset: 90 + }, %) + |> line([-shelfMountL, 0], %) + |> line([0, -thickness], %) + |> line([shelfMountL, 0], %) + |> tangentialArc({ + radius: filletR - thickness, + offset: -90 + }, %) + |> line([0, -wallMountL], %) + |> close(%) + |> extrude(width, %) diff --git a/src/wasm-lib/tests/executor/main.rs b/src/wasm-lib/tests/executor/main.rs index 7d2abfc82..7eb27622b 100644 --- a/src/wasm-lib/tests/executor/main.rs +++ b/src/wasm-lib/tests/executor/main.rs @@ -150,77 +150,21 @@ async fn kcl_test_execute_with_function_sketch_with_position() { #[tokio::test(flavor = "multi_thread")] async fn kcl_test_execute_with_angled_line() { - let code = r#"const part001 = startSketchOn('XY') - |> startProfileAt([4.83, 12.56], %) - |> line([15.1, 2.48], %) - |> line([3.15, -9.85], %, $seg01) - |> line([-15.17, -4.1], %) - |> angledLine([segAng(seg01), 12.35], %) - |> line([-13.02, 10.03], %) - |> close(%) - |> extrude(4, %) -"#; - + let code = kcl_input!("angled_line"); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); assert_out("angled_line", &result); } #[tokio::test(flavor = "multi_thread")] async fn kcl_test_execute_parametric_example() { - let code = r#"const sigmaAllow = 35000 // psi -const width = 9 // inch -const p = 150 // Force on shelf - lbs -const distance = 6 // inches -const FOS = 2 - -const leg1 = 5 // inches -const leg2 = 8 // inches -const thickness = sqrt(distance * p * FOS * 6 / sigmaAllow / width) // inches -const bracket = startSketchOn('XY') - |> startProfileAt([0, 0], %) - |> line([0, leg1], %) - |> line([leg2, 0], %) - |> line([0, -thickness], %) - |> line([-leg2 + thickness, 0], %) - |> line([0, -leg1 + thickness], %) - |> close(%) - |> extrude(width, %) -"#; - + let code = kcl_input!("parametric"); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); assert_out("parametric", &result); } #[tokio::test(flavor = "multi_thread")] async fn kcl_test_execute_parametric_with_tan_arc_example() { - let code = r#"const sigmaAllow = 15000 // psi -const width = 11 // inch -const p = 150 // Force on shelf - lbs -const distance = 12 // inches -const FOS = 2 -const thickness = sqrt(distance * p * FOS * 6 / ( sigmaAllow * width )) -const filletR = thickness * 2 -const shelfMountL = 9 -const wallMountL = 8 - -const bracket = startSketchAt([0, 0]) - |> line([0, wallMountL], %) - |> tangentialArc({ - radius: filletR, - offset: 90 - }, %) - |> line([-shelfMountL, 0], %) - |> line([0, -thickness], %) - |> line([shelfMountL, 0], %) - |> tangentialArc({ - radius: filletR - thickness, - offset: -90 - }, %) - |> line([0, -wallMountL], %) - |> close(%) - |> extrude(width, %) -"#; - + let code = kcl_input!("parametric_with_tan_arc"); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); assert_out("parametric_with_tan_arc", &result); } @@ -280,24 +224,7 @@ async fn kcl_test_execute_kittycad_svg() { #[tokio::test(flavor = "multi_thread")] async fn kcl_test_member_expression_sketch_group() { - let code = r#"fn cube = (pos, scale) => { - const sg = startSketchOn('XY') - |> startProfileAt(pos, %) - |> line([0, scale], %) - |> line([scale, 0], %) - |> line([0, -scale], %) - |> close(%) - - return sg -} - -const b1 = cube([0,0], 10) -const b2 = cube([3,3], 4) - |> extrude(10, %) - -const pt1 = b1.value[0] -const pt2 = b2.value[0] -"#; + let code = kcl_input!("member_expression_sketch_group"); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); assert_out("member_expression_sketch_group", &result); @@ -305,11 +232,7 @@ const pt2 = b2.value[0] #[tokio::test(flavor = "multi_thread")] async fn kcl_test_helix_defaults() { - let code = r#"const part001 = startSketchOn('XY') - |> circle([5, 5], 10, %) - |> extrude(10, %) - |> helix({revolutions: 16, angle_start: 0}, %) -"#; + let code = kcl_input!("helix_defaults"); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); assert_out("helix_defaults", &result); @@ -317,11 +240,7 @@ async fn kcl_test_helix_defaults() { #[tokio::test(flavor = "multi_thread")] async fn kcl_test_helix_defaults_negative_extrude() { - let code = r#"const part001 = startSketchOn('XY') - |> circle([5, 5], 10, %) - |> extrude(-10, %) - |> helix({revolutions: 16, angle_start: 0}, %) -"#; + let code = kcl_input!("helix_defaults_negative_extrude"); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); assert_out("helix_defaults_negative_extrude", &result); @@ -329,11 +248,7 @@ async fn kcl_test_helix_defaults_negative_extrude() { #[tokio::test(flavor = "multi_thread")] async fn kcl_test_helix_ccw() { - let code = r#"const part001 = startSketchOn('XY') - |> circle([5, 5], 10, %) - |> extrude(10, %) - |> helix({revolutions: 16, angle_start: 0, ccw: true}, %) -"#; + let code = kcl_input!("helix_ccw"); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); assert_out("helix_ccw", &result); @@ -341,11 +256,7 @@ async fn kcl_test_helix_ccw() { #[tokio::test(flavor = "multi_thread")] async fn kcl_test_helix_with_length() { - let code = r#"const part001 = startSketchOn('XY') - |> circle([5, 5], 10, %) - |> extrude(10, %) - |> helix({revolutions: 16, angle_start: 0, length: 3}, %) -"#; + let code = kcl_input!("helix_with_length"); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); assert_out("helix_with_length", &result); @@ -353,14 +264,7 @@ async fn kcl_test_helix_with_length() { #[tokio::test(flavor = "multi_thread")] async fn kcl_test_dimensions_match() { - let code = r#"const part001 = startSketchOn('XY') - |> startProfileAt([-10, -10], %) - |> line([20, 0], %) - |> line([0, 20], %) - |> line([-20, 0], %) - |> close(%) - |> extrude(10, %) -"#; + let code = kcl_input!("dimensions_match"); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); assert_out("dimensions_match", &result); @@ -368,16 +272,7 @@ async fn kcl_test_dimensions_match() { #[tokio::test(flavor = "multi_thread")] async fn kcl_test_close_arc() { - let code = r#"const center = [0,0] -const radius = 40 -const height = 3 - -const body = startSketchOn('XY') - |> startProfileAt([center[0]+radius, center[1]], %) - |> arc({angle_end: 360, angle_start: 0, radius: radius}, %) - |> close(%) - |> extrude(height, %) -"#; + let code = kcl_input!("close_arc"); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); assert_out("close_arc", &result); @@ -385,25 +280,7 @@ const body = startSketchOn('XY') #[tokio::test(flavor = "multi_thread")] async fn kcl_test_negative_args() { - let code = r#"const width = 5 -const height = 10 -const length = 12 - -fn box = (sk1, sk2, scale) => { - const boxSketch = startSketchOn('XY') - |> startProfileAt([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 code = kcl_input!("negative_args"); let result = execute_and_snapshot(code, UnitLength::Mm).await.unwrap(); assert_out("negative_args", &result);