diff --git a/rust/kcl-lib/src/simulation_tests.rs b/rust/kcl-lib/src/simulation_tests.rs index 0760ee627..6fd8611af 100644 --- a/rust/kcl-lib/src/simulation_tests.rs +++ b/rust/kcl-lib/src/simulation_tests.rs @@ -3360,3 +3360,24 @@ mod nested_windows_main_kcl { super::execute(TEST_NAME, true).await } } +mod nested_assembly { + const TEST_NAME: &str = "nested_assembly"; + + /// 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 + } +} diff --git a/rust/kcl-lib/tests/nested_assembly/artifact_commands.snap b/rust/kcl-lib/tests/nested_assembly/artifact_commands.snap new file mode 100644 index 000000000..27c86f808 --- /dev/null +++ b/rust/kcl-lib/tests/nested_assembly/artifact_commands.snap @@ -0,0 +1,184 @@ +--- +source: kcl-lib/src/simulation_tests.rs +description: Artifact commands nested_main_kcl.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": 1.0, + "z": 0.0 + }, + "size": 60.0, + "clobber": false, + "hide": true + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "close_path", + "path_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": 0.0, + "z": 1.0 + } + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "extend_path", + "path": "[uuid]", + "segment": { + "type": "arc", + "center": { + "x": 15.0, + "y": 0.0 + }, + "radius": 5.0, + "start": { + "unit": "degrees", + "value": 0.0 + }, + "end": { + "unit": "degrees", + "value": 360.0 + }, + "relative": false + } + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "move_path_pen", + "path": "[uuid]", + "to": { + "x": 20.0, + "y": 0.0, + "z": 0.0 + } + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "sketch_mode_disable" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "start_path" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "object_bring_to_front", + "object_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "revolve", + "target": "[uuid]", + "origin": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "axis": { + "x": 0.0, + "y": 1.0, + "z": 0.0 + }, + "axis_is_2d": true, + "angle": { + "unit": "degrees", + "value": 360.0 + }, + "tolerance": 0.0000001, + "opposite": "None" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_adjacency_info", + "object_id": "[uuid]", + "edge_id": "[uuid]" + } + }, + { + "cmdId": "[uuid]", + "range": [], + "command": { + "type": "solid3d_get_extrusion_face_info", + "object_id": "[uuid]", + "edge_id": "[uuid]" + } + } +] diff --git a/rust/kcl-lib/tests/nested_assembly/artifact_graph_flowchart.snap b/rust/kcl-lib/tests/nested_assembly/artifact_graph_flowchart.snap new file mode 100644 index 000000000..e070c36ff --- /dev/null +++ b/rust/kcl-lib/tests/nested_assembly/artifact_graph_flowchart.snap @@ -0,0 +1,6 @@ +--- +source: kcl-lib/src/simulation_tests.rs +description: Artifact graph flowchart nested_main_kcl.kcl +extension: md +snapshot_kind: binary +--- diff --git a/rust/kcl-lib/tests/nested_assembly/artifact_graph_flowchart.snap.md b/rust/kcl-lib/tests/nested_assembly/artifact_graph_flowchart.snap.md new file mode 100644 index 000000000..112f43416 --- /dev/null +++ b/rust/kcl-lib/tests/nested_assembly/artifact_graph_flowchart.snap.md @@ -0,0 +1,23 @@ +```mermaid +flowchart LR + subgraph path2 [Path] + 2["Path
[43, 81, 1]"] + 3["Segment
[43, 81, 1]"] + 4[Solid2d] + end + 1["Plane
[18, 35, 1]"] + 5["Sweep Revolve
[89, 142, 1]"] + 6[Wall] + %% face_code_ref=Missing NodePath + 7["SweepEdge Adjacent"] + 1 --- 2 + 2 --- 3 + 2 --- 4 + 2 ---- 5 + 5 <--x 3 + 3 --- 6 + 3 --- 7 + 5 --- 6 + 5 --- 7 + 6 --- 7 +``` diff --git a/rust/kcl-lib/tests/nested_assembly/ast.snap b/rust/kcl-lib/tests/nested_assembly/ast.snap new file mode 100644 index 000000000..9e7538f9e --- /dev/null +++ b/rust/kcl-lib/tests/nested_assembly/ast.snap @@ -0,0 +1,73 @@ +--- +source: kcl-lib/src/simulation_tests.rs +description: Result of parsing nested_main_kcl.kcl +--- +{ + "Ok": { + "body": [ + { + "commentStart": 0, + "end": 0, + "path": { + "type": "Kcl", + "filename": "nested/foo/bar/main.kcl" + }, + "selector": { + "type": "None", + "alias": { + "commentStart": 0, + "end": 0, + "name": "bar", + "start": 0, + "type": "Identifier" + } + }, + "start": 0, + "type": "ImportStatement", + "type": "ImportStatement" + }, + { + "commentStart": 0, + "end": 0, + "expression": { + "abs_path": false, + "commentStart": 0, + "end": 0, + "name": { + "commentStart": 0, + "end": 0, + "name": "bar", + "start": 0, + "type": "Identifier" + }, + "path": [], + "start": 0, + "type": "Name", + "type": "Name" + }, + "start": 0, + "type": "ExpressionStatement", + "type": "ExpressionStatement" + } + ], + "commentStart": 0, + "end": 0, + "nonCodeMeta": { + "nonCodeNodes": { + "0": [ + { + "commentStart": 0, + "end": 0, + "start": 0, + "type": "NonCodeNode", + "value": { + "type": "newLine" + } + } + ] + }, + "startNodes": [] + }, + "start": 0 + } +} diff --git a/rust/kcl-lib/tests/nested_assembly/input.kcl b/rust/kcl-lib/tests/nested_assembly/input.kcl new file mode 100644 index 000000000..ab113746f --- /dev/null +++ b/rust/kcl-lib/tests/nested_assembly/input.kcl @@ -0,0 +1,3 @@ +import "nested/foo/bar/main.kcl" as bar + +bar diff --git a/rust/kcl-lib/tests/nested_assembly/nested/foo/bar/imported.kcl b/rust/kcl-lib/tests/nested_assembly/nested/foo/bar/imported.kcl new file mode 100644 index 000000000..fefdcad20 --- /dev/null +++ b/rust/kcl-lib/tests/nested_assembly/nested/foo/bar/imported.kcl @@ -0,0 +1,7 @@ +// A donut shape. +startSketchOn(XY) + |> circle( center = [15, 0], radius = 5 ) + |> revolve( + angle = 360, + axis = Y, + ) diff --git a/rust/kcl-lib/tests/nested_assembly/nested/foo/bar/main.kcl b/rust/kcl-lib/tests/nested_assembly/nested/foo/bar/main.kcl new file mode 100644 index 000000000..26be51464 --- /dev/null +++ b/rust/kcl-lib/tests/nested_assembly/nested/foo/bar/main.kcl @@ -0,0 +1,3 @@ +import "imported.kcl" as imported + +imported diff --git a/rust/kcl-lib/tests/nested_assembly/ops.snap b/rust/kcl-lib/tests/nested_assembly/ops.snap new file mode 100644 index 000000000..a68c3f395 --- /dev/null +++ b/rust/kcl-lib/tests/nested_assembly/ops.snap @@ -0,0 +1,18 @@ +--- +source: kcl-lib/src/simulation_tests.rs +description: Operations executed nested_main_kcl.kcl +--- +[ + { + "type": "GroupBegin", + "group": { + "type": "ModuleInstance", + "name": "main.kcl", + "moduleId": 0 + }, + "sourceRange": [] + }, + { + "type": "GroupEnd" + } +] diff --git a/rust/kcl-lib/tests/nested_assembly/program_memory.snap b/rust/kcl-lib/tests/nested_assembly/program_memory.snap new file mode 100644 index 000000000..ae79838e6 --- /dev/null +++ b/rust/kcl-lib/tests/nested_assembly/program_memory.snap @@ -0,0 +1,10 @@ +--- +source: kcl-lib/src/simulation_tests.rs +description: Variables in memory after executing nested_main_kcl.kcl +--- +{ + "bar": { + "type": "Module", + "value": 1 + } +} diff --git a/rust/kcl-lib/tests/nested_assembly/rendered_model.png b/rust/kcl-lib/tests/nested_assembly/rendered_model.png new file mode 100644 index 000000000..f6cfde3de Binary files /dev/null and b/rust/kcl-lib/tests/nested_assembly/rendered_model.png differ diff --git a/rust/kcl-lib/tests/nested_assembly/unparsed.snap b/rust/kcl-lib/tests/nested_assembly/unparsed.snap new file mode 100644 index 000000000..e97ab63f6 --- /dev/null +++ b/rust/kcl-lib/tests/nested_assembly/unparsed.snap @@ -0,0 +1,7 @@ +--- +source: kcl-lib/src/simulation_tests.rs +description: Result of unparsing nested_main_kcl.kcl +--- +import "nested/foo/bar/main.kcl" as bar + +bar diff --git a/rust/kcl-lib/tests/nested_assembly/unparsed@imported.kcl.snap b/rust/kcl-lib/tests/nested_assembly/unparsed@imported.kcl.snap new file mode 100644 index 000000000..5936b09eb --- /dev/null +++ b/rust/kcl-lib/tests/nested_assembly/unparsed@imported.kcl.snap @@ -0,0 +1,8 @@ +--- +source: kcl-lib/src/simulation_tests.rs +description: Result of unparsing tests/nested_assembly/nested/foo/bar/imported.kcl +--- +// A donut shape. +startSketchOn(XY) + |> circle(center = [15, 0], radius = 5) + |> revolve(angle = 360, axis = Y) diff --git a/rust/kcl-lib/tests/nested_assembly/unparsed@main.kcl.snap b/rust/kcl-lib/tests/nested_assembly/unparsed@main.kcl.snap new file mode 100644 index 000000000..a1b845096 --- /dev/null +++ b/rust/kcl-lib/tests/nested_assembly/unparsed@main.kcl.snap @@ -0,0 +1,7 @@ +--- +source: kcl-lib/src/simulation_tests.rs +description: Result of unparsing tests/nested_assembly/nested/foo/bar/main.kcl +--- +import "imported.kcl" as imported + +imported