diff --git a/rust/kcl-lib/src/simulation_tests.rs b/rust/kcl-lib/src/simulation_tests.rs index 30358e57f..10514ffbd 100644 --- a/rust/kcl-lib/src/simulation_tests.rs +++ b/rust/kcl-lib/src/simulation_tests.rs @@ -1258,6 +1258,48 @@ mod linear_pattern3d_a_pattern { super::execute(TEST_NAME, true).await } } +mod pattern_circular_in_module { + const TEST_NAME: &str = "pattern_circular_in_module"; + + /// Test parsing KCL. + #[test] + fn parse() { + super::parse(TEST_NAME) + } + + /// Test that parsing and unparsing KCL produces the original KCL input. + #[tokio::test(flavor = "multi_thread")] + async fn unparse() { + super::unparse(TEST_NAME).await + } + + /// Test that KCL is executed correctly. + #[tokio::test(flavor = "multi_thread")] + async fn kcl_test_execute() { + super::execute(TEST_NAME, true).await + } +} +mod pattern_linear_in_module { + const TEST_NAME: &str = "pattern_linear_in_module"; + + /// Test parsing KCL. + #[test] + fn parse() { + super::parse(TEST_NAME) + } + + /// Test that parsing and unparsing KCL produces the original KCL input. + #[tokio::test(flavor = "multi_thread")] + async fn unparse() { + super::unparse(TEST_NAME).await + } + + /// Test that KCL is executed correctly. + #[tokio::test(flavor = "multi_thread")] + async fn kcl_test_execute() { + super::execute(TEST_NAME, true).await + } +} mod tangential_arc { const TEST_NAME: &str = "tangential_arc"; diff --git a/rust/kcl-lib/src/std/patterns.rs b/rust/kcl-lib/src/std/patterns.rs index 184bbc7a8..545637307 100644 --- a/rust/kcl-lib/src/std/patterns.rs +++ b/rust/kcl-lib/src/std/patterns.rs @@ -381,6 +381,7 @@ async fn send_pattern_transform( args: &Args, ) -> Result, KclError> { let id = exec_state.next_uuid(); + let extra_instances = transforms.len(); let resp = args .send_modeling_cmd( @@ -393,10 +394,19 @@ async fn send_pattern_transform( ) .await?; - let OkWebSocketResponseData::Modeling { + let mut mock_ids = Vec::new(); + let entity_ids = if let OkWebSocketResponseData::Modeling { modeling_response: OkModelingCmdResponse::EntityLinearPatternTransform(pattern_info), } = &resp - else { + { + &pattern_info.entity_ids + } else if args.ctx.no_engine_commands().await { + mock_ids.reserve(extra_instances); + for _ in 0..extra_instances { + mock_ids.push(exec_state.next_uuid()); + } + &mock_ids + } else { return Err(KclError::Engine(KclErrorDetails { message: format!("EntityLinearPattern response was not as expected: {:?}", resp), source_ranges: vec![args.source_range], @@ -404,7 +414,7 @@ async fn send_pattern_transform( }; let mut geometries = vec![solid.clone()]; - for id in pattern_info.entity_ids.iter().copied() { + for id in entity_ids.iter().copied() { let mut new_solid = solid.clone(); new_solid.set_id(id); geometries.push(new_solid); @@ -1280,10 +1290,21 @@ async fn pattern_circular( ) .await?; - let OkWebSocketResponseData::Modeling { + // The common case is borrowing from the response. Instead of cloning, + // create a Vec to borrow from in mock mode. + let mut mock_ids = Vec::new(); + let entity_ids = if let OkWebSocketResponseData::Modeling { modeling_response: OkModelingCmdResponse::EntityCircularPattern(pattern_info), } = &resp - else { + { + &pattern_info.entity_ids + } else if args.ctx.no_engine_commands().await { + mock_ids.reserve(num_repetitions as usize); + for _ in 0..num_repetitions { + mock_ids.push(exec_state.next_uuid()); + } + &mock_ids + } else { return Err(KclError::Engine(KclErrorDetails { message: format!("EntityCircularPattern response was not as expected: {:?}", resp), source_ranges: vec![args.source_range], @@ -1293,18 +1314,18 @@ async fn pattern_circular( let geometries = match geometry { Geometry::Sketch(sketch) => { let mut geometries = vec![sketch.clone()]; - for id in pattern_info.entity_ids.iter() { + for id in entity_ids.iter().copied() { let mut new_sketch = sketch.clone(); - new_sketch.id = *id; + new_sketch.id = id; geometries.push(new_sketch); } Geometries::Sketches(geometries) } Geometry::Solid(solid) => { let mut geometries = vec![solid.clone()]; - for id in pattern_info.entity_ids.iter() { + for id in entity_ids.iter().copied() { let mut new_solid = solid.clone(); - new_solid.id = *id; + new_solid.id = id; geometries.push(new_solid); } Geometries::Solids(geometries) diff --git a/rust/kcl-lib/tests/pattern_circular_in_module/artifact_commands.snap b/rust/kcl-lib/tests/pattern_circular_in_module/artifact_commands.snap new file mode 100644 index 000000000..94a381555 --- /dev/null +++ b/rust/kcl-lib/tests/pattern_circular_in_module/artifact_commands.snap @@ -0,0 +1,700 @@ +--- +source: kcl-lib/src/simulation_tests.rs +description: Artifact commands pattern_circular_in_module.kcl +--- +[ + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "edge_lines_visible", + "hidden": false + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "object_visible", + "object_id": "[uuid]", + "hidden": true + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "object_visible", + "object_id": "[uuid]", + "hidden": true + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "make_plane", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "x_axis": { + "x": 1.0, + "y": 0.0, + "z": 0.0 + }, + "y_axis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "size": 60.0, + "clobber": false, + "hide": true + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "enable_sketch_mode", + "entity_id": "[uuid]", + "ortho": false, + "animated": false, + "adjust_camera": false, + "planar_normal": { + "x": 0.0, + "y": -1.0, + "z": 0.0 + } + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "start_path" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "move_path_pen", + "path": "[uuid]", + "to": { + "x": 0.5, + "y": 25.0, + "z": 0.0 + } + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "sketch_mode_disable" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "extend_path", + "path": "[uuid]", + "segment": { + "type": "line", + "end": { + "x": 0.0, + "y": 5.0, + "z": 0.0 + }, + "relative": true + } + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "extend_path", + "path": "[uuid]", + "segment": { + "type": "line", + "end": { + "x": -1.0, + "y": 0.0, + "z": 0.0 + }, + "relative": true + } + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "extend_path", + "path": "[uuid]", + "segment": { + "type": "line", + "end": { + "x": 0.0, + "y": -5.0, + "z": 0.0 + }, + "relative": true + } + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "close_path", + "path_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "entity_circular_pattern", + "entity_id": "[uuid]", + "axis": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "center": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "num_repetitions": 3, + "arc_degrees": 360.0, + "rotate_duplicates": true + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "enable_sketch_mode", + "entity_id": "[uuid]", + "ortho": false, + "animated": false, + "adjust_camera": false, + "planar_normal": { + "x": 0.0, + "y": -1.0, + "z": 0.0 + } + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "extrude", + "target": "[uuid]", + "distance": 1.0, + "faces": null + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "sketch_mode_disable" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "object_bring_to_front", + "object_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_extrusion_face_info", + "object_id": "[uuid]", + "edge_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "enable_sketch_mode", + "entity_id": "[uuid]", + "ortho": false, + "animated": false, + "adjust_camera": false, + "planar_normal": { + "x": 0.0, + "y": -1.0, + "z": 0.0 + } + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "extrude", + "target": "[uuid]", + "distance": 1.0, + "faces": null + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "sketch_mode_disable" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "object_bring_to_front", + "object_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_extrusion_face_info", + "object_id": "[uuid]", + "edge_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "enable_sketch_mode", + "entity_id": "[uuid]", + "ortho": false, + "animated": false, + "adjust_camera": false, + "planar_normal": { + "x": 0.0, + "y": -1.0, + "z": 0.0 + } + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "extrude", + "target": "[uuid]", + "distance": 1.0, + "faces": null + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "sketch_mode_disable" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "object_bring_to_front", + "object_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_extrusion_face_info", + "object_id": "[uuid]", + "edge_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "enable_sketch_mode", + "entity_id": "[uuid]", + "ortho": false, + "animated": false, + "adjust_camera": false, + "planar_normal": { + "x": 0.0, + "y": -1.0, + "z": 0.0 + } + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "extrude", + "target": "[uuid]", + "distance": 1.0, + "faces": null + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "sketch_mode_disable" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "object_bring_to_front", + "object_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_extrusion_face_info", + "object_id": "[uuid]", + "edge_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + } +] diff --git a/rust/kcl-lib/tests/pattern_circular_in_module/artifact_graph_flowchart.snap b/rust/kcl-lib/tests/pattern_circular_in_module/artifact_graph_flowchart.snap new file mode 100644 index 000000000..29d246f42 --- /dev/null +++ b/rust/kcl-lib/tests/pattern_circular_in_module/artifact_graph_flowchart.snap @@ -0,0 +1,6 @@ +--- +source: kcl-lib/src/simulation_tests.rs +description: Artifact graph flowchart pattern_circular_in_module.kcl +extension: md +snapshot_kind: binary +--- diff --git a/rust/kcl-lib/tests/pattern_circular_in_module/artifact_graph_flowchart.snap.md b/rust/kcl-lib/tests/pattern_circular_in_module/artifact_graph_flowchart.snap.md new file mode 100644 index 000000000..ded3c1d62 --- /dev/null +++ b/rust/kcl-lib/tests/pattern_circular_in_module/artifact_graph_flowchart.snap.md @@ -0,0 +1,63 @@ +```mermaid +flowchart LR + subgraph path2 [Path] + 2["Path
[63, 90, 5]"] + 3["Segment
[98, 116, 5]"] + 4["Segment
[124, 143, 5]"] + 5["Segment
[151, 170, 5]"] + 6["Segment
[178, 185, 5]"] + 7[Solid2d] + end + 1["Plane
[38, 55, 5]"] + 8["Sweep Extrusion
[342, 376, 5]"] + 9[Wall] + 10[Wall] + 11[Wall] + 12[Wall] + 13["Cap Start"] + 14["Cap End"] + 15["SweepEdge Opposite"] + 16["SweepEdge Adjacent"] + 17["SweepEdge Opposite"] + 18["SweepEdge Adjacent"] + 19["SweepEdge Opposite"] + 20["SweepEdge Adjacent"] + 21["SweepEdge Opposite"] + 22["SweepEdge Adjacent"] + 23["Sweep Extrusion
[342, 376, 5]"] + 24["Sweep Extrusion
[342, 376, 5]"] + 25["Sweep Extrusion
[342, 376, 5]"] + 1 --- 2 + 2 --- 3 + 2 --- 4 + 2 --- 5 + 2 --- 6 + 2 ---- 8 + 2 --- 7 + 3 --- 9 + 3 --- 15 + 3 --- 16 + 4 --- 10 + 4 --- 17 + 4 --- 18 + 5 --- 11 + 5 --- 19 + 5 --- 20 + 6 --- 12 + 6 --- 21 + 6 --- 22 + 8 --- 9 + 8 --- 10 + 8 --- 11 + 8 --- 12 + 8 --- 13 + 8 --- 14 + 8 --- 15 + 8 --- 16 + 8 --- 17 + 8 --- 18 + 8 --- 19 + 8 --- 20 + 8 --- 21 + 8 --- 22 +``` diff --git a/rust/kcl-lib/tests/pattern_circular_in_module/ast.snap b/rust/kcl-lib/tests/pattern_circular_in_module/ast.snap new file mode 100644 index 000000000..c51772b1a --- /dev/null +++ b/rust/kcl-lib/tests/pattern_circular_in_module/ast.snap @@ -0,0 +1,89 @@ +--- +source: kcl-lib/src/simulation_tests.rs +description: Result of parsing pattern_circular_in_module.kcl +--- +{ + "Ok": { + "body": [ + { + "commentStart": 0, + "end": 0, + "path": { + "type": "Kcl", + "filename": "thing.kcl" + }, + "selector": { + "type": "List", + "items": [ + { + "alias": null, + "commentStart": 7, + "end": 0, + "name": { + "commentStart": 7, + "end": 0, + "name": "thing", + "start": 0, + "type": "Identifier" + }, + "start": 0, + "type": "ImportItem" + } + ] + }, + "start": 0, + "type": "ImportStatement", + "type": "ImportStatement" + }, + { + "commentStart": 29, + "end": 0, + "expression": { + "arguments": [], + "callee": { + "abs_path": false, + "commentStart": 31, + "end": 0, + "name": { + "commentStart": 31, + "end": 0, + "name": "thing", + "start": 0, + "type": "Identifier" + }, + "path": [], + "start": 0, + "type": "Name" + }, + "commentStart": 31, + "end": 0, + "start": 0, + "type": "CallExpression", + "type": "CallExpression" + }, + "start": 0, + "type": "ExpressionStatement", + "type": "ExpressionStatement" + } + ], + "commentStart": 0, + "end": 0, + "nonCodeMeta": { + "nonCodeNodes": { + "0": [ + { + "commentStart": 29, + "end": 0, + "start": 0, + "type": "NonCodeNode", + "value": { + "type": "newLine" + } + } + ] + }, + "startNodes": [] + }, + "start": 0 + } +} diff --git a/rust/kcl-lib/tests/pattern_circular_in_module/input.kcl b/rust/kcl-lib/tests/pattern_circular_in_module/input.kcl new file mode 100644 index 000000000..7060ff276 --- /dev/null +++ b/rust/kcl-lib/tests/pattern_circular_in_module/input.kcl @@ -0,0 +1,3 @@ +import thing from "thing.kcl" + +thing() diff --git a/rust/kcl-lib/tests/pattern_circular_in_module/ops.snap b/rust/kcl-lib/tests/pattern_circular_in_module/ops.snap new file mode 100644 index 000000000..38aa7bb3b --- /dev/null +++ b/rust/kcl-lib/tests/pattern_circular_in_module/ops.snap @@ -0,0 +1,176 @@ +--- +source: kcl-lib/src/simulation_tests.rs +description: Operations executed pattern_circular_in_module.kcl +--- +[ + { + "type": "UserDefinedFunctionCall", + "name": "thing", + "functionSourceRange": [ + 15, + 378, + 5 + ], + "unlabeledArg": null, + "labeledArgs": {}, + "sourceRange": [] + }, + { + "labeledArgs": { + "data": { + "value": { + "type": "Plane", + "artifact_id": "[uuid]" + }, + "sourceRange": [] + } + }, + "name": "startSketchOn", + "sourceRange": [], + "type": "StdLibCall", + "unlabeledArg": null + }, + { + "labeledArgs": { + "length": { + "value": { + "type": "Number", + "value": 1.0, + "ty": { + "type": "Default", + "len": { + "type": "Mm" + }, + "angle": { + "type": "Degrees" + } + } + }, + "sourceRange": [] + } + }, + "name": "extrude", + "sourceRange": [], + "type": "StdLibCall", + "unlabeledArg": { + "value": { + "type": "Array", + "value": [ + { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + }, + { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + }, + { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + }, + { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + } + ] + }, + "sourceRange": [] + } + }, + { + "type": "UserDefinedFunctionReturn" + }, + { + "type": "UserDefinedFunctionCall", + "name": "thing", + "functionSourceRange": [ + 15, + 378, + 5 + ], + "unlabeledArg": null, + "labeledArgs": {}, + "sourceRange": [] + }, + { + "labeledArgs": { + "data": { + "value": { + "type": "Plane", + "artifact_id": "[uuid]" + }, + "sourceRange": [] + } + }, + "name": "startSketchOn", + "sourceRange": [], + "type": "StdLibCall", + "unlabeledArg": null + }, + { + "labeledArgs": { + "length": { + "value": { + "type": "Number", + "value": 1.0, + "ty": { + "type": "Default", + "len": { + "type": "Mm" + }, + "angle": { + "type": "Degrees" + } + } + }, + "sourceRange": [] + } + }, + "name": "extrude", + "sourceRange": [], + "type": "StdLibCall", + "unlabeledArg": { + "value": { + "type": "Array", + "value": [ + { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + }, + { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + }, + { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + }, + { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + } + ] + }, + "sourceRange": [] + } + }, + { + "type": "UserDefinedFunctionReturn" + } +] diff --git a/rust/kcl-lib/tests/pattern_circular_in_module/program_memory.snap b/rust/kcl-lib/tests/pattern_circular_in_module/program_memory.snap new file mode 100644 index 000000000..e4265fe09 --- /dev/null +++ b/rust/kcl-lib/tests/pattern_circular_in_module/program_memory.snap @@ -0,0 +1,9 @@ +--- +source: kcl-lib/src/simulation_tests.rs +description: Variables in memory after executing pattern_circular_in_module.kcl +--- +{ + "thing": { + "type": "Function" + } +} diff --git a/rust/kcl-lib/tests/pattern_circular_in_module/rendered_model.png b/rust/kcl-lib/tests/pattern_circular_in_module/rendered_model.png new file mode 100644 index 000000000..307949e1e Binary files /dev/null and b/rust/kcl-lib/tests/pattern_circular_in_module/rendered_model.png differ diff --git a/rust/kcl-lib/tests/pattern_circular_in_module/thing.kcl b/rust/kcl-lib/tests/pattern_circular_in_module/thing.kcl new file mode 100644 index 000000000..38710c21c --- /dev/null +++ b/rust/kcl-lib/tests/pattern_circular_in_module/thing.kcl @@ -0,0 +1,19 @@ +export fn thing() { + exampleSketch = startSketchOn(XZ) + |> startProfileAt([.5, 25], %) + |> line(end = [0, 5]) + |> line(end = [-1, 0]) + |> line(end = [0, -5]) + |> close() + |> patternCircular2d( + center = [0, 0], + instances = 4, + arcDegrees = 360, + rotateDuplicates = true, + ) + + return extrude(exampleSketch, length = 1) +} + +// This makes it run in isolated mode when the function is imported. +thing() diff --git a/rust/kcl-lib/tests/pattern_circular_in_module/unparsed.snap b/rust/kcl-lib/tests/pattern_circular_in_module/unparsed.snap new file mode 100644 index 000000000..4e86f609f --- /dev/null +++ b/rust/kcl-lib/tests/pattern_circular_in_module/unparsed.snap @@ -0,0 +1,7 @@ +--- +source: kcl-lib/src/simulation_tests.rs +description: Result of unparsing pattern_circular_in_module.kcl +--- +import thing from "thing.kcl" + +thing() diff --git a/rust/kcl-lib/tests/pattern_circular_in_module/unparsed@thing.kcl.snap b/rust/kcl-lib/tests/pattern_circular_in_module/unparsed@thing.kcl.snap new file mode 100644 index 000000000..58b9ca134 --- /dev/null +++ b/rust/kcl-lib/tests/pattern_circular_in_module/unparsed@thing.kcl.snap @@ -0,0 +1,23 @@ +--- +source: kcl-lib/src/simulation_tests.rs +description: Result of unparsing tests/pattern_circular_in_module/thing.kcl +--- +export fn thing() { + exampleSketch = startSketchOn(XZ) + |> startProfileAt([.5, 25], %) + |> line(end = [0, 5]) + |> line(end = [-1, 0]) + |> line(end = [0, -5]) + |> close() + |> patternCircular2d( + center = [0, 0], + instances = 4, + arcDegrees = 360, + rotateDuplicates = true, + ) + + return extrude(exampleSketch, length = 1) +} + +// This makes it run in isolated mode when the function is imported. +thing() diff --git a/rust/kcl-lib/tests/pattern_linear_in_module/artifact_commands.snap b/rust/kcl-lib/tests/pattern_linear_in_module/artifact_commands.snap new file mode 100644 index 000000000..d3c89da73 --- /dev/null +++ b/rust/kcl-lib/tests/pattern_linear_in_module/artifact_commands.snap @@ -0,0 +1,808 @@ +--- +source: kcl-lib/src/simulation_tests.rs +description: Artifact commands pattern_linear_in_module.kcl +--- +[ + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "edge_lines_visible", + "hidden": false + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "object_visible", + "object_id": "[uuid]", + "hidden": true + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "object_visible", + "object_id": "[uuid]", + "hidden": true + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "make_plane", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "x_axis": { + "x": 1.0, + "y": 0.0, + "z": 0.0 + }, + "y_axis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "size": 60.0, + "clobber": false, + "hide": true + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "enable_sketch_mode", + "entity_id": "[uuid]", + "ortho": false, + "animated": false, + "adjust_camera": false, + "planar_normal": { + "x": 0.0, + "y": -1.0, + "z": 0.0 + } + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "start_path" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "move_path_pen", + "path": "[uuid]", + "to": { + "x": 1.0, + "y": 0.0, + "z": 0.0 + } + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "sketch_mode_disable" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "extend_path", + "path": "[uuid]", + "segment": { + "type": "arc", + "center": { + "x": 0.0, + "y": 0.0 + }, + "radius": 1.0, + "start": { + "unit": "degrees", + "value": 0.0 + }, + "end": { + "unit": "degrees", + "value": 360.0 + }, + "relative": false + } + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "close_path", + "path_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "entity_linear_pattern_transform", + "entity_id": "[uuid]", + "transform": [], + "transforms": [ + [ + { + "translate": { + "x": 4.0, + "y": 0.0, + "z": 0.0 + }, + "scale": { + "x": 1.0, + "y": 1.0, + "z": 1.0 + }, + "rotation": { + "axis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "angle": { + "unit": "degrees", + "value": 0.0 + }, + "origin": { + "type": "local" + } + }, + "replicate": true + } + ], + [ + { + "translate": { + "x": 8.0, + "y": 0.0, + "z": 0.0 + }, + "scale": { + "x": 1.0, + "y": 1.0, + "z": 1.0 + }, + "rotation": { + "axis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "angle": { + "unit": "degrees", + "value": 0.0 + }, + "origin": { + "type": "local" + } + }, + "replicate": true + } + ], + [ + { + "translate": { + "x": 12.0, + "y": 0.0, + "z": 0.0 + }, + "scale": { + "x": 1.0, + "y": 1.0, + "z": 1.0 + }, + "rotation": { + "axis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "angle": { + "unit": "degrees", + "value": 0.0 + }, + "origin": { + "type": "local" + } + }, + "replicate": true + } + ], + [ + { + "translate": { + "x": 16.0, + "y": 0.0, + "z": 0.0 + }, + "scale": { + "x": 1.0, + "y": 1.0, + "z": 1.0 + }, + "rotation": { + "axis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "angle": { + "unit": "degrees", + "value": 0.0 + }, + "origin": { + "type": "local" + } + }, + "replicate": true + } + ], + [ + { + "translate": { + "x": 20.0, + "y": 0.0, + "z": 0.0 + }, + "scale": { + "x": 1.0, + "y": 1.0, + "z": 1.0 + }, + "rotation": { + "axis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "angle": { + "unit": "degrees", + "value": 0.0 + }, + "origin": { + "type": "local" + } + }, + "replicate": true + } + ], + [ + { + "translate": { + "x": 24.0, + "y": 0.0, + "z": 0.0 + }, + "scale": { + "x": 1.0, + "y": 1.0, + "z": 1.0 + }, + "rotation": { + "axis": { + "x": 0.0, + "y": 0.0, + "z": 1.0 + }, + "angle": { + "unit": "degrees", + "value": 0.0 + }, + "origin": { + "type": "local" + } + }, + "replicate": true + } + ] + ] + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "enable_sketch_mode", + "entity_id": "[uuid]", + "ortho": false, + "animated": false, + "adjust_camera": false, + "planar_normal": { + "x": 0.0, + "y": -1.0, + "z": 0.0 + } + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "extrude", + "target": "[uuid]", + "distance": 1.0, + "faces": null + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "sketch_mode_disable" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "object_bring_to_front", + "object_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_extrusion_face_info", + "object_id": "[uuid]", + "edge_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "enable_sketch_mode", + "entity_id": "[uuid]", + "ortho": false, + "animated": false, + "adjust_camera": false, + "planar_normal": { + "x": 0.0, + "y": -1.0, + "z": 0.0 + } + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "extrude", + "target": "[uuid]", + "distance": 1.0, + "faces": null + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "sketch_mode_disable" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "object_bring_to_front", + "object_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_extrusion_face_info", + "object_id": "[uuid]", + "edge_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "enable_sketch_mode", + "entity_id": "[uuid]", + "ortho": false, + "animated": false, + "adjust_camera": false, + "planar_normal": { + "x": 0.0, + "y": -1.0, + "z": 0.0 + } + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "extrude", + "target": "[uuid]", + "distance": 1.0, + "faces": null + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "sketch_mode_disable" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "object_bring_to_front", + "object_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_extrusion_face_info", + "object_id": "[uuid]", + "edge_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "enable_sketch_mode", + "entity_id": "[uuid]", + "ortho": false, + "animated": false, + "adjust_camera": false, + "planar_normal": { + "x": 0.0, + "y": -1.0, + "z": 0.0 + } + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "extrude", + "target": "[uuid]", + "distance": 1.0, + "faces": null + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "sketch_mode_disable" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "object_bring_to_front", + "object_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_extrusion_face_info", + "object_id": "[uuid]", + "edge_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "enable_sketch_mode", + "entity_id": "[uuid]", + "ortho": false, + "animated": false, + "adjust_camera": false, + "planar_normal": { + "x": 0.0, + "y": -1.0, + "z": 0.0 + } + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "extrude", + "target": "[uuid]", + "distance": 1.0, + "faces": null + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "sketch_mode_disable" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "object_bring_to_front", + "object_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_extrusion_face_info", + "object_id": "[uuid]", + "edge_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "enable_sketch_mode", + "entity_id": "[uuid]", + "ortho": false, + "animated": false, + "adjust_camera": false, + "planar_normal": { + "x": 0.0, + "y": -1.0, + "z": 0.0 + } + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "extrude", + "target": "[uuid]", + "distance": 1.0, + "faces": null + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "sketch_mode_disable" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "object_bring_to_front", + "object_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_extrusion_face_info", + "object_id": "[uuid]", + "edge_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "enable_sketch_mode", + "entity_id": "[uuid]", + "ortho": false, + "animated": false, + "adjust_camera": false, + "planar_normal": { + "x": 0.0, + "y": -1.0, + "z": 0.0 + } + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "extrude", + "target": "[uuid]", + "distance": 1.0, + "faces": null + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "sketch_mode_disable" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "object_bring_to_front", + "object_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_extrusion_face_info", + "object_id": "[uuid]", + "edge_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_opposite_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_next_adjacent_edge", + "object_id": "[uuid]", + "edge_id": "[uuid]", + "face_id": "[uuid]" + } + } +] diff --git a/rust/kcl-lib/tests/pattern_linear_in_module/artifact_graph_flowchart.snap b/rust/kcl-lib/tests/pattern_linear_in_module/artifact_graph_flowchart.snap new file mode 100644 index 000000000..b7966628b --- /dev/null +++ b/rust/kcl-lib/tests/pattern_linear_in_module/artifact_graph_flowchart.snap @@ -0,0 +1,6 @@ +--- +source: kcl-lib/src/simulation_tests.rs +description: Artifact graph flowchart pattern_linear_in_module.kcl +extension: md +snapshot_kind: binary +--- diff --git a/rust/kcl-lib/tests/pattern_linear_in_module/artifact_graph_flowchart.snap.md b/rust/kcl-lib/tests/pattern_linear_in_module/artifact_graph_flowchart.snap.md new file mode 100644 index 000000000..b8510d85e --- /dev/null +++ b/rust/kcl-lib/tests/pattern_linear_in_module/artifact_graph_flowchart.snap.md @@ -0,0 +1,33 @@ +```mermaid +flowchart LR + subgraph path2 [Path] + 2["Path
[54, 89, 5]"] + 3["Segment
[54, 89, 5]"] + 4[Solid2d] + end + 1["Plane
[29, 46, 5]"] + 5["Sweep Extrusion
[200, 219, 5]"] + 6[Wall] + 7["Cap Start"] + 8["Cap End"] + 9["SweepEdge Opposite"] + 10["SweepEdge Adjacent"] + 11["Sweep Extrusion
[200, 219, 5]"] + 12["Sweep Extrusion
[200, 219, 5]"] + 13["Sweep Extrusion
[200, 219, 5]"] + 14["Sweep Extrusion
[200, 219, 5]"] + 15["Sweep Extrusion
[200, 219, 5]"] + 16["Sweep Extrusion
[200, 219, 5]"] + 1 --- 2 + 2 --- 3 + 2 ---- 5 + 2 --- 4 + 3 --- 6 + 3 --- 9 + 3 --- 10 + 5 --- 6 + 5 --- 7 + 5 --- 8 + 5 --- 9 + 5 --- 10 +``` diff --git a/rust/kcl-lib/tests/pattern_linear_in_module/ast.snap b/rust/kcl-lib/tests/pattern_linear_in_module/ast.snap new file mode 100644 index 000000000..b9fcea5c2 --- /dev/null +++ b/rust/kcl-lib/tests/pattern_linear_in_module/ast.snap @@ -0,0 +1,89 @@ +--- +source: kcl-lib/src/simulation_tests.rs +description: Result of parsing pattern_linear_in_module.kcl +--- +{ + "Ok": { + "body": [ + { + "commentStart": 0, + "end": 0, + "path": { + "type": "Kcl", + "filename": "thing.kcl" + }, + "selector": { + "type": "List", + "items": [ + { + "alias": null, + "commentStart": 7, + "end": 0, + "name": { + "commentStart": 7, + "end": 0, + "name": "thing", + "start": 0, + "type": "Identifier" + }, + "start": 0, + "type": "ImportItem" + } + ] + }, + "start": 0, + "type": "ImportStatement", + "type": "ImportStatement" + }, + { + "commentStart": 29, + "end": 0, + "expression": { + "arguments": [], + "callee": { + "abs_path": false, + "commentStart": 31, + "end": 0, + "name": { + "commentStart": 31, + "end": 0, + "name": "thing", + "start": 0, + "type": "Identifier" + }, + "path": [], + "start": 0, + "type": "Name" + }, + "commentStart": 31, + "end": 0, + "start": 0, + "type": "CallExpression", + "type": "CallExpression" + }, + "start": 0, + "type": "ExpressionStatement", + "type": "ExpressionStatement" + } + ], + "commentStart": 0, + "end": 0, + "nonCodeMeta": { + "nonCodeNodes": { + "0": [ + { + "commentStart": 29, + "end": 0, + "start": 0, + "type": "NonCodeNode", + "value": { + "type": "newLine" + } + } + ] + }, + "startNodes": [] + }, + "start": 0 + } +} diff --git a/rust/kcl-lib/tests/pattern_linear_in_module/input.kcl b/rust/kcl-lib/tests/pattern_linear_in_module/input.kcl new file mode 100644 index 000000000..7060ff276 --- /dev/null +++ b/rust/kcl-lib/tests/pattern_linear_in_module/input.kcl @@ -0,0 +1,3 @@ +import thing from "thing.kcl" + +thing() diff --git a/rust/kcl-lib/tests/pattern_linear_in_module/ops.snap b/rust/kcl-lib/tests/pattern_linear_in_module/ops.snap new file mode 100644 index 000000000..589583cb2 --- /dev/null +++ b/rust/kcl-lib/tests/pattern_linear_in_module/ops.snap @@ -0,0 +1,344 @@ +--- +source: kcl-lib/src/simulation_tests.rs +description: Operations executed pattern_linear_in_module.kcl +--- +[ + { + "type": "UserDefinedFunctionCall", + "name": "thing", + "functionSourceRange": [ + 15, + 221, + 5 + ], + "unlabeledArg": null, + "labeledArgs": {}, + "sourceRange": [] + }, + { + "labeledArgs": { + "data": { + "value": { + "type": "Plane", + "artifact_id": "[uuid]" + }, + "sourceRange": [] + } + }, + "name": "startSketchOn", + "sourceRange": [], + "type": "StdLibCall", + "unlabeledArg": null + }, + { + "type": "UserDefinedFunctionCall", + "name": "circle", + "functionSourceRange": [ + 0, + 0, + 0 + ], + "unlabeledArg": null, + "labeledArgs": { + "center": { + "value": { + "type": "Array", + "value": [ + { + "type": "Number", + "value": 0.0, + "ty": { + "type": "Default", + "len": { + "type": "Mm" + }, + "angle": { + "type": "Degrees" + } + } + }, + { + "type": "Number", + "value": 0.0, + "ty": { + "type": "Default", + "len": { + "type": "Mm" + }, + "angle": { + "type": "Degrees" + } + } + } + ] + }, + "sourceRange": [] + }, + "radius": { + "value": { + "type": "Number", + "value": 1.0, + "ty": { + "type": "Default", + "len": { + "type": "Mm" + }, + "angle": { + "type": "Degrees" + } + } + }, + "sourceRange": [] + } + }, + "sourceRange": [] + }, + { + "type": "UserDefinedFunctionReturn" + }, + { + "labeledArgs": { + "length": { + "value": { + "type": "Number", + "value": 1.0, + "ty": { + "type": "Default", + "len": { + "type": "Mm" + }, + "angle": { + "type": "Degrees" + } + } + }, + "sourceRange": [] + } + }, + "name": "extrude", + "sourceRange": [], + "type": "StdLibCall", + "unlabeledArg": { + "value": { + "type": "Array", + "value": [ + { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + }, + { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + }, + { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + }, + { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + }, + { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + }, + { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + }, + { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + } + ] + }, + "sourceRange": [] + } + }, + { + "type": "UserDefinedFunctionReturn" + }, + { + "type": "UserDefinedFunctionCall", + "name": "thing", + "functionSourceRange": [ + 15, + 221, + 5 + ], + "unlabeledArg": null, + "labeledArgs": {}, + "sourceRange": [] + }, + { + "labeledArgs": { + "data": { + "value": { + "type": "Plane", + "artifact_id": "[uuid]" + }, + "sourceRange": [] + } + }, + "name": "startSketchOn", + "sourceRange": [], + "type": "StdLibCall", + "unlabeledArg": null + }, + { + "type": "UserDefinedFunctionCall", + "name": "circle", + "functionSourceRange": [ + 0, + 0, + 0 + ], + "unlabeledArg": null, + "labeledArgs": { + "center": { + "value": { + "type": "Array", + "value": [ + { + "type": "Number", + "value": 0.0, + "ty": { + "type": "Default", + "len": { + "type": "Mm" + }, + "angle": { + "type": "Degrees" + } + } + }, + { + "type": "Number", + "value": 0.0, + "ty": { + "type": "Default", + "len": { + "type": "Mm" + }, + "angle": { + "type": "Degrees" + } + } + } + ] + }, + "sourceRange": [] + }, + "radius": { + "value": { + "type": "Number", + "value": 1.0, + "ty": { + "type": "Default", + "len": { + "type": "Mm" + }, + "angle": { + "type": "Degrees" + } + } + }, + "sourceRange": [] + } + }, + "sourceRange": [] + }, + { + "type": "UserDefinedFunctionReturn" + }, + { + "labeledArgs": { + "length": { + "value": { + "type": "Number", + "value": 1.0, + "ty": { + "type": "Default", + "len": { + "type": "Mm" + }, + "angle": { + "type": "Degrees" + } + } + }, + "sourceRange": [] + } + }, + "name": "extrude", + "sourceRange": [], + "type": "StdLibCall", + "unlabeledArg": { + "value": { + "type": "Array", + "value": [ + { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + }, + { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + }, + { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + }, + { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + }, + { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + }, + { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + }, + { + "type": "Sketch", + "value": { + "artifactId": "[uuid]" + } + } + ] + }, + "sourceRange": [] + } + }, + { + "type": "UserDefinedFunctionReturn" + } +] diff --git a/rust/kcl-lib/tests/pattern_linear_in_module/program_memory.snap b/rust/kcl-lib/tests/pattern_linear_in_module/program_memory.snap new file mode 100644 index 000000000..77112d383 --- /dev/null +++ b/rust/kcl-lib/tests/pattern_linear_in_module/program_memory.snap @@ -0,0 +1,9 @@ +--- +source: kcl-lib/src/simulation_tests.rs +description: Variables in memory after executing pattern_linear_in_module.kcl +--- +{ + "thing": { + "type": "Function" + } +} diff --git a/rust/kcl-lib/tests/pattern_linear_in_module/rendered_model.png b/rust/kcl-lib/tests/pattern_linear_in_module/rendered_model.png new file mode 100644 index 000000000..a84c6737a Binary files /dev/null and b/rust/kcl-lib/tests/pattern_linear_in_module/rendered_model.png differ diff --git a/rust/kcl-lib/tests/pattern_linear_in_module/thing.kcl b/rust/kcl-lib/tests/pattern_linear_in_module/thing.kcl new file mode 100644 index 000000000..c9532988e --- /dev/null +++ b/rust/kcl-lib/tests/pattern_linear_in_module/thing.kcl @@ -0,0 +1,13 @@ +export fn thing() { + return startSketchOn(XZ) + |> circle(center = [0, 0], radius = 1) + |> patternLinear2d( + axis = [1, 0], + instances = 7, + distance = 4 + ) + |> extrude(length = 1) +} + +// This makes it run in isolated mode when the function is imported. +thing() diff --git a/rust/kcl-lib/tests/pattern_linear_in_module/unparsed.snap b/rust/kcl-lib/tests/pattern_linear_in_module/unparsed.snap new file mode 100644 index 000000000..00bb2a9de --- /dev/null +++ b/rust/kcl-lib/tests/pattern_linear_in_module/unparsed.snap @@ -0,0 +1,7 @@ +--- +source: kcl-lib/src/simulation_tests.rs +description: Result of unparsing pattern_linear_in_module.kcl +--- +import thing from "thing.kcl" + +thing() diff --git a/rust/kcl-lib/tests/pattern_linear_in_module/unparsed@thing.kcl.snap b/rust/kcl-lib/tests/pattern_linear_in_module/unparsed@thing.kcl.snap new file mode 100644 index 000000000..bbea38e2f --- /dev/null +++ b/rust/kcl-lib/tests/pattern_linear_in_module/unparsed@thing.kcl.snap @@ -0,0 +1,13 @@ +--- +source: kcl-lib/src/simulation_tests.rs +description: Result of unparsing tests/pattern_linear_in_module/thing.kcl +--- +export fn thing() { + return startSketchOn(XZ) + |> circle(center = [0, 0], radius = 1) + |> patternLinear2d(axis = [1, 0], instances = 7, distance = 4) + |> extrude(length = 1) +} + +// This makes it run in isolated mode when the function is imported. +thing()