From 7b4bf84db65674221a44a269effbdf07e09e0ac6 Mon Sep 17 00:00:00 2001 From: Adam Chalmers Date: Fri, 15 Nov 2024 09:57:57 -0600 Subject: [PATCH] Move tests from no_visuals to simulation --- src/wasm-lib/kcl/src/simulation_tests.rs | 378 ++++++++++++++++++ .../kcl/tests/array_elem_push_fail/ast.snap | 157 ++++++++ .../array_elem_push_fail/execution_error.snap | 6 + .../tests/array_elem_push_fail/input.kcl} | 0 .../tests/array_elem_push_fail/tokens.snap | 219 ++++++++++ .../kcl/tests/array_index_oob/ast.snap | 82 ++++ .../array_index_oob/execution_error.snap | 6 + .../kcl/tests/array_index_oob/input.kcl | 2 + .../kcl/tests/array_index_oob/tokens.snap | 105 +++++ .../kcl/tests/comparisons_multiple/ast.snap | 80 ++++ .../comparisons_multiple/execution_error.snap | 6 + .../tests/comparisons_multiple/input.kcl} | 0 .../tests/comparisons_multiple/tokens.snap | 105 +++++ .../kcl/tests/import_constant/ast.snap | 35 ++ .../import_constant/execution_error.snap | 6 + .../tests/import_constant/input.kcl} | 0 .../kcl/tests/import_constant/tokens.snap | 57 +++ src/wasm-lib/kcl/tests/import_cycle1/ast.snap | 119 ++++++ .../tests/import_cycle1/execution_error.snap | 6 + .../kcl/tests/import_cycle1/input.kcl | 5 + .../kcl/tests/import_cycle1/tokens.snap | 219 ++++++++++ .../import_from_other_directory/input.kcl} | 0 .../kcl/tests/import_side_effect/ast.snap | 35 ++ .../import_side_effect/execution_error.snap | 6 + .../tests/import_side_effect/input.kcl} | 0 .../kcl/tests/import_side_effect/tokens.snap | 57 +++ .../tests/invalid_index_fractional/ast.snap | 107 +++++ .../execution_error.snap | 6 + .../tests/invalid_index_fractional/input.kcl | 2 + .../invalid_index_fractional/tokens.snap | 147 +++++++ .../kcl/tests/invalid_index_negative/ast.snap | 141 +++++++ .../execution_error.snap | 6 + .../tests/invalid_index_negative/input.kcl | 3 + .../tests/invalid_index_negative/tokens.snap | 189 +++++++++ .../kcl/tests/invalid_index_str/ast.snap | 107 +++++ .../invalid_index_str/execution_error.snap | 6 + .../kcl/tests/invalid_index_str/input.kcl | 2 + .../kcl/tests/invalid_index_str/tokens.snap | 147 +++++++ .../kcl/tests/invalid_member_object/ast.snap | 83 ++++ .../execution_error.snap | 6 + .../kcl/tests/invalid_member_object/input.kcl | 2 + .../tests/invalid_member_object/tokens.snap | 99 +++++ .../tests/invalid_member_object_prop/ast.snap | 83 ++++ .../execution_error.snap | 6 + .../invalid_member_object_prop/input.kcl | 2 + .../invalid_member_object_prop/tokens.snap | 99 +++++ .../tests/non_string_key_of_object/ast.snap | 102 +++++ .../execution_error.snap | 6 + .../tests/non_string_key_of_object/input.kcl | 2 + .../non_string_key_of_object/tokens.snap | 141 +++++++ .../kcl/tests/object_prop_not_found/ast.snap | 82 ++++ .../execution_error.snap | 6 + .../kcl/tests/object_prop_not_found/input.kcl | 2 + .../tests/object_prop_not_found/tokens.snap | 111 +++++ .../ast.snap | 150 +++++++ .../execution_error.snap | 6 + .../input.kcl} | 2 +- .../tokens.snap | 219 ++++++++++ .../inputs/no_visuals/array_index_oob.kcl | 2 - .../inputs/no_visuals/import_cycle1.kcl | 3 - .../no_visuals/invalid_index_fractional.kcl | 2 - .../no_visuals/invalid_index_negative.kcl | 3 - .../inputs/no_visuals/invalid_index_str.kcl | 2 - .../no_visuals/invalid_member_object.kcl | 2 - .../no_visuals/invalid_member_object_prop.kcl | 2 - .../no_visuals/non_string_key_of_object.kcl | 2 - .../no_visuals/object_prop_not_found.kcl | 2 - src/wasm-lib/tests/executor/no_visuals.rs | 129 ------ 68 files changed, 3762 insertions(+), 150 deletions(-) create mode 100644 src/wasm-lib/kcl/tests/array_elem_push_fail/ast.snap create mode 100644 src/wasm-lib/kcl/tests/array_elem_push_fail/execution_error.snap rename src/wasm-lib/{tests/executor/inputs/no_visuals/array_elem_push_fail.kcl => kcl/tests/array_elem_push_fail/input.kcl} (100%) create mode 100644 src/wasm-lib/kcl/tests/array_elem_push_fail/tokens.snap create mode 100644 src/wasm-lib/kcl/tests/array_index_oob/ast.snap create mode 100644 src/wasm-lib/kcl/tests/array_index_oob/execution_error.snap create mode 100644 src/wasm-lib/kcl/tests/array_index_oob/input.kcl create mode 100644 src/wasm-lib/kcl/tests/array_index_oob/tokens.snap create mode 100644 src/wasm-lib/kcl/tests/comparisons_multiple/ast.snap create mode 100644 src/wasm-lib/kcl/tests/comparisons_multiple/execution_error.snap rename src/wasm-lib/{tests/executor/inputs/no_visuals/comparisons_multiple.kcl => kcl/tests/comparisons_multiple/input.kcl} (100%) create mode 100644 src/wasm-lib/kcl/tests/comparisons_multiple/tokens.snap create mode 100644 src/wasm-lib/kcl/tests/import_constant/ast.snap create mode 100644 src/wasm-lib/kcl/tests/import_constant/execution_error.snap rename src/wasm-lib/{tests/executor/inputs/no_visuals/import_constant.kcl => kcl/tests/import_constant/input.kcl} (100%) create mode 100644 src/wasm-lib/kcl/tests/import_constant/tokens.snap create mode 100644 src/wasm-lib/kcl/tests/import_cycle1/ast.snap create mode 100644 src/wasm-lib/kcl/tests/import_cycle1/execution_error.snap create mode 100644 src/wasm-lib/kcl/tests/import_cycle1/input.kcl create mode 100644 src/wasm-lib/kcl/tests/import_cycle1/tokens.snap rename src/wasm-lib/{tests/executor/inputs/no_visuals/import_from_other_directory.kcl => kcl/tests/import_from_other_directory/input.kcl} (100%) create mode 100644 src/wasm-lib/kcl/tests/import_side_effect/ast.snap create mode 100644 src/wasm-lib/kcl/tests/import_side_effect/execution_error.snap rename src/wasm-lib/{tests/executor/inputs/no_visuals/import_side_effect.kcl => kcl/tests/import_side_effect/input.kcl} (100%) create mode 100644 src/wasm-lib/kcl/tests/import_side_effect/tokens.snap create mode 100644 src/wasm-lib/kcl/tests/invalid_index_fractional/ast.snap create mode 100644 src/wasm-lib/kcl/tests/invalid_index_fractional/execution_error.snap create mode 100644 src/wasm-lib/kcl/tests/invalid_index_fractional/input.kcl create mode 100644 src/wasm-lib/kcl/tests/invalid_index_fractional/tokens.snap create mode 100644 src/wasm-lib/kcl/tests/invalid_index_negative/ast.snap create mode 100644 src/wasm-lib/kcl/tests/invalid_index_negative/execution_error.snap create mode 100644 src/wasm-lib/kcl/tests/invalid_index_negative/input.kcl create mode 100644 src/wasm-lib/kcl/tests/invalid_index_negative/tokens.snap create mode 100644 src/wasm-lib/kcl/tests/invalid_index_str/ast.snap create mode 100644 src/wasm-lib/kcl/tests/invalid_index_str/execution_error.snap create mode 100644 src/wasm-lib/kcl/tests/invalid_index_str/input.kcl create mode 100644 src/wasm-lib/kcl/tests/invalid_index_str/tokens.snap create mode 100644 src/wasm-lib/kcl/tests/invalid_member_object/ast.snap create mode 100644 src/wasm-lib/kcl/tests/invalid_member_object/execution_error.snap create mode 100644 src/wasm-lib/kcl/tests/invalid_member_object/input.kcl create mode 100644 src/wasm-lib/kcl/tests/invalid_member_object/tokens.snap create mode 100644 src/wasm-lib/kcl/tests/invalid_member_object_prop/ast.snap create mode 100644 src/wasm-lib/kcl/tests/invalid_member_object_prop/execution_error.snap create mode 100644 src/wasm-lib/kcl/tests/invalid_member_object_prop/input.kcl create mode 100644 src/wasm-lib/kcl/tests/invalid_member_object_prop/tokens.snap create mode 100644 src/wasm-lib/kcl/tests/non_string_key_of_object/ast.snap create mode 100644 src/wasm-lib/kcl/tests/non_string_key_of_object/execution_error.snap create mode 100644 src/wasm-lib/kcl/tests/non_string_key_of_object/input.kcl create mode 100644 src/wasm-lib/kcl/tests/non_string_key_of_object/tokens.snap create mode 100644 src/wasm-lib/kcl/tests/object_prop_not_found/ast.snap create mode 100644 src/wasm-lib/kcl/tests/object_prop_not_found/execution_error.snap create mode 100644 src/wasm-lib/kcl/tests/object_prop_not_found/input.kcl create mode 100644 src/wasm-lib/kcl/tests/object_prop_not_found/tokens.snap create mode 100644 src/wasm-lib/kcl/tests/pipe_substitution_inside_function_called_from_pipeline/ast.snap create mode 100644 src/wasm-lib/kcl/tests/pipe_substitution_inside_function_called_from_pipeline/execution_error.snap rename src/wasm-lib/{tests/executor/inputs/no_visuals/pipe_substitution_inside_function_called_from_pipeline.kcl => kcl/tests/pipe_substitution_inside_function_called_from_pipeline/input.kcl} (86%) create mode 100644 src/wasm-lib/kcl/tests/pipe_substitution_inside_function_called_from_pipeline/tokens.snap delete mode 100644 src/wasm-lib/tests/executor/inputs/no_visuals/array_index_oob.kcl delete mode 100644 src/wasm-lib/tests/executor/inputs/no_visuals/import_cycle1.kcl delete mode 100644 src/wasm-lib/tests/executor/inputs/no_visuals/invalid_index_fractional.kcl delete mode 100644 src/wasm-lib/tests/executor/inputs/no_visuals/invalid_index_negative.kcl delete mode 100644 src/wasm-lib/tests/executor/inputs/no_visuals/invalid_index_str.kcl delete mode 100644 src/wasm-lib/tests/executor/inputs/no_visuals/invalid_member_object.kcl delete mode 100644 src/wasm-lib/tests/executor/inputs/no_visuals/invalid_member_object_prop.kcl delete mode 100644 src/wasm-lib/tests/executor/inputs/no_visuals/non_string_key_of_object.kcl delete mode 100644 src/wasm-lib/tests/executor/inputs/no_visuals/object_prop_not_found.kcl diff --git a/src/wasm-lib/kcl/src/simulation_tests.rs b/src/wasm-lib/kcl/src/simulation_tests.rs index 4a7c67e006..a7fd874b1a 100644 --- a/src/wasm-lib/kcl/src/simulation_tests.rs +++ b/src/wasm-lib/kcl/src/simulation_tests.rs @@ -432,3 +432,381 @@ mod array_elem_push { super::execute(TEST_NAME, false).await } } +mod invalid_index_str { + const TEST_NAME: &str = "invalid_index_str"; + + /// Test tokenizing KCL. + #[test] + fn tokenize() { + super::tokenize(TEST_NAME) + } + + /// Test parsing KCL. + #[test] + fn parse() { + super::parse(TEST_NAME) + } + + /// Test that parsing and unparsing KCL produces the original KCL input. + #[test] + fn unparse() { + super::unparse(TEST_NAME) + } + + /// Test that KCL is executed correctly. + #[tokio::test(flavor = "multi_thread")] + async fn kcl_test_execute() { + super::execute(TEST_NAME, false).await + } +} +mod invalid_index_negative { + const TEST_NAME: &str = "invalid_index_negative"; + + /// Test tokenizing KCL. + #[test] + fn tokenize() { + super::tokenize(TEST_NAME) + } + + /// Test parsing KCL. + #[test] + fn parse() { + super::parse(TEST_NAME) + } + + /// Test that parsing and unparsing KCL produces the original KCL input. + #[test] + fn unparse() { + super::unparse(TEST_NAME) + } + + /// Test that KCL is executed correctly. + #[tokio::test(flavor = "multi_thread")] + async fn kcl_test_execute() { + super::execute(TEST_NAME, false).await + } +} +mod invalid_index_fractional { + const TEST_NAME: &str = "invalid_index_fractional"; + + /// Test tokenizing KCL. + #[test] + fn tokenize() { + super::tokenize(TEST_NAME) + } + + /// Test parsing KCL. + #[test] + fn parse() { + super::parse(TEST_NAME) + } + + /// Test that parsing and unparsing KCL produces the original KCL input. + #[test] + fn unparse() { + super::unparse(TEST_NAME) + } + + /// Test that KCL is executed correctly. + #[tokio::test(flavor = "multi_thread")] + async fn kcl_test_execute() { + super::execute(TEST_NAME, false).await + } +} +mod invalid_member_object { + const TEST_NAME: &str = "invalid_member_object"; + + /// Test tokenizing KCL. + #[test] + fn tokenize() { + super::tokenize(TEST_NAME) + } + + /// Test parsing KCL. + #[test] + fn parse() { + super::parse(TEST_NAME) + } + + /// Test that parsing and unparsing KCL produces the original KCL input. + #[test] + fn unparse() { + super::unparse(TEST_NAME) + } + + /// Test that KCL is executed correctly. + #[tokio::test(flavor = "multi_thread")] + async fn kcl_test_execute() { + super::execute(TEST_NAME, false).await + } +} +mod invalid_member_object_prop { + const TEST_NAME: &str = "invalid_member_object_prop"; + + /// Test tokenizing KCL. + #[test] + fn tokenize() { + super::tokenize(TEST_NAME) + } + + /// Test parsing KCL. + #[test] + fn parse() { + super::parse(TEST_NAME) + } + + /// Test that parsing and unparsing KCL produces the original KCL input. + #[test] + fn unparse() { + super::unparse(TEST_NAME) + } + + /// Test that KCL is executed correctly. + #[tokio::test(flavor = "multi_thread")] + async fn kcl_test_execute() { + super::execute(TEST_NAME, false).await + } +} +mod non_string_key_of_object { + const TEST_NAME: &str = "non_string_key_of_object"; + + /// Test tokenizing KCL. + #[test] + fn tokenize() { + super::tokenize(TEST_NAME) + } + + /// Test parsing KCL. + #[test] + fn parse() { + super::parse(TEST_NAME) + } + + /// Test that parsing and unparsing KCL produces the original KCL input. + #[test] + fn unparse() { + super::unparse(TEST_NAME) + } + + /// Test that KCL is executed correctly. + #[tokio::test(flavor = "multi_thread")] + async fn kcl_test_execute() { + super::execute(TEST_NAME, false).await + } +} +mod array_index_oob { + const TEST_NAME: &str = "array_index_oob"; + + /// Test tokenizing KCL. + #[test] + fn tokenize() { + super::tokenize(TEST_NAME) + } + + /// Test parsing KCL. + #[test] + fn parse() { + super::parse(TEST_NAME) + } + + /// Test that parsing and unparsing KCL produces the original KCL input. + #[test] + fn unparse() { + super::unparse(TEST_NAME) + } + + /// Test that KCL is executed correctly. + #[tokio::test(flavor = "multi_thread")] + async fn kcl_test_execute() { + super::execute(TEST_NAME, false).await + } +} +mod object_prop_not_found { + const TEST_NAME: &str = "object_prop_not_found"; + + /// Test tokenizing KCL. + #[test] + fn tokenize() { + super::tokenize(TEST_NAME) + } + + /// Test parsing KCL. + #[test] + fn parse() { + super::parse(TEST_NAME) + } + + /// Test that parsing and unparsing KCL produces the original KCL input. + #[test] + fn unparse() { + super::unparse(TEST_NAME) + } + + /// Test that KCL is executed correctly. + #[tokio::test(flavor = "multi_thread")] + async fn kcl_test_execute() { + super::execute(TEST_NAME, false).await + } +} +mod pipe_substitution_inside_function_called_from_pipeline { + const TEST_NAME: &str = "pipe_substitution_inside_function_called_from_pipeline"; + + /// Test tokenizing KCL. + #[test] + fn tokenize() { + super::tokenize(TEST_NAME) + } + + /// Test parsing KCL. + #[test] + fn parse() { + super::parse(TEST_NAME) + } + + /// Test that parsing and unparsing KCL produces the original KCL input. + #[test] + fn unparse() { + super::unparse(TEST_NAME) + } + + /// Test that KCL is executed correctly. + #[tokio::test(flavor = "multi_thread")] + async fn kcl_test_execute() { + super::execute(TEST_NAME, false).await + } +} +mod comparisons_multiple { + const TEST_NAME: &str = "comparisons_multiple"; + + /// Test tokenizing KCL. + #[test] + fn tokenize() { + super::tokenize(TEST_NAME) + } + + /// Test parsing KCL. + #[test] + fn parse() { + super::parse(TEST_NAME) + } + + /// Test that parsing and unparsing KCL produces the original KCL input. + #[test] + fn unparse() { + super::unparse(TEST_NAME) + } + + /// Test that KCL is executed correctly. + #[tokio::test(flavor = "multi_thread")] + async fn kcl_test_execute() { + super::execute(TEST_NAME, false).await + } +} +mod import_cycle1 { + const TEST_NAME: &str = "import_cycle1"; + + /// Test tokenizing KCL. + #[test] + fn tokenize() { + super::tokenize(TEST_NAME) + } + + /// Test parsing KCL. + #[test] + fn parse() { + super::parse(TEST_NAME) + } + + /// Test that parsing and unparsing KCL produces the original KCL input. + #[test] + fn unparse() { + super::unparse(TEST_NAME) + } + + /// Test that KCL is executed correctly. + #[tokio::test(flavor = "multi_thread")] + async fn kcl_test_execute() { + super::execute(TEST_NAME, false).await + } +} +mod import_constant { + const TEST_NAME: &str = "import_constant"; + + /// Test tokenizing KCL. + #[test] + fn tokenize() { + super::tokenize(TEST_NAME) + } + + /// Test parsing KCL. + #[test] + fn parse() { + super::parse(TEST_NAME) + } + + /// Test that parsing and unparsing KCL produces the original KCL input. + #[test] + fn unparse() { + super::unparse(TEST_NAME) + } + + /// Test that KCL is executed correctly. + #[tokio::test(flavor = "multi_thread")] + async fn kcl_test_execute() { + super::execute(TEST_NAME, false).await + } +} +mod import_side_effect { + const TEST_NAME: &str = "import_side_effect"; + + /// Test tokenizing KCL. + #[test] + fn tokenize() { + super::tokenize(TEST_NAME) + } + + /// Test parsing KCL. + #[test] + fn parse() { + super::parse(TEST_NAME) + } + + /// Test that parsing and unparsing KCL produces the original KCL input. + #[test] + fn unparse() { + super::unparse(TEST_NAME) + } + + /// Test that KCL is executed correctly. + #[tokio::test(flavor = "multi_thread")] + async fn kcl_test_execute() { + super::execute(TEST_NAME, false).await + } +} +mod array_elem_push_fail { + const TEST_NAME: &str = "array_elem_push_fail"; + + /// Test tokenizing KCL. + #[test] + fn tokenize() { + super::tokenize(TEST_NAME) + } + + /// Test parsing KCL. + #[test] + fn parse() { + super::parse(TEST_NAME) + } + + /// Test that parsing and unparsing KCL produces the original KCL input. + #[test] + fn unparse() { + super::unparse(TEST_NAME) + } + + /// Test that KCL is executed correctly. + #[tokio::test(flavor = "multi_thread")] + async fn kcl_test_execute() { + super::execute(TEST_NAME, false).await + } +} diff --git a/src/wasm-lib/kcl/tests/array_elem_push_fail/ast.snap b/src/wasm-lib/kcl/tests/array_elem_push_fail/ast.snap new file mode 100644 index 0000000000..3dbdee066d --- /dev/null +++ b/src/wasm-lib/kcl/tests/array_elem_push_fail/ast.snap @@ -0,0 +1,157 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of parsing array_elem_push_fail.kcl +snapshot_kind: text +--- +{ + "Ok": { + "body": [ + { + "declarations": [ + { + "end": 15, + "id": { + "end": 3, + "name": "arr", + "start": 0, + "type": "Identifier" + }, + "init": { + "elements": [ + { + "end": 8, + "raw": "1", + "start": 7, + "type": "Literal", + "type": "Literal", + "value": 1 + }, + { + "end": 11, + "raw": "2", + "start": 10, + "type": "Literal", + "type": "Literal", + "value": 2 + }, + { + "end": 14, + "raw": "3", + "start": 13, + "type": "Literal", + "type": "Literal", + "value": 3 + } + ], + "end": 15, + "start": 6, + "type": "ArrayExpression", + "type": "ArrayExpression" + }, + "start": 0, + "type": "VariableDeclarator" + } + ], + "end": 15, + "kind": "const", + "start": 0, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + }, + { + "declarations": [ + { + "end": 40, + "id": { + "end": 25, + "name": "pushedArr", + "start": 16, + "type": "Identifier" + }, + "init": { + "arguments": [ + { + "end": 36, + "name": "arr", + "start": 33, + "type": "Identifier", + "type": "Identifier" + }, + { + "end": 39, + "raw": "4", + "start": 38, + "type": "Literal", + "type": "Literal", + "value": 4 + } + ], + "callee": { + "end": 32, + "name": "push", + "start": 28, + "type": "Identifier" + }, + "end": 40, + "optional": false, + "start": 28, + "type": "CallExpression", + "type": "CallExpression" + }, + "start": 16, + "type": "VariableDeclarator" + } + ], + "end": 40, + "kind": "const", + "start": 16, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + }, + { + "declarations": [ + { + "end": 54, + "id": { + "end": 45, + "name": "fail", + "start": 41, + "type": "Identifier" + }, + "init": { + "computed": false, + "end": 54, + "object": { + "end": 51, + "name": "arr", + "start": 48, + "type": "Identifier", + "type": "Identifier" + }, + "property": { + "end": 53, + "raw": "3", + "start": 52, + "type": "Literal", + "type": "Literal", + "value": 3 + }, + "start": 48, + "type": "MemberExpression", + "type": "MemberExpression" + }, + "start": 41, + "type": "VariableDeclarator" + } + ], + "end": 54, + "kind": "const", + "start": 41, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + } + ], + "end": 55, + "start": 0 + } +} diff --git a/src/wasm-lib/kcl/tests/array_elem_push_fail/execution_error.snap b/src/wasm-lib/kcl/tests/array_elem_push_fail/execution_error.snap new file mode 100644 index 0000000000..f7a7694472 --- /dev/null +++ b/src/wasm-lib/kcl/tests/array_elem_push_fail/execution_error.snap @@ -0,0 +1,6 @@ +--- +source: kcl/src/simulation_tests.rs +description: Error from executing array_elem_push_fail.kcl +snapshot_kind: text +--- +undefined value: KclErrorDetails { source_ranges: [SourceRange([48, 54, 0])], message: "The array doesn't have any item at index 3" } diff --git a/src/wasm-lib/tests/executor/inputs/no_visuals/array_elem_push_fail.kcl b/src/wasm-lib/kcl/tests/array_elem_push_fail/input.kcl similarity index 100% rename from src/wasm-lib/tests/executor/inputs/no_visuals/array_elem_push_fail.kcl rename to src/wasm-lib/kcl/tests/array_elem_push_fail/input.kcl diff --git a/src/wasm-lib/kcl/tests/array_elem_push_fail/tokens.snap b/src/wasm-lib/kcl/tests/array_elem_push_fail/tokens.snap new file mode 100644 index 0000000000..267e2e6c6e --- /dev/null +++ b/src/wasm-lib/kcl/tests/array_elem_push_fail/tokens.snap @@ -0,0 +1,219 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of tokenizing array_elem_push_fail.kcl +snapshot_kind: text +--- +{ + "Ok": [ + { + "type": "word", + "start": 0, + "end": 3, + "value": "arr" + }, + { + "type": "whitespace", + "start": 3, + "end": 4, + "value": " " + }, + { + "type": "operator", + "start": 4, + "end": 5, + "value": "=" + }, + { + "type": "whitespace", + "start": 5, + "end": 6, + "value": " " + }, + { + "type": "brace", + "start": 6, + "end": 7, + "value": "[" + }, + { + "type": "number", + "start": 7, + "end": 8, + "value": "1" + }, + { + "type": "comma", + "start": 8, + "end": 9, + "value": "," + }, + { + "type": "whitespace", + "start": 9, + "end": 10, + "value": " " + }, + { + "type": "number", + "start": 10, + "end": 11, + "value": "2" + }, + { + "type": "comma", + "start": 11, + "end": 12, + "value": "," + }, + { + "type": "whitespace", + "start": 12, + "end": 13, + "value": " " + }, + { + "type": "number", + "start": 13, + "end": 14, + "value": "3" + }, + { + "type": "brace", + "start": 14, + "end": 15, + "value": "]" + }, + { + "type": "whitespace", + "start": 15, + "end": 16, + "value": "\n" + }, + { + "type": "word", + "start": 16, + "end": 25, + "value": "pushedArr" + }, + { + "type": "whitespace", + "start": 25, + "end": 26, + "value": " " + }, + { + "type": "operator", + "start": 26, + "end": 27, + "value": "=" + }, + { + "type": "whitespace", + "start": 27, + "end": 28, + "value": " " + }, + { + "type": "word", + "start": 28, + "end": 32, + "value": "push" + }, + { + "type": "brace", + "start": 32, + "end": 33, + "value": "(" + }, + { + "type": "word", + "start": 33, + "end": 36, + "value": "arr" + }, + { + "type": "comma", + "start": 36, + "end": 37, + "value": "," + }, + { + "type": "whitespace", + "start": 37, + "end": 38, + "value": " " + }, + { + "type": "number", + "start": 38, + "end": 39, + "value": "4" + }, + { + "type": "brace", + "start": 39, + "end": 40, + "value": ")" + }, + { + "type": "whitespace", + "start": 40, + "end": 41, + "value": "\n" + }, + { + "type": "word", + "start": 41, + "end": 45, + "value": "fail" + }, + { + "type": "whitespace", + "start": 45, + "end": 46, + "value": " " + }, + { + "type": "operator", + "start": 46, + "end": 47, + "value": "=" + }, + { + "type": "whitespace", + "start": 47, + "end": 48, + "value": " " + }, + { + "type": "word", + "start": 48, + "end": 51, + "value": "arr" + }, + { + "type": "brace", + "start": 51, + "end": 52, + "value": "[" + }, + { + "type": "number", + "start": 52, + "end": 53, + "value": "3" + }, + { + "type": "brace", + "start": 53, + "end": 54, + "value": "]" + }, + { + "type": "whitespace", + "start": 54, + "end": 55, + "value": "\n" + } + ] +} diff --git a/src/wasm-lib/kcl/tests/array_index_oob/ast.snap b/src/wasm-lib/kcl/tests/array_index_oob/ast.snap new file mode 100644 index 0000000000..5ba9f2eef9 --- /dev/null +++ b/src/wasm-lib/kcl/tests/array_index_oob/ast.snap @@ -0,0 +1,82 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of parsing array_index_oob.kcl +snapshot_kind: text +--- +{ + "Ok": { + "body": [ + { + "declarations": [ + { + "end": 8, + "id": { + "end": 3, + "name": "arr", + "start": 0, + "type": "Identifier" + }, + "init": { + "elements": [], + "end": 8, + "start": 6, + "type": "ArrayExpression", + "type": "ArrayExpression" + }, + "start": 0, + "type": "VariableDeclarator" + } + ], + "end": 8, + "kind": "const", + "start": 0, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + }, + { + "declarations": [ + { + "end": 19, + "id": { + "end": 10, + "name": "x", + "start": 9, + "type": "Identifier" + }, + "init": { + "computed": false, + "end": 19, + "object": { + "end": 16, + "name": "arr", + "start": 13, + "type": "Identifier", + "type": "Identifier" + }, + "property": { + "end": 18, + "raw": "0", + "start": 17, + "type": "Literal", + "type": "Literal", + "value": 0 + }, + "start": 13, + "type": "MemberExpression", + "type": "MemberExpression" + }, + "start": 9, + "type": "VariableDeclarator" + } + ], + "end": 19, + "kind": "const", + "start": 9, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + } + ], + "end": 20, + "start": 0 + } +} diff --git a/src/wasm-lib/kcl/tests/array_index_oob/execution_error.snap b/src/wasm-lib/kcl/tests/array_index_oob/execution_error.snap new file mode 100644 index 0000000000..525b9c860d --- /dev/null +++ b/src/wasm-lib/kcl/tests/array_index_oob/execution_error.snap @@ -0,0 +1,6 @@ +--- +source: kcl/src/simulation_tests.rs +description: Error from executing array_index_oob.kcl +snapshot_kind: text +--- +undefined value: KclErrorDetails { source_ranges: [SourceRange([13, 19, 0])], message: "The array doesn't have any item at index 0" } diff --git a/src/wasm-lib/kcl/tests/array_index_oob/input.kcl b/src/wasm-lib/kcl/tests/array_index_oob/input.kcl new file mode 100644 index 0000000000..53a30946bf --- /dev/null +++ b/src/wasm-lib/kcl/tests/array_index_oob/input.kcl @@ -0,0 +1,2 @@ +arr = [] +x = arr[0] diff --git a/src/wasm-lib/kcl/tests/array_index_oob/tokens.snap b/src/wasm-lib/kcl/tests/array_index_oob/tokens.snap new file mode 100644 index 0000000000..d394d812a0 --- /dev/null +++ b/src/wasm-lib/kcl/tests/array_index_oob/tokens.snap @@ -0,0 +1,105 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of tokenizing array_index_oob.kcl +snapshot_kind: text +--- +{ + "Ok": [ + { + "type": "word", + "start": 0, + "end": 3, + "value": "arr" + }, + { + "type": "whitespace", + "start": 3, + "end": 4, + "value": " " + }, + { + "type": "operator", + "start": 4, + "end": 5, + "value": "=" + }, + { + "type": "whitespace", + "start": 5, + "end": 6, + "value": " " + }, + { + "type": "brace", + "start": 6, + "end": 7, + "value": "[" + }, + { + "type": "brace", + "start": 7, + "end": 8, + "value": "]" + }, + { + "type": "whitespace", + "start": 8, + "end": 9, + "value": "\n" + }, + { + "type": "word", + "start": 9, + "end": 10, + "value": "x" + }, + { + "type": "whitespace", + "start": 10, + "end": 11, + "value": " " + }, + { + "type": "operator", + "start": 11, + "end": 12, + "value": "=" + }, + { + "type": "whitespace", + "start": 12, + "end": 13, + "value": " " + }, + { + "type": "word", + "start": 13, + "end": 16, + "value": "arr" + }, + { + "type": "brace", + "start": 16, + "end": 17, + "value": "[" + }, + { + "type": "number", + "start": 17, + "end": 18, + "value": "0" + }, + { + "type": "brace", + "start": 18, + "end": 19, + "value": "]" + }, + { + "type": "whitespace", + "start": 19, + "end": 20, + "value": "\n" + } + ] +} diff --git a/src/wasm-lib/kcl/tests/comparisons_multiple/ast.snap b/src/wasm-lib/kcl/tests/comparisons_multiple/ast.snap new file mode 100644 index 0000000000..b8c8de1895 --- /dev/null +++ b/src/wasm-lib/kcl/tests/comparisons_multiple/ast.snap @@ -0,0 +1,80 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of parsing comparisons_multiple.kcl +snapshot_kind: text +--- +{ + "Ok": { + "body": [ + { + "end": 46, + "expression": { + "arguments": [ + { + "end": 18, + "left": { + "end": 13, + "left": { + "end": 8, + "raw": "3", + "start": 7, + "type": "Literal", + "type": "Literal", + "value": 3 + }, + "operator": "==", + "right": { + "end": 13, + "raw": "3", + "start": 12, + "type": "Literal", + "type": "Literal", + "value": 3 + }, + "start": 7, + "type": "BinaryExpression", + "type": "BinaryExpression" + }, + "operator": "==", + "right": { + "end": 18, + "raw": "3", + "start": 17, + "type": "Literal", + "type": "Literal", + "value": 3 + }, + "start": 7, + "type": "BinaryExpression", + "type": "BinaryExpression" + }, + { + "end": 45, + "raw": "\"this should not compile\"", + "start": 20, + "type": "Literal", + "type": "Literal", + "value": "this should not compile" + } + ], + "callee": { + "end": 6, + "name": "assert", + "start": 0, + "type": "Identifier" + }, + "end": 46, + "optional": false, + "start": 0, + "type": "CallExpression", + "type": "CallExpression" + }, + "start": 0, + "type": "ExpressionStatement", + "type": "ExpressionStatement" + } + ], + "end": 47, + "start": 0 + } +} diff --git a/src/wasm-lib/kcl/tests/comparisons_multiple/execution_error.snap b/src/wasm-lib/kcl/tests/comparisons_multiple/execution_error.snap new file mode 100644 index 0000000000..2a7bc6941d --- /dev/null +++ b/src/wasm-lib/kcl/tests/comparisons_multiple/execution_error.snap @@ -0,0 +1,6 @@ +--- +source: kcl/src/simulation_tests.rs +description: Error from executing comparisons_multiple.kcl +snapshot_kind: text +--- +semantic: KclErrorDetails { source_ranges: [SourceRange([7, 13, 0])], message: "Expected a number, but found a boolean (true/false value)" } diff --git a/src/wasm-lib/tests/executor/inputs/no_visuals/comparisons_multiple.kcl b/src/wasm-lib/kcl/tests/comparisons_multiple/input.kcl similarity index 100% rename from src/wasm-lib/tests/executor/inputs/no_visuals/comparisons_multiple.kcl rename to src/wasm-lib/kcl/tests/comparisons_multiple/input.kcl diff --git a/src/wasm-lib/kcl/tests/comparisons_multiple/tokens.snap b/src/wasm-lib/kcl/tests/comparisons_multiple/tokens.snap new file mode 100644 index 0000000000..c6d3736adf --- /dev/null +++ b/src/wasm-lib/kcl/tests/comparisons_multiple/tokens.snap @@ -0,0 +1,105 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of tokenizing comparisons_multiple.kcl +snapshot_kind: text +--- +{ + "Ok": [ + { + "type": "word", + "start": 0, + "end": 6, + "value": "assert" + }, + { + "type": "brace", + "start": 6, + "end": 7, + "value": "(" + }, + { + "type": "number", + "start": 7, + "end": 8, + "value": "3" + }, + { + "type": "whitespace", + "start": 8, + "end": 9, + "value": " " + }, + { + "type": "operator", + "start": 9, + "end": 11, + "value": "==" + }, + { + "type": "whitespace", + "start": 11, + "end": 12, + "value": " " + }, + { + "type": "number", + "start": 12, + "end": 13, + "value": "3" + }, + { + "type": "whitespace", + "start": 13, + "end": 14, + "value": " " + }, + { + "type": "operator", + "start": 14, + "end": 16, + "value": "==" + }, + { + "type": "whitespace", + "start": 16, + "end": 17, + "value": " " + }, + { + "type": "number", + "start": 17, + "end": 18, + "value": "3" + }, + { + "type": "comma", + "start": 18, + "end": 19, + "value": "," + }, + { + "type": "whitespace", + "start": 19, + "end": 20, + "value": " " + }, + { + "type": "string", + "start": 20, + "end": 45, + "value": "\"this should not compile\"" + }, + { + "type": "brace", + "start": 45, + "end": 46, + "value": ")" + }, + { + "type": "whitespace", + "start": 46, + "end": 47, + "value": "\n" + } + ] +} diff --git a/src/wasm-lib/kcl/tests/import_constant/ast.snap b/src/wasm-lib/kcl/tests/import_constant/ast.snap new file mode 100644 index 0000000000..27cfa258e2 --- /dev/null +++ b/src/wasm-lib/kcl/tests/import_constant/ast.snap @@ -0,0 +1,35 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of parsing import_constant.kcl +snapshot_kind: text +--- +{ + "Ok": { + "body": [ + { + "end": 39, + "items": [ + { + "alias": null, + "end": 12, + "name": { + "end": 12, + "name": "three", + "start": 7, + "type": "Identifier" + }, + "start": 7, + "type": "ImportItem" + } + ], + "path": "export_constant.kcl", + "raw_path": "\"export_constant.kcl\"", + "start": 0, + "type": "ImportStatement", + "type": "ImportStatement" + } + ], + "end": 40, + "start": 0 + } +} diff --git a/src/wasm-lib/kcl/tests/import_constant/execution_error.snap b/src/wasm-lib/kcl/tests/import_constant/execution_error.snap new file mode 100644 index 0000000000..ecc0d57a48 --- /dev/null +++ b/src/wasm-lib/kcl/tests/import_constant/execution_error.snap @@ -0,0 +1,6 @@ +--- +source: kcl/src/simulation_tests.rs +description: Error from executing import_constant.kcl +snapshot_kind: text +--- +engine: KclErrorDetails { source_ranges: [SourceRange([0, 39, 0])], message: "Failed to read file `export_constant.kcl`: No such file or directory (os error 2)" } diff --git a/src/wasm-lib/tests/executor/inputs/no_visuals/import_constant.kcl b/src/wasm-lib/kcl/tests/import_constant/input.kcl similarity index 100% rename from src/wasm-lib/tests/executor/inputs/no_visuals/import_constant.kcl rename to src/wasm-lib/kcl/tests/import_constant/input.kcl diff --git a/src/wasm-lib/kcl/tests/import_constant/tokens.snap b/src/wasm-lib/kcl/tests/import_constant/tokens.snap new file mode 100644 index 0000000000..f268f4e614 --- /dev/null +++ b/src/wasm-lib/kcl/tests/import_constant/tokens.snap @@ -0,0 +1,57 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of tokenizing import_constant.kcl +snapshot_kind: text +--- +{ + "Ok": [ + { + "type": "keyword", + "start": 0, + "end": 6, + "value": "import" + }, + { + "type": "whitespace", + "start": 6, + "end": 7, + "value": " " + }, + { + "type": "word", + "start": 7, + "end": 12, + "value": "three" + }, + { + "type": "whitespace", + "start": 12, + "end": 13, + "value": " " + }, + { + "type": "word", + "start": 13, + "end": 17, + "value": "from" + }, + { + "type": "whitespace", + "start": 17, + "end": 18, + "value": " " + }, + { + "type": "string", + "start": 18, + "end": 39, + "value": "\"export_constant.kcl\"" + }, + { + "type": "whitespace", + "start": 39, + "end": 40, + "value": "\n" + } + ] +} diff --git a/src/wasm-lib/kcl/tests/import_cycle1/ast.snap b/src/wasm-lib/kcl/tests/import_cycle1/ast.snap new file mode 100644 index 0000000000..e1e478225b --- /dev/null +++ b/src/wasm-lib/kcl/tests/import_cycle1/ast.snap @@ -0,0 +1,119 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of parsing import_cycle1.kcl +snapshot_kind: text +--- +{ + "Ok": { + "body": [ + { + "end": 35, + "items": [ + { + "alias": null, + "end": 10, + "name": { + "end": 10, + "name": "two", + "start": 7, + "type": "Identifier" + }, + "start": 7, + "type": "ImportItem" + } + ], + "path": "import_cycle2.kcl", + "raw_path": "\"import_cycle2.kcl\"", + "start": 0, + "type": "ImportStatement", + "type": "ImportStatement" + }, + { + "declarations": [ + { + "end": 81, + "id": { + "end": 50, + "name": "one", + "start": 47, + "type": "Identifier" + }, + "init": { + "body": { + "body": [ + { + "argument": { + "end": 79, + "left": { + "arguments": [], + "callee": { + "end": 73, + "name": "two", + "start": 70, + "type": "Identifier" + }, + "end": 75, + "optional": false, + "start": 70, + "type": "CallExpression", + "type": "CallExpression" + }, + "operator": "-", + "right": { + "end": 79, + "raw": "1", + "start": 78, + "type": "Literal", + "type": "Literal", + "value": 1 + }, + "start": 70, + "type": "BinaryExpression", + "type": "BinaryExpression" + }, + "end": 79, + "start": 63, + "type": "ReturnStatement", + "type": "ReturnStatement" + } + ], + "end": 81, + "start": 59 + }, + "end": 81, + "params": [], + "start": 53, + "type": "FunctionExpression", + "type": "FunctionExpression" + }, + "start": 47, + "type": "VariableDeclarator" + } + ], + "end": 81, + "kind": "fn", + "start": 37, + "type": "VariableDeclaration", + "type": "VariableDeclaration", + "visibility": "export" + } + ], + "end": 82, + "nonCodeMeta": { + "nonCodeNodes": { + "0": [ + { + "end": 37, + "start": 35, + "type": "NonCodeNode", + "value": { + "type": "newLine" + } + } + ] + }, + "startNodes": [] + }, + "start": 0 + } +} diff --git a/src/wasm-lib/kcl/tests/import_cycle1/execution_error.snap b/src/wasm-lib/kcl/tests/import_cycle1/execution_error.snap new file mode 100644 index 0000000000..26535746a0 --- /dev/null +++ b/src/wasm-lib/kcl/tests/import_cycle1/execution_error.snap @@ -0,0 +1,6 @@ +--- +source: kcl/src/simulation_tests.rs +description: Error from executing import_cycle1.kcl +snapshot_kind: text +--- +engine: KclErrorDetails { source_ranges: [SourceRange([0, 35, 0])], message: "Failed to read file `import_cycle2.kcl`: No such file or directory (os error 2)" } diff --git a/src/wasm-lib/kcl/tests/import_cycle1/input.kcl b/src/wasm-lib/kcl/tests/import_cycle1/input.kcl new file mode 100644 index 0000000000..9a92ffbfa7 --- /dev/null +++ b/src/wasm-lib/kcl/tests/import_cycle1/input.kcl @@ -0,0 +1,5 @@ +import two from "import_cycle2.kcl" + +export fn one = () => { + return two() - 1 +} diff --git a/src/wasm-lib/kcl/tests/import_cycle1/tokens.snap b/src/wasm-lib/kcl/tests/import_cycle1/tokens.snap new file mode 100644 index 0000000000..6443cf8997 --- /dev/null +++ b/src/wasm-lib/kcl/tests/import_cycle1/tokens.snap @@ -0,0 +1,219 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of tokenizing import_cycle1.kcl +snapshot_kind: text +--- +{ + "Ok": [ + { + "type": "keyword", + "start": 0, + "end": 6, + "value": "import" + }, + { + "type": "whitespace", + "start": 6, + "end": 7, + "value": " " + }, + { + "type": "word", + "start": 7, + "end": 10, + "value": "two" + }, + { + "type": "whitespace", + "start": 10, + "end": 11, + "value": " " + }, + { + "type": "word", + "start": 11, + "end": 15, + "value": "from" + }, + { + "type": "whitespace", + "start": 15, + "end": 16, + "value": " " + }, + { + "type": "string", + "start": 16, + "end": 35, + "value": "\"import_cycle2.kcl\"" + }, + { + "type": "whitespace", + "start": 35, + "end": 37, + "value": "\n\n" + }, + { + "type": "keyword", + "start": 37, + "end": 43, + "value": "export" + }, + { + "type": "whitespace", + "start": 43, + "end": 44, + "value": " " + }, + { + "type": "keyword", + "start": 44, + "end": 46, + "value": "fn" + }, + { + "type": "whitespace", + "start": 46, + "end": 47, + "value": " " + }, + { + "type": "word", + "start": 47, + "end": 50, + "value": "one" + }, + { + "type": "whitespace", + "start": 50, + "end": 51, + "value": " " + }, + { + "type": "operator", + "start": 51, + "end": 52, + "value": "=" + }, + { + "type": "whitespace", + "start": 52, + "end": 53, + "value": " " + }, + { + "type": "brace", + "start": 53, + "end": 54, + "value": "(" + }, + { + "type": "brace", + "start": 54, + "end": 55, + "value": ")" + }, + { + "type": "whitespace", + "start": 55, + "end": 56, + "value": " " + }, + { + "type": "operator", + "start": 56, + "end": 58, + "value": "=>" + }, + { + "type": "whitespace", + "start": 58, + "end": 59, + "value": " " + }, + { + "type": "brace", + "start": 59, + "end": 60, + "value": "{" + }, + { + "type": "whitespace", + "start": 60, + "end": 63, + "value": "\n " + }, + { + "type": "keyword", + "start": 63, + "end": 69, + "value": "return" + }, + { + "type": "whitespace", + "start": 69, + "end": 70, + "value": " " + }, + { + "type": "word", + "start": 70, + "end": 73, + "value": "two" + }, + { + "type": "brace", + "start": 73, + "end": 74, + "value": "(" + }, + { + "type": "brace", + "start": 74, + "end": 75, + "value": ")" + }, + { + "type": "whitespace", + "start": 75, + "end": 76, + "value": " " + }, + { + "type": "operator", + "start": 76, + "end": 77, + "value": "-" + }, + { + "type": "whitespace", + "start": 77, + "end": 78, + "value": " " + }, + { + "type": "number", + "start": 78, + "end": 79, + "value": "1" + }, + { + "type": "whitespace", + "start": 79, + "end": 80, + "value": "\n" + }, + { + "type": "brace", + "start": 80, + "end": 81, + "value": "}" + }, + { + "type": "whitespace", + "start": 81, + "end": 82, + "value": "\n" + } + ] +} diff --git a/src/wasm-lib/tests/executor/inputs/no_visuals/import_from_other_directory.kcl b/src/wasm-lib/kcl/tests/import_from_other_directory/input.kcl similarity index 100% rename from src/wasm-lib/tests/executor/inputs/no_visuals/import_from_other_directory.kcl rename to src/wasm-lib/kcl/tests/import_from_other_directory/input.kcl diff --git a/src/wasm-lib/kcl/tests/import_side_effect/ast.snap b/src/wasm-lib/kcl/tests/import_side_effect/ast.snap new file mode 100644 index 0000000000..c9f0fc679d --- /dev/null +++ b/src/wasm-lib/kcl/tests/import_side_effect/ast.snap @@ -0,0 +1,35 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of parsing import_side_effect.kcl +snapshot_kind: text +--- +{ + "Ok": { + "body": [ + { + "end": 40, + "items": [ + { + "alias": null, + "end": 10, + "name": { + "end": 10, + "name": "foo", + "start": 7, + "type": "Identifier" + }, + "start": 7, + "type": "ImportItem" + } + ], + "path": "export_side_effect.kcl", + "raw_path": "\"export_side_effect.kcl\"", + "start": 0, + "type": "ImportStatement", + "type": "ImportStatement" + } + ], + "end": 41, + "start": 0 + } +} diff --git a/src/wasm-lib/kcl/tests/import_side_effect/execution_error.snap b/src/wasm-lib/kcl/tests/import_side_effect/execution_error.snap new file mode 100644 index 0000000000..02879b1b89 --- /dev/null +++ b/src/wasm-lib/kcl/tests/import_side_effect/execution_error.snap @@ -0,0 +1,6 @@ +--- +source: kcl/src/simulation_tests.rs +description: Error from executing import_side_effect.kcl +snapshot_kind: text +--- +engine: KclErrorDetails { source_ranges: [SourceRange([0, 40, 0])], message: "Failed to read file `export_side_effect.kcl`: No such file or directory (os error 2)" } diff --git a/src/wasm-lib/tests/executor/inputs/no_visuals/import_side_effect.kcl b/src/wasm-lib/kcl/tests/import_side_effect/input.kcl similarity index 100% rename from src/wasm-lib/tests/executor/inputs/no_visuals/import_side_effect.kcl rename to src/wasm-lib/kcl/tests/import_side_effect/input.kcl diff --git a/src/wasm-lib/kcl/tests/import_side_effect/tokens.snap b/src/wasm-lib/kcl/tests/import_side_effect/tokens.snap new file mode 100644 index 0000000000..ebb7d45073 --- /dev/null +++ b/src/wasm-lib/kcl/tests/import_side_effect/tokens.snap @@ -0,0 +1,57 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of tokenizing import_side_effect.kcl +snapshot_kind: text +--- +{ + "Ok": [ + { + "type": "keyword", + "start": 0, + "end": 6, + "value": "import" + }, + { + "type": "whitespace", + "start": 6, + "end": 7, + "value": " " + }, + { + "type": "word", + "start": 7, + "end": 10, + "value": "foo" + }, + { + "type": "whitespace", + "start": 10, + "end": 11, + "value": " " + }, + { + "type": "word", + "start": 11, + "end": 15, + "value": "from" + }, + { + "type": "whitespace", + "start": 15, + "end": 16, + "value": " " + }, + { + "type": "string", + "start": 16, + "end": 40, + "value": "\"export_side_effect.kcl\"" + }, + { + "type": "whitespace", + "start": 40, + "end": 41, + "value": "\n" + } + ] +} diff --git a/src/wasm-lib/kcl/tests/invalid_index_fractional/ast.snap b/src/wasm-lib/kcl/tests/invalid_index_fractional/ast.snap new file mode 100644 index 0000000000..da28302847 --- /dev/null +++ b/src/wasm-lib/kcl/tests/invalid_index_fractional/ast.snap @@ -0,0 +1,107 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of parsing invalid_index_fractional.kcl +snapshot_kind: text +--- +{ + "Ok": { + "body": [ + { + "declarations": [ + { + "end": 15, + "id": { + "end": 3, + "name": "arr", + "start": 0, + "type": "Identifier" + }, + "init": { + "elements": [ + { + "end": 8, + "raw": "1", + "start": 7, + "type": "Literal", + "type": "Literal", + "value": 1 + }, + { + "end": 11, + "raw": "2", + "start": 10, + "type": "Literal", + "type": "Literal", + "value": 2 + }, + { + "end": 14, + "raw": "3", + "start": 13, + "type": "Literal", + "type": "Literal", + "value": 3 + } + ], + "end": 15, + "start": 6, + "type": "ArrayExpression", + "type": "ArrayExpression" + }, + "start": 0, + "type": "VariableDeclarator" + } + ], + "end": 15, + "kind": "const", + "start": 0, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + }, + { + "declarations": [ + { + "end": 28, + "id": { + "end": 17, + "name": "x", + "start": 16, + "type": "Identifier" + }, + "init": { + "computed": false, + "end": 28, + "object": { + "end": 23, + "name": "arr", + "start": 20, + "type": "Identifier", + "type": "Identifier" + }, + "property": { + "end": 27, + "raw": "1.2", + "start": 24, + "type": "Literal", + "type": "Literal", + "value": 1.2 + }, + "start": 20, + "type": "MemberExpression", + "type": "MemberExpression" + }, + "start": 16, + "type": "VariableDeclarator" + } + ], + "end": 28, + "kind": "const", + "start": 16, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + } + ], + "end": 29, + "start": 0 + } +} diff --git a/src/wasm-lib/kcl/tests/invalid_index_fractional/execution_error.snap b/src/wasm-lib/kcl/tests/invalid_index_fractional/execution_error.snap new file mode 100644 index 0000000000..955ba0223f --- /dev/null +++ b/src/wasm-lib/kcl/tests/invalid_index_fractional/execution_error.snap @@ -0,0 +1,6 @@ +--- +source: kcl/src/simulation_tests.rs +description: Error from executing invalid_index_fractional.kcl +snapshot_kind: text +--- +semantic: KclErrorDetails { source_ranges: [SourceRange([20, 28, 0])], message: "Only strings or ints (>= 0) can be properties/indexes" } diff --git a/src/wasm-lib/kcl/tests/invalid_index_fractional/input.kcl b/src/wasm-lib/kcl/tests/invalid_index_fractional/input.kcl new file mode 100644 index 0000000000..4f2a3483e0 --- /dev/null +++ b/src/wasm-lib/kcl/tests/invalid_index_fractional/input.kcl @@ -0,0 +1,2 @@ +arr = [1, 2, 3] +x = arr[1.2] diff --git a/src/wasm-lib/kcl/tests/invalid_index_fractional/tokens.snap b/src/wasm-lib/kcl/tests/invalid_index_fractional/tokens.snap new file mode 100644 index 0000000000..20cf06013b --- /dev/null +++ b/src/wasm-lib/kcl/tests/invalid_index_fractional/tokens.snap @@ -0,0 +1,147 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of tokenizing invalid_index_fractional.kcl +snapshot_kind: text +--- +{ + "Ok": [ + { + "type": "word", + "start": 0, + "end": 3, + "value": "arr" + }, + { + "type": "whitespace", + "start": 3, + "end": 4, + "value": " " + }, + { + "type": "operator", + "start": 4, + "end": 5, + "value": "=" + }, + { + "type": "whitespace", + "start": 5, + "end": 6, + "value": " " + }, + { + "type": "brace", + "start": 6, + "end": 7, + "value": "[" + }, + { + "type": "number", + "start": 7, + "end": 8, + "value": "1" + }, + { + "type": "comma", + "start": 8, + "end": 9, + "value": "," + }, + { + "type": "whitespace", + "start": 9, + "end": 10, + "value": " " + }, + { + "type": "number", + "start": 10, + "end": 11, + "value": "2" + }, + { + "type": "comma", + "start": 11, + "end": 12, + "value": "," + }, + { + "type": "whitespace", + "start": 12, + "end": 13, + "value": " " + }, + { + "type": "number", + "start": 13, + "end": 14, + "value": "3" + }, + { + "type": "brace", + "start": 14, + "end": 15, + "value": "]" + }, + { + "type": "whitespace", + "start": 15, + "end": 16, + "value": "\n" + }, + { + "type": "word", + "start": 16, + "end": 17, + "value": "x" + }, + { + "type": "whitespace", + "start": 17, + "end": 18, + "value": " " + }, + { + "type": "operator", + "start": 18, + "end": 19, + "value": "=" + }, + { + "type": "whitespace", + "start": 19, + "end": 20, + "value": " " + }, + { + "type": "word", + "start": 20, + "end": 23, + "value": "arr" + }, + { + "type": "brace", + "start": 23, + "end": 24, + "value": "[" + }, + { + "type": "number", + "start": 24, + "end": 27, + "value": "1.2" + }, + { + "type": "brace", + "start": 27, + "end": 28, + "value": "]" + }, + { + "type": "whitespace", + "start": 28, + "end": 29, + "value": "\n" + } + ] +} diff --git a/src/wasm-lib/kcl/tests/invalid_index_negative/ast.snap b/src/wasm-lib/kcl/tests/invalid_index_negative/ast.snap new file mode 100644 index 0000000000..228c992792 --- /dev/null +++ b/src/wasm-lib/kcl/tests/invalid_index_negative/ast.snap @@ -0,0 +1,141 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of parsing invalid_index_negative.kcl +snapshot_kind: text +--- +{ + "Ok": { + "body": [ + { + "declarations": [ + { + "end": 15, + "id": { + "end": 3, + "name": "arr", + "start": 0, + "type": "Identifier" + }, + "init": { + "elements": [ + { + "end": 8, + "raw": "1", + "start": 7, + "type": "Literal", + "type": "Literal", + "value": 1 + }, + { + "end": 11, + "raw": "2", + "start": 10, + "type": "Literal", + "type": "Literal", + "value": 2 + }, + { + "end": 14, + "raw": "3", + "start": 13, + "type": "Literal", + "type": "Literal", + "value": 3 + } + ], + "end": 15, + "start": 6, + "type": "ArrayExpression", + "type": "ArrayExpression" + }, + "start": 0, + "type": "VariableDeclarator" + } + ], + "end": 15, + "kind": "const", + "start": 0, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + }, + { + "declarations": [ + { + "end": 22, + "id": { + "end": 17, + "name": "i", + "start": 16, + "type": "Identifier" + }, + "init": { + "argument": { + "end": 22, + "raw": "1", + "start": 21, + "type": "Literal", + "type": "Literal", + "value": 1 + }, + "end": 22, + "operator": "-", + "start": 20, + "type": "UnaryExpression", + "type": "UnaryExpression" + }, + "start": 16, + "type": "VariableDeclarator" + } + ], + "end": 22, + "kind": "const", + "start": 16, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + }, + { + "declarations": [ + { + "end": 33, + "id": { + "end": 24, + "name": "x", + "start": 23, + "type": "Identifier" + }, + "init": { + "computed": true, + "end": 33, + "object": { + "end": 30, + "name": "arr", + "start": 27, + "type": "Identifier", + "type": "Identifier" + }, + "property": { + "end": 32, + "name": "i", + "start": 31, + "type": "Identifier", + "type": "Identifier" + }, + "start": 27, + "type": "MemberExpression", + "type": "MemberExpression" + }, + "start": 23, + "type": "VariableDeclarator" + } + ], + "end": 33, + "kind": "const", + "start": 23, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + } + ], + "end": 34, + "start": 0 + } +} diff --git a/src/wasm-lib/kcl/tests/invalid_index_negative/execution_error.snap b/src/wasm-lib/kcl/tests/invalid_index_negative/execution_error.snap new file mode 100644 index 0000000000..516c9414f4 --- /dev/null +++ b/src/wasm-lib/kcl/tests/invalid_index_negative/execution_error.snap @@ -0,0 +1,6 @@ +--- +source: kcl/src/simulation_tests.rs +description: Error from executing invalid_index_negative.kcl +snapshot_kind: text +--- +semantic: KclErrorDetails { source_ranges: [SourceRange([27, 33, 0])], message: "'-1' is negative, so you can't index an array with it" } diff --git a/src/wasm-lib/kcl/tests/invalid_index_negative/input.kcl b/src/wasm-lib/kcl/tests/invalid_index_negative/input.kcl new file mode 100644 index 0000000000..457374509d --- /dev/null +++ b/src/wasm-lib/kcl/tests/invalid_index_negative/input.kcl @@ -0,0 +1,3 @@ +arr = [1, 2, 3] +i = -1 +x = arr[i] diff --git a/src/wasm-lib/kcl/tests/invalid_index_negative/tokens.snap b/src/wasm-lib/kcl/tests/invalid_index_negative/tokens.snap new file mode 100644 index 0000000000..9a3bdc823e --- /dev/null +++ b/src/wasm-lib/kcl/tests/invalid_index_negative/tokens.snap @@ -0,0 +1,189 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of tokenizing invalid_index_negative.kcl +snapshot_kind: text +--- +{ + "Ok": [ + { + "type": "word", + "start": 0, + "end": 3, + "value": "arr" + }, + { + "type": "whitespace", + "start": 3, + "end": 4, + "value": " " + }, + { + "type": "operator", + "start": 4, + "end": 5, + "value": "=" + }, + { + "type": "whitespace", + "start": 5, + "end": 6, + "value": " " + }, + { + "type": "brace", + "start": 6, + "end": 7, + "value": "[" + }, + { + "type": "number", + "start": 7, + "end": 8, + "value": "1" + }, + { + "type": "comma", + "start": 8, + "end": 9, + "value": "," + }, + { + "type": "whitespace", + "start": 9, + "end": 10, + "value": " " + }, + { + "type": "number", + "start": 10, + "end": 11, + "value": "2" + }, + { + "type": "comma", + "start": 11, + "end": 12, + "value": "," + }, + { + "type": "whitespace", + "start": 12, + "end": 13, + "value": " " + }, + { + "type": "number", + "start": 13, + "end": 14, + "value": "3" + }, + { + "type": "brace", + "start": 14, + "end": 15, + "value": "]" + }, + { + "type": "whitespace", + "start": 15, + "end": 16, + "value": "\n" + }, + { + "type": "word", + "start": 16, + "end": 17, + "value": "i" + }, + { + "type": "whitespace", + "start": 17, + "end": 18, + "value": " " + }, + { + "type": "operator", + "start": 18, + "end": 19, + "value": "=" + }, + { + "type": "whitespace", + "start": 19, + "end": 20, + "value": " " + }, + { + "type": "operator", + "start": 20, + "end": 21, + "value": "-" + }, + { + "type": "number", + "start": 21, + "end": 22, + "value": "1" + }, + { + "type": "whitespace", + "start": 22, + "end": 23, + "value": "\n" + }, + { + "type": "word", + "start": 23, + "end": 24, + "value": "x" + }, + { + "type": "whitespace", + "start": 24, + "end": 25, + "value": " " + }, + { + "type": "operator", + "start": 25, + "end": 26, + "value": "=" + }, + { + "type": "whitespace", + "start": 26, + "end": 27, + "value": " " + }, + { + "type": "word", + "start": 27, + "end": 30, + "value": "arr" + }, + { + "type": "brace", + "start": 30, + "end": 31, + "value": "[" + }, + { + "type": "word", + "start": 31, + "end": 32, + "value": "i" + }, + { + "type": "brace", + "start": 32, + "end": 33, + "value": "]" + }, + { + "type": "whitespace", + "start": 33, + "end": 34, + "value": "\n" + } + ] +} diff --git a/src/wasm-lib/kcl/tests/invalid_index_str/ast.snap b/src/wasm-lib/kcl/tests/invalid_index_str/ast.snap new file mode 100644 index 0000000000..64b43737c5 --- /dev/null +++ b/src/wasm-lib/kcl/tests/invalid_index_str/ast.snap @@ -0,0 +1,107 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of parsing invalid_index_str.kcl +snapshot_kind: text +--- +{ + "Ok": { + "body": [ + { + "declarations": [ + { + "end": 15, + "id": { + "end": 3, + "name": "arr", + "start": 0, + "type": "Identifier" + }, + "init": { + "elements": [ + { + "end": 8, + "raw": "1", + "start": 7, + "type": "Literal", + "type": "Literal", + "value": 1 + }, + { + "end": 11, + "raw": "2", + "start": 10, + "type": "Literal", + "type": "Literal", + "value": 2 + }, + { + "end": 14, + "raw": "3", + "start": 13, + "type": "Literal", + "type": "Literal", + "value": 3 + } + ], + "end": 15, + "start": 6, + "type": "ArrayExpression", + "type": "ArrayExpression" + }, + "start": 0, + "type": "VariableDeclarator" + } + ], + "end": 15, + "kind": "const", + "start": 0, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + }, + { + "declarations": [ + { + "end": 28, + "id": { + "end": 17, + "name": "x", + "start": 16, + "type": "Identifier" + }, + "init": { + "computed": false, + "end": 28, + "object": { + "end": 23, + "name": "arr", + "start": 20, + "type": "Identifier", + "type": "Identifier" + }, + "property": { + "end": 27, + "raw": "\"s\"", + "start": 24, + "type": "Literal", + "type": "Literal", + "value": "s" + }, + "start": 20, + "type": "MemberExpression", + "type": "MemberExpression" + }, + "start": 16, + "type": "VariableDeclarator" + } + ], + "end": 28, + "kind": "const", + "start": 16, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + } + ], + "end": 29, + "start": 0 + } +} diff --git a/src/wasm-lib/kcl/tests/invalid_index_str/execution_error.snap b/src/wasm-lib/kcl/tests/invalid_index_str/execution_error.snap new file mode 100644 index 0000000000..b890237a45 --- /dev/null +++ b/src/wasm-lib/kcl/tests/invalid_index_str/execution_error.snap @@ -0,0 +1,6 @@ +--- +source: kcl/src/simulation_tests.rs +description: Error from executing invalid_index_str.kcl +snapshot_kind: text +--- +semantic: KclErrorDetails { source_ranges: [SourceRange([20, 28, 0])], message: "Only integers >= 0 can be used as the index of an array, but you're using a string" } diff --git a/src/wasm-lib/kcl/tests/invalid_index_str/input.kcl b/src/wasm-lib/kcl/tests/invalid_index_str/input.kcl new file mode 100644 index 0000000000..20781cd73b --- /dev/null +++ b/src/wasm-lib/kcl/tests/invalid_index_str/input.kcl @@ -0,0 +1,2 @@ +arr = [1, 2, 3] +x = arr["s"] diff --git a/src/wasm-lib/kcl/tests/invalid_index_str/tokens.snap b/src/wasm-lib/kcl/tests/invalid_index_str/tokens.snap new file mode 100644 index 0000000000..f91c9f2086 --- /dev/null +++ b/src/wasm-lib/kcl/tests/invalid_index_str/tokens.snap @@ -0,0 +1,147 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of tokenizing invalid_index_str.kcl +snapshot_kind: text +--- +{ + "Ok": [ + { + "type": "word", + "start": 0, + "end": 3, + "value": "arr" + }, + { + "type": "whitespace", + "start": 3, + "end": 4, + "value": " " + }, + { + "type": "operator", + "start": 4, + "end": 5, + "value": "=" + }, + { + "type": "whitespace", + "start": 5, + "end": 6, + "value": " " + }, + { + "type": "brace", + "start": 6, + "end": 7, + "value": "[" + }, + { + "type": "number", + "start": 7, + "end": 8, + "value": "1" + }, + { + "type": "comma", + "start": 8, + "end": 9, + "value": "," + }, + { + "type": "whitespace", + "start": 9, + "end": 10, + "value": " " + }, + { + "type": "number", + "start": 10, + "end": 11, + "value": "2" + }, + { + "type": "comma", + "start": 11, + "end": 12, + "value": "," + }, + { + "type": "whitespace", + "start": 12, + "end": 13, + "value": " " + }, + { + "type": "number", + "start": 13, + "end": 14, + "value": "3" + }, + { + "type": "brace", + "start": 14, + "end": 15, + "value": "]" + }, + { + "type": "whitespace", + "start": 15, + "end": 16, + "value": "\n" + }, + { + "type": "word", + "start": 16, + "end": 17, + "value": "x" + }, + { + "type": "whitespace", + "start": 17, + "end": 18, + "value": " " + }, + { + "type": "operator", + "start": 18, + "end": 19, + "value": "=" + }, + { + "type": "whitespace", + "start": 19, + "end": 20, + "value": " " + }, + { + "type": "word", + "start": 20, + "end": 23, + "value": "arr" + }, + { + "type": "brace", + "start": 23, + "end": 24, + "value": "[" + }, + { + "type": "string", + "start": 24, + "end": 27, + "value": "\"s\"" + }, + { + "type": "brace", + "start": 27, + "end": 28, + "value": "]" + }, + { + "type": "whitespace", + "start": 28, + "end": 29, + "value": "\n" + } + ] +} diff --git a/src/wasm-lib/kcl/tests/invalid_member_object/ast.snap b/src/wasm-lib/kcl/tests/invalid_member_object/ast.snap new file mode 100644 index 0000000000..828da0620a --- /dev/null +++ b/src/wasm-lib/kcl/tests/invalid_member_object/ast.snap @@ -0,0 +1,83 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of parsing invalid_member_object.kcl +snapshot_kind: text +--- +{ + "Ok": { + "body": [ + { + "declarations": [ + { + "end": 9, + "id": { + "end": 3, + "name": "num", + "start": 0, + "type": "Identifier" + }, + "init": { + "end": 9, + "raw": "999", + "start": 6, + "type": "Literal", + "type": "Literal", + "value": 999 + }, + "start": 0, + "type": "VariableDeclarator" + } + ], + "end": 9, + "kind": "const", + "start": 0, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + }, + { + "declarations": [ + { + "end": 20, + "id": { + "end": 11, + "name": "x", + "start": 10, + "type": "Identifier" + }, + "init": { + "computed": false, + "end": 20, + "object": { + "end": 17, + "name": "num", + "start": 14, + "type": "Identifier", + "type": "Identifier" + }, + "property": { + "end": 19, + "raw": "3", + "start": 18, + "type": "Literal", + "type": "Literal", + "value": 3 + }, + "start": 14, + "type": "MemberExpression", + "type": "MemberExpression" + }, + "start": 10, + "type": "VariableDeclarator" + } + ], + "end": 20, + "kind": "const", + "start": 10, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + } + ], + "end": 21, + "start": 0 + } +} diff --git a/src/wasm-lib/kcl/tests/invalid_member_object/execution_error.snap b/src/wasm-lib/kcl/tests/invalid_member_object/execution_error.snap new file mode 100644 index 0000000000..0ccb145479 --- /dev/null +++ b/src/wasm-lib/kcl/tests/invalid_member_object/execution_error.snap @@ -0,0 +1,6 @@ +--- +source: kcl/src/simulation_tests.rs +description: Error from executing invalid_member_object.kcl +snapshot_kind: text +--- +semantic: KclErrorDetails { source_ranges: [SourceRange([14, 20, 0])], message: "Only arrays and objects can be indexed, but you're trying to index an integer" } diff --git a/src/wasm-lib/kcl/tests/invalid_member_object/input.kcl b/src/wasm-lib/kcl/tests/invalid_member_object/input.kcl new file mode 100644 index 0000000000..1875c80bf3 --- /dev/null +++ b/src/wasm-lib/kcl/tests/invalid_member_object/input.kcl @@ -0,0 +1,2 @@ +num = 999 +x = num[3] diff --git a/src/wasm-lib/kcl/tests/invalid_member_object/tokens.snap b/src/wasm-lib/kcl/tests/invalid_member_object/tokens.snap new file mode 100644 index 0000000000..5a836da1df --- /dev/null +++ b/src/wasm-lib/kcl/tests/invalid_member_object/tokens.snap @@ -0,0 +1,99 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of tokenizing invalid_member_object.kcl +snapshot_kind: text +--- +{ + "Ok": [ + { + "type": "word", + "start": 0, + "end": 3, + "value": "num" + }, + { + "type": "whitespace", + "start": 3, + "end": 4, + "value": " " + }, + { + "type": "operator", + "start": 4, + "end": 5, + "value": "=" + }, + { + "type": "whitespace", + "start": 5, + "end": 6, + "value": " " + }, + { + "type": "number", + "start": 6, + "end": 9, + "value": "999" + }, + { + "type": "whitespace", + "start": 9, + "end": 10, + "value": "\n" + }, + { + "type": "word", + "start": 10, + "end": 11, + "value": "x" + }, + { + "type": "whitespace", + "start": 11, + "end": 12, + "value": " " + }, + { + "type": "operator", + "start": 12, + "end": 13, + "value": "=" + }, + { + "type": "whitespace", + "start": 13, + "end": 14, + "value": " " + }, + { + "type": "word", + "start": 14, + "end": 17, + "value": "num" + }, + { + "type": "brace", + "start": 17, + "end": 18, + "value": "[" + }, + { + "type": "number", + "start": 18, + "end": 19, + "value": "3" + }, + { + "type": "brace", + "start": 19, + "end": 20, + "value": "]" + }, + { + "type": "whitespace", + "start": 20, + "end": 21, + "value": "\n" + } + ] +} diff --git a/src/wasm-lib/kcl/tests/invalid_member_object_prop/ast.snap b/src/wasm-lib/kcl/tests/invalid_member_object_prop/ast.snap new file mode 100644 index 0000000000..d8f5eef035 --- /dev/null +++ b/src/wasm-lib/kcl/tests/invalid_member_object_prop/ast.snap @@ -0,0 +1,83 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of parsing invalid_member_object_prop.kcl +snapshot_kind: text +--- +{ + "Ok": { + "body": [ + { + "declarations": [ + { + "end": 8, + "id": { + "end": 1, + "name": "b", + "start": 0, + "type": "Identifier" + }, + "init": { + "end": 8, + "raw": "true", + "start": 4, + "type": "Literal", + "type": "Literal", + "value": true + }, + "start": 0, + "type": "VariableDeclarator" + } + ], + "end": 8, + "kind": "const", + "start": 0, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + }, + { + "declarations": [ + { + "end": 26, + "id": { + "end": 10, + "name": "x", + "start": 9, + "type": "Identifier" + }, + "init": { + "computed": false, + "end": 26, + "object": { + "end": 14, + "name": "b", + "start": 13, + "type": "Identifier", + "type": "Identifier" + }, + "property": { + "end": 25, + "raw": "\"property\"", + "start": 15, + "type": "Literal", + "type": "Literal", + "value": "property" + }, + "start": 13, + "type": "MemberExpression", + "type": "MemberExpression" + }, + "start": 9, + "type": "VariableDeclarator" + } + ], + "end": 26, + "kind": "const", + "start": 9, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + } + ], + "end": 27, + "start": 0 + } +} diff --git a/src/wasm-lib/kcl/tests/invalid_member_object_prop/execution_error.snap b/src/wasm-lib/kcl/tests/invalid_member_object_prop/execution_error.snap new file mode 100644 index 0000000000..737cb69f87 --- /dev/null +++ b/src/wasm-lib/kcl/tests/invalid_member_object_prop/execution_error.snap @@ -0,0 +1,6 @@ +--- +source: kcl/src/simulation_tests.rs +description: Error from executing invalid_member_object_prop.kcl +snapshot_kind: text +--- +semantic: KclErrorDetails { source_ranges: [SourceRange([13, 26, 0])], message: "Only arrays and objects can be indexed, but you're trying to index a boolean (true/false value)" } diff --git a/src/wasm-lib/kcl/tests/invalid_member_object_prop/input.kcl b/src/wasm-lib/kcl/tests/invalid_member_object_prop/input.kcl new file mode 100644 index 0000000000..7585a34956 --- /dev/null +++ b/src/wasm-lib/kcl/tests/invalid_member_object_prop/input.kcl @@ -0,0 +1,2 @@ +b = true +x = b["property"] diff --git a/src/wasm-lib/kcl/tests/invalid_member_object_prop/tokens.snap b/src/wasm-lib/kcl/tests/invalid_member_object_prop/tokens.snap new file mode 100644 index 0000000000..1f972fb86a --- /dev/null +++ b/src/wasm-lib/kcl/tests/invalid_member_object_prop/tokens.snap @@ -0,0 +1,99 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of tokenizing invalid_member_object_prop.kcl +snapshot_kind: text +--- +{ + "Ok": [ + { + "type": "word", + "start": 0, + "end": 1, + "value": "b" + }, + { + "type": "whitespace", + "start": 1, + "end": 2, + "value": " " + }, + { + "type": "operator", + "start": 2, + "end": 3, + "value": "=" + }, + { + "type": "whitespace", + "start": 3, + "end": 4, + "value": " " + }, + { + "type": "keyword", + "start": 4, + "end": 8, + "value": "true" + }, + { + "type": "whitespace", + "start": 8, + "end": 9, + "value": "\n" + }, + { + "type": "word", + "start": 9, + "end": 10, + "value": "x" + }, + { + "type": "whitespace", + "start": 10, + "end": 11, + "value": " " + }, + { + "type": "operator", + "start": 11, + "end": 12, + "value": "=" + }, + { + "type": "whitespace", + "start": 12, + "end": 13, + "value": " " + }, + { + "type": "word", + "start": 13, + "end": 14, + "value": "b" + }, + { + "type": "brace", + "start": 14, + "end": 15, + "value": "[" + }, + { + "type": "string", + "start": 15, + "end": 25, + "value": "\"property\"" + }, + { + "type": "brace", + "start": 25, + "end": 26, + "value": "]" + }, + { + "type": "whitespace", + "start": 26, + "end": 27, + "value": "\n" + } + ] +} diff --git a/src/wasm-lib/kcl/tests/non_string_key_of_object/ast.snap b/src/wasm-lib/kcl/tests/non_string_key_of_object/ast.snap new file mode 100644 index 0000000000..8965f776f0 --- /dev/null +++ b/src/wasm-lib/kcl/tests/non_string_key_of_object/ast.snap @@ -0,0 +1,102 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of parsing non_string_key_of_object.kcl +snapshot_kind: text +--- +{ + "Ok": { + "body": [ + { + "declarations": [ + { + "end": 18, + "id": { + "end": 3, + "name": "obj", + "start": 0, + "type": "Identifier" + }, + "init": { + "end": 18, + "properties": [ + { + "end": 16, + "key": { + "end": 11, + "name": "key", + "start": 8, + "type": "Identifier" + }, + "start": 8, + "type": "ObjectProperty", + "value": { + "end": 16, + "raw": "123", + "start": 13, + "type": "Literal", + "type": "Literal", + "value": 123 + } + } + ], + "start": 6, + "type": "ObjectExpression", + "type": "ObjectExpression" + }, + "start": 0, + "type": "VariableDeclarator" + } + ], + "end": 18, + "kind": "const", + "start": 0, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + }, + { + "declarations": [ + { + "end": 31, + "id": { + "end": 22, + "name": "num", + "start": 19, + "type": "Identifier" + }, + "init": { + "computed": false, + "end": 31, + "object": { + "end": 28, + "name": "obj", + "start": 25, + "type": "Identifier", + "type": "Identifier" + }, + "property": { + "end": 30, + "raw": "3", + "start": 29, + "type": "Literal", + "type": "Literal", + "value": 3 + }, + "start": 25, + "type": "MemberExpression", + "type": "MemberExpression" + }, + "start": 19, + "type": "VariableDeclarator" + } + ], + "end": 31, + "kind": "const", + "start": 19, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + } + ], + "end": 32, + "start": 0 + } +} diff --git a/src/wasm-lib/kcl/tests/non_string_key_of_object/execution_error.snap b/src/wasm-lib/kcl/tests/non_string_key_of_object/execution_error.snap new file mode 100644 index 0000000000..999d424316 --- /dev/null +++ b/src/wasm-lib/kcl/tests/non_string_key_of_object/execution_error.snap @@ -0,0 +1,6 @@ +--- +source: kcl/src/simulation_tests.rs +description: Error from executing non_string_key_of_object.kcl +snapshot_kind: text +--- +semantic: KclErrorDetails { source_ranges: [SourceRange([25, 31, 0])], message: "Only strings can be used as the property of an object, but you're using a number" } diff --git a/src/wasm-lib/kcl/tests/non_string_key_of_object/input.kcl b/src/wasm-lib/kcl/tests/non_string_key_of_object/input.kcl new file mode 100644 index 0000000000..3650e17f48 --- /dev/null +++ b/src/wasm-lib/kcl/tests/non_string_key_of_object/input.kcl @@ -0,0 +1,2 @@ +obj = { key: 123 } +num = obj[3] diff --git a/src/wasm-lib/kcl/tests/non_string_key_of_object/tokens.snap b/src/wasm-lib/kcl/tests/non_string_key_of_object/tokens.snap new file mode 100644 index 0000000000..f285af9a18 --- /dev/null +++ b/src/wasm-lib/kcl/tests/non_string_key_of_object/tokens.snap @@ -0,0 +1,141 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of tokenizing non_string_key_of_object.kcl +snapshot_kind: text +--- +{ + "Ok": [ + { + "type": "word", + "start": 0, + "end": 3, + "value": "obj" + }, + { + "type": "whitespace", + "start": 3, + "end": 4, + "value": " " + }, + { + "type": "operator", + "start": 4, + "end": 5, + "value": "=" + }, + { + "type": "whitespace", + "start": 5, + "end": 6, + "value": " " + }, + { + "type": "brace", + "start": 6, + "end": 7, + "value": "{" + }, + { + "type": "whitespace", + "start": 7, + "end": 8, + "value": " " + }, + { + "type": "word", + "start": 8, + "end": 11, + "value": "key" + }, + { + "type": "colon", + "start": 11, + "end": 12, + "value": ":" + }, + { + "type": "whitespace", + "start": 12, + "end": 13, + "value": " " + }, + { + "type": "number", + "start": 13, + "end": 16, + "value": "123" + }, + { + "type": "whitespace", + "start": 16, + "end": 17, + "value": " " + }, + { + "type": "brace", + "start": 17, + "end": 18, + "value": "}" + }, + { + "type": "whitespace", + "start": 18, + "end": 19, + "value": "\n" + }, + { + "type": "word", + "start": 19, + "end": 22, + "value": "num" + }, + { + "type": "whitespace", + "start": 22, + "end": 23, + "value": " " + }, + { + "type": "operator", + "start": 23, + "end": 24, + "value": "=" + }, + { + "type": "whitespace", + "start": 24, + "end": 25, + "value": " " + }, + { + "type": "word", + "start": 25, + "end": 28, + "value": "obj" + }, + { + "type": "brace", + "start": 28, + "end": 29, + "value": "[" + }, + { + "type": "number", + "start": 29, + "end": 30, + "value": "3" + }, + { + "type": "brace", + "start": 30, + "end": 31, + "value": "]" + }, + { + "type": "whitespace", + "start": 31, + "end": 32, + "value": "\n" + } + ] +} diff --git a/src/wasm-lib/kcl/tests/object_prop_not_found/ast.snap b/src/wasm-lib/kcl/tests/object_prop_not_found/ast.snap new file mode 100644 index 0000000000..ac81998777 --- /dev/null +++ b/src/wasm-lib/kcl/tests/object_prop_not_found/ast.snap @@ -0,0 +1,82 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of parsing object_prop_not_found.kcl +snapshot_kind: text +--- +{ + "Ok": { + "body": [ + { + "declarations": [ + { + "end": 10, + "id": { + "end": 3, + "name": "obj", + "start": 0, + "type": "Identifier" + }, + "init": { + "end": 10, + "properties": [], + "start": 6, + "type": "ObjectExpression", + "type": "ObjectExpression" + }, + "start": 0, + "type": "VariableDeclarator" + } + ], + "end": 10, + "kind": "const", + "start": 0, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + }, + { + "declarations": [ + { + "end": 25, + "id": { + "end": 12, + "name": "k", + "start": 11, + "type": "Identifier" + }, + "init": { + "computed": false, + "end": 25, + "object": { + "end": 18, + "name": "obj", + "start": 15, + "type": "Identifier", + "type": "Identifier" + }, + "property": { + "end": 24, + "raw": "\"age\"", + "start": 19, + "type": "Literal", + "type": "Literal", + "value": "age" + }, + "start": 15, + "type": "MemberExpression", + "type": "MemberExpression" + }, + "start": 11, + "type": "VariableDeclarator" + } + ], + "end": 25, + "kind": "const", + "start": 11, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + } + ], + "end": 26, + "start": 0 + } +} diff --git a/src/wasm-lib/kcl/tests/object_prop_not_found/execution_error.snap b/src/wasm-lib/kcl/tests/object_prop_not_found/execution_error.snap new file mode 100644 index 0000000000..33ebf36f19 --- /dev/null +++ b/src/wasm-lib/kcl/tests/object_prop_not_found/execution_error.snap @@ -0,0 +1,6 @@ +--- +source: kcl/src/simulation_tests.rs +description: Error from executing object_prop_not_found.kcl +snapshot_kind: text +--- +undefined value: KclErrorDetails { source_ranges: [SourceRange([15, 25, 0])], message: "Property 'age' not found in object" } diff --git a/src/wasm-lib/kcl/tests/object_prop_not_found/input.kcl b/src/wasm-lib/kcl/tests/object_prop_not_found/input.kcl new file mode 100644 index 0000000000..90d79044e9 --- /dev/null +++ b/src/wasm-lib/kcl/tests/object_prop_not_found/input.kcl @@ -0,0 +1,2 @@ +obj = { } +k = obj["age"] diff --git a/src/wasm-lib/kcl/tests/object_prop_not_found/tokens.snap b/src/wasm-lib/kcl/tests/object_prop_not_found/tokens.snap new file mode 100644 index 0000000000..8acd51f88d --- /dev/null +++ b/src/wasm-lib/kcl/tests/object_prop_not_found/tokens.snap @@ -0,0 +1,111 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of tokenizing object_prop_not_found.kcl +snapshot_kind: text +--- +{ + "Ok": [ + { + "type": "word", + "start": 0, + "end": 3, + "value": "obj" + }, + { + "type": "whitespace", + "start": 3, + "end": 4, + "value": " " + }, + { + "type": "operator", + "start": 4, + "end": 5, + "value": "=" + }, + { + "type": "whitespace", + "start": 5, + "end": 6, + "value": " " + }, + { + "type": "brace", + "start": 6, + "end": 7, + "value": "{" + }, + { + "type": "whitespace", + "start": 7, + "end": 9, + "value": " " + }, + { + "type": "brace", + "start": 9, + "end": 10, + "value": "}" + }, + { + "type": "whitespace", + "start": 10, + "end": 11, + "value": "\n" + }, + { + "type": "word", + "start": 11, + "end": 12, + "value": "k" + }, + { + "type": "whitespace", + "start": 12, + "end": 13, + "value": " " + }, + { + "type": "operator", + "start": 13, + "end": 14, + "value": "=" + }, + { + "type": "whitespace", + "start": 14, + "end": 15, + "value": " " + }, + { + "type": "word", + "start": 15, + "end": 18, + "value": "obj" + }, + { + "type": "brace", + "start": 18, + "end": 19, + "value": "[" + }, + { + "type": "string", + "start": 19, + "end": 24, + "value": "\"age\"" + }, + { + "type": "brace", + "start": 24, + "end": 25, + "value": "]" + }, + { + "type": "whitespace", + "start": 25, + "end": 26, + "value": "\n" + } + ] +} diff --git a/src/wasm-lib/kcl/tests/pipe_substitution_inside_function_called_from_pipeline/ast.snap b/src/wasm-lib/kcl/tests/pipe_substitution_inside_function_called_from_pipeline/ast.snap new file mode 100644 index 0000000000..7228aee14a --- /dev/null +++ b/src/wasm-lib/kcl/tests/pipe_substitution_inside_function_called_from_pipeline/ast.snap @@ -0,0 +1,150 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of parsing pipe_substitution_inside_function_called_from_pipeline.kcl +snapshot_kind: text +--- +{ + "Ok": { + "body": [ + { + "declarations": [ + { + "end": 95, + "id": { + "end": 65, + "name": "f", + "start": 64, + "type": "Identifier" + }, + "init": { + "body": { + "body": [ + { + "argument": { + "end": 93, + "start": 92, + "type": "PipeSubstitution", + "type": "PipeSubstitution" + }, + "end": 93, + "start": 85, + "type": "ReturnStatement", + "type": "ReturnStatement" + } + ], + "end": 95, + "start": 81 + }, + "end": 95, + "params": [ + { + "type": "Parameter", + "identifier": { + "end": 76, + "name": "ignored", + "start": 69, + "type": "Identifier" + }, + "optional": false + } + ], + "start": 68, + "type": "FunctionExpression", + "type": "FunctionExpression" + }, + "start": 64, + "type": "VariableDeclarator" + } + ], + "end": 95, + "kind": "fn", + "start": 61, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + }, + { + "declarations": [ + { + "end": 117, + "id": { + "end": 103, + "name": "answer", + "start": 97, + "type": "Identifier" + }, + "init": { + "body": [ + { + "end": 107, + "start": 106, + "type": "PipeSubstitution", + "type": "PipeSubstitution" + }, + { + "arguments": [ + { + "end": 116, + "start": 115, + "type": "PipeSubstitution", + "type": "PipeSubstitution" + } + ], + "callee": { + "end": 114, + "name": "f", + "start": 113, + "type": "Identifier" + }, + "end": 117, + "optional": false, + "start": 113, + "type": "CallExpression", + "type": "CallExpression" + } + ], + "end": 117, + "start": 106, + "type": "PipeExpression", + "type": "PipeExpression" + }, + "start": 97, + "type": "VariableDeclarator" + } + ], + "end": 117, + "kind": "const", + "start": 97, + "type": "VariableDeclaration", + "type": "VariableDeclaration" + } + ], + "end": 118, + "nonCodeMeta": { + "nonCodeNodes": { + "0": [ + { + "end": 97, + "start": 95, + "type": "NonCodeNode", + "value": { + "type": "newLine" + } + } + ] + }, + "startNodes": [ + { + "end": 60, + "start": 0, + "type": "NonCodeNode", + "value": { + "type": "blockComment", + "value": "Make sure pipe value doesn't leak into the function call.", + "style": "line" + } + } + ] + }, + "start": 0 + } +} diff --git a/src/wasm-lib/kcl/tests/pipe_substitution_inside_function_called_from_pipeline/execution_error.snap b/src/wasm-lib/kcl/tests/pipe_substitution_inside_function_called_from_pipeline/execution_error.snap new file mode 100644 index 0000000000..ddd7dda7a1 --- /dev/null +++ b/src/wasm-lib/kcl/tests/pipe_substitution_inside_function_called_from_pipeline/execution_error.snap @@ -0,0 +1,6 @@ +--- +source: kcl/src/simulation_tests.rs +description: Error from executing pipe_substitution_inside_function_called_from_pipeline.kcl +snapshot_kind: text +--- +semantic: KclErrorDetails { source_ranges: [SourceRange([106, 107, 0])], message: "cannot use % outside a pipe expression" } diff --git a/src/wasm-lib/tests/executor/inputs/no_visuals/pipe_substitution_inside_function_called_from_pipeline.kcl b/src/wasm-lib/kcl/tests/pipe_substitution_inside_function_called_from_pipeline/input.kcl similarity index 86% rename from src/wasm-lib/tests/executor/inputs/no_visuals/pipe_substitution_inside_function_called_from_pipeline.kcl rename to src/wasm-lib/kcl/tests/pipe_substitution_inside_function_called_from_pipeline/input.kcl index 8be546a186..379bc27000 100644 --- a/src/wasm-lib/tests/executor/inputs/no_visuals/pipe_substitution_inside_function_called_from_pipeline.kcl +++ b/src/wasm-lib/kcl/tests/pipe_substitution_inside_function_called_from_pipeline/input.kcl @@ -3,5 +3,5 @@ fn f = (ignored) => { return % } -const answer = % +answer = % |> f(%) diff --git a/src/wasm-lib/kcl/tests/pipe_substitution_inside_function_called_from_pipeline/tokens.snap b/src/wasm-lib/kcl/tests/pipe_substitution_inside_function_called_from_pipeline/tokens.snap new file mode 100644 index 0000000000..bb7f1f83cb --- /dev/null +++ b/src/wasm-lib/kcl/tests/pipe_substitution_inside_function_called_from_pipeline/tokens.snap @@ -0,0 +1,219 @@ +--- +source: kcl/src/simulation_tests.rs +description: Result of tokenizing pipe_substitution_inside_function_called_from_pipeline.kcl +snapshot_kind: text +--- +{ + "Ok": [ + { + "type": "lineComment", + "start": 0, + "end": 60, + "value": "// Make sure pipe value doesn't leak into the function call." + }, + { + "type": "whitespace", + "start": 60, + "end": 61, + "value": "\n" + }, + { + "type": "keyword", + "start": 61, + "end": 63, + "value": "fn" + }, + { + "type": "whitespace", + "start": 63, + "end": 64, + "value": " " + }, + { + "type": "word", + "start": 64, + "end": 65, + "value": "f" + }, + { + "type": "whitespace", + "start": 65, + "end": 66, + "value": " " + }, + { + "type": "operator", + "start": 66, + "end": 67, + "value": "=" + }, + { + "type": "whitespace", + "start": 67, + "end": 68, + "value": " " + }, + { + "type": "brace", + "start": 68, + "end": 69, + "value": "(" + }, + { + "type": "word", + "start": 69, + "end": 76, + "value": "ignored" + }, + { + "type": "brace", + "start": 76, + "end": 77, + "value": ")" + }, + { + "type": "whitespace", + "start": 77, + "end": 78, + "value": " " + }, + { + "type": "operator", + "start": 78, + "end": 80, + "value": "=>" + }, + { + "type": "whitespace", + "start": 80, + "end": 81, + "value": " " + }, + { + "type": "brace", + "start": 81, + "end": 82, + "value": "{" + }, + { + "type": "whitespace", + "start": 82, + "end": 85, + "value": "\n " + }, + { + "type": "keyword", + "start": 85, + "end": 91, + "value": "return" + }, + { + "type": "whitespace", + "start": 91, + "end": 92, + "value": " " + }, + { + "type": "operator", + "start": 92, + "end": 93, + "value": "%" + }, + { + "type": "whitespace", + "start": 93, + "end": 94, + "value": "\n" + }, + { + "type": "brace", + "start": 94, + "end": 95, + "value": "}" + }, + { + "type": "whitespace", + "start": 95, + "end": 97, + "value": "\n\n" + }, + { + "type": "word", + "start": 97, + "end": 103, + "value": "answer" + }, + { + "type": "whitespace", + "start": 103, + "end": 104, + "value": " " + }, + { + "type": "operator", + "start": 104, + "end": 105, + "value": "=" + }, + { + "type": "whitespace", + "start": 105, + "end": 106, + "value": " " + }, + { + "type": "operator", + "start": 106, + "end": 107, + "value": "%" + }, + { + "type": "whitespace", + "start": 107, + "end": 110, + "value": "\n " + }, + { + "type": "operator", + "start": 110, + "end": 112, + "value": "|>" + }, + { + "type": "whitespace", + "start": 112, + "end": 113, + "value": " " + }, + { + "type": "word", + "start": 113, + "end": 114, + "value": "f" + }, + { + "type": "brace", + "start": 114, + "end": 115, + "value": "(" + }, + { + "type": "operator", + "start": 115, + "end": 116, + "value": "%" + }, + { + "type": "brace", + "start": 116, + "end": 117, + "value": ")" + }, + { + "type": "whitespace", + "start": 117, + "end": 118, + "value": "\n" + } + ] +} diff --git a/src/wasm-lib/tests/executor/inputs/no_visuals/array_index_oob.kcl b/src/wasm-lib/tests/executor/inputs/no_visuals/array_index_oob.kcl deleted file mode 100644 index 1cd77ca46a..0000000000 --- a/src/wasm-lib/tests/executor/inputs/no_visuals/array_index_oob.kcl +++ /dev/null @@ -1,2 +0,0 @@ -let arr = [] -let x = arr[0] diff --git a/src/wasm-lib/tests/executor/inputs/no_visuals/import_cycle1.kcl b/src/wasm-lib/tests/executor/inputs/no_visuals/import_cycle1.kcl deleted file mode 100644 index 101ba0dd88..0000000000 --- a/src/wasm-lib/tests/executor/inputs/no_visuals/import_cycle1.kcl +++ /dev/null @@ -1,3 +0,0 @@ -import two from "import_cycle2.kcl" - -export fn one = () => { return two() - 1 } diff --git a/src/wasm-lib/tests/executor/inputs/no_visuals/invalid_index_fractional.kcl b/src/wasm-lib/tests/executor/inputs/no_visuals/invalid_index_fractional.kcl deleted file mode 100644 index eefab701df..0000000000 --- a/src/wasm-lib/tests/executor/inputs/no_visuals/invalid_index_fractional.kcl +++ /dev/null @@ -1,2 +0,0 @@ -let arr = [1, 2, 3] -let x = arr[1.2] diff --git a/src/wasm-lib/tests/executor/inputs/no_visuals/invalid_index_negative.kcl b/src/wasm-lib/tests/executor/inputs/no_visuals/invalid_index_negative.kcl deleted file mode 100644 index 19a0fd9a1b..0000000000 --- a/src/wasm-lib/tests/executor/inputs/no_visuals/invalid_index_negative.kcl +++ /dev/null @@ -1,3 +0,0 @@ -let arr = [1, 2, 3] -let i = -1 -let x = arr[i] diff --git a/src/wasm-lib/tests/executor/inputs/no_visuals/invalid_index_str.kcl b/src/wasm-lib/tests/executor/inputs/no_visuals/invalid_index_str.kcl deleted file mode 100644 index 21ab041ef7..0000000000 --- a/src/wasm-lib/tests/executor/inputs/no_visuals/invalid_index_str.kcl +++ /dev/null @@ -1,2 +0,0 @@ -let arr = [1, 2, 3] -let x = arr["s"] diff --git a/src/wasm-lib/tests/executor/inputs/no_visuals/invalid_member_object.kcl b/src/wasm-lib/tests/executor/inputs/no_visuals/invalid_member_object.kcl deleted file mode 100644 index 0348e9c510..0000000000 --- a/src/wasm-lib/tests/executor/inputs/no_visuals/invalid_member_object.kcl +++ /dev/null @@ -1,2 +0,0 @@ -let num = 999 -let x = num[3] diff --git a/src/wasm-lib/tests/executor/inputs/no_visuals/invalid_member_object_prop.kcl b/src/wasm-lib/tests/executor/inputs/no_visuals/invalid_member_object_prop.kcl deleted file mode 100644 index e01d88d115..0000000000 --- a/src/wasm-lib/tests/executor/inputs/no_visuals/invalid_member_object_prop.kcl +++ /dev/null @@ -1,2 +0,0 @@ -let b = true -let x = b["property"] diff --git a/src/wasm-lib/tests/executor/inputs/no_visuals/non_string_key_of_object.kcl b/src/wasm-lib/tests/executor/inputs/no_visuals/non_string_key_of_object.kcl deleted file mode 100644 index 778ef67321..0000000000 --- a/src/wasm-lib/tests/executor/inputs/no_visuals/non_string_key_of_object.kcl +++ /dev/null @@ -1,2 +0,0 @@ -let obj = {key: 123} -let num = obj[3] diff --git a/src/wasm-lib/tests/executor/inputs/no_visuals/object_prop_not_found.kcl b/src/wasm-lib/tests/executor/inputs/no_visuals/object_prop_not_found.kcl deleted file mode 100644 index 83b8149993..0000000000 --- a/src/wasm-lib/tests/executor/inputs/no_visuals/object_prop_not_found.kcl +++ /dev/null @@ -1,2 +0,0 @@ -let obj = {} -let k = obj["age"] diff --git a/src/wasm-lib/tests/executor/no_visuals.rs b/src/wasm-lib/tests/executor/no_visuals.rs index 8714aaafe2..f006a6b23d 100644 --- a/src/wasm-lib/tests/executor/no_visuals.rs +++ b/src/wasm-lib/tests/executor/no_visuals.rs @@ -1,132 +1,7 @@ -use kcl_lib::{ - ast::types::{ModuleId, Node, Program}, - errors::KclError, - executor::{ExecutorContext, IdGenerator}, - parser, -}; - -macro_rules! gen_test_fail { - ($file:ident, $expected:literal) => { - #[tokio::test] - async fn $file() { - let code = include_str!(concat!("inputs/no_visuals/", stringify!($file), ".kcl")); - let actual = run_fail(&code).await; - assert_eq!(actual.get_message(), $expected); - } - }; -} - -macro_rules! gen_test_parse_fail { - ($file:ident, $expected:literal) => { - #[tokio::test] - async fn $file() { - let code = include_str!(concat!("inputs/no_visuals/", stringify!($file), ".kcl")); - let actual = run_parse_fail(&code).await; - assert_eq!(actual.get_message(), $expected); - } - }; -} - -async fn setup(program: &str) -> (ExecutorContext, Node, IdGenerator) { - let module_id = ModuleId::default(); - let tokens = kcl_lib::token::lexer(program, module_id).unwrap(); - let parser = kcl_lib::parser::Parser::new(tokens); - let program = parser.ast().unwrap(); - let ctx = kcl_lib::executor::ExecutorContext { - engine: std::sync::Arc::new(Box::new( - kcl_lib::engine::conn_mock::EngineConnection::new().await.unwrap(), - )), - fs: std::sync::Arc::new(kcl_lib::fs::FileManager::new()), - stdlib: std::sync::Arc::new(kcl_lib::std::StdLib::new()), - settings: Default::default(), - context_type: kcl_lib::executor::ContextType::Mock, - }; - (ctx, program, IdGenerator::default()) -} - -async fn run_fail(code: &str) -> KclError { - let (ctx, program, id_generator) = setup(code).await; - let Err(e) = ctx - .run( - &program, - None, - id_generator, - Some("tests/executor/inputs/no_visuals/".to_owned()), - ) - .await - else { - panic!("Expected this KCL program to fail, but it (incorrectly) never threw an error."); - }; - e -} - -async fn run_parse_fail(code: &str) -> KclError { - let Err(e) = parser::top_level_parse(code) else { - panic!("Expected this KCL program to fail to parse, but it (incorrectly) never threw an error."); - }; - e -} - -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" -); -gen_test_fail!( - invalid_index_negative, - "semantic: '-1' is negative, so you can't index an array with it" -); -gen_test_fail!( - invalid_index_fractional, - "semantic: Only strings or ints (>= 0) can be properties/indexes" -); -gen_test_fail!( - invalid_member_object, - "semantic: Only arrays and objects can be indexed, but you're trying to index an integer" -); -gen_test_fail!( - invalid_member_object_prop, - "semantic: Only arrays and objects can be indexed, but you're trying to index a boolean (true/false value)" -); -gen_test_fail!( - non_string_key_of_object, - "semantic: Only strings can be used as the property of an object, but you're using a number" -); -gen_test_fail!( - array_index_oob, - "undefined value: The array doesn't have any item at index 0" -); -gen_test_fail!( - object_prop_not_found, - "undefined value: Property 'age' not found in object" -); -gen_test_fail!( - pipe_substitution_inside_function_called_from_pipeline, - "semantic: cannot use % outside a pipe expression" -); // gen_test_fail!( // if_else_no_expr, // "syntax: blocks inside an if/else expression must end in an expression" // ); -gen_test_fail!( - comparisons_multiple, - "semantic: Expected a number, but found a boolean (true/false value)" -); -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" -); -gen_test_fail!( - import_constant, - "semantic: Error loading imported file. Open it to view more details. export_constant.kcl: Only functions can be exported" -); -gen_test_fail!( - import_side_effect, - "semantic: Error loading imported file. Open it to view more details. export_side_effect.kcl: Cannot send modeling commands while importing. Wrap your code in a function if you want to import the file." -); -gen_test_parse_fail!( - import_from_other_directory, - "syntax: import path may only contain alphanumeric characters, underscore, hyphen, and period. Files in other directories are not yet supported." -); // TODO: We'd like these tests. // gen_test_fail!( // import_in_if, @@ -136,7 +11,3 @@ gen_test_parse_fail!( // import_in_function, // "syntax: Can import only import at the top level" // ); -gen_test_fail!( - array_elem_push_fail, - "undefined value: The array doesn't have any item at index 3" -);