From 8b96cf3e33172a2baf7547a64746c5961695a5ae Mon Sep 17 00:00:00 2001 From: zongz Date: Tue, 15 Aug 2023 11:32:37 +0800 Subject: [PATCH] feat: replace "__main__" by package name when parse import statments in entry. --- kclvm/cmd/src/test_data/instances/test_inst_10/expected | 2 ++ kclvm/cmd/src/test_data/instances/test_inst_10/kcl.yaml | 7 +++++++ .../test_data/instances/test_inst_10/test_inst_101/kcl.mod | 5 +++++ .../test_data/instances/test_inst_10/test_inst_101/main.k | 5 +++++ .../test_data/instances/test_inst_10/test_inst_102/kcl.mod | 5 +++++ .../test_data/instances/test_inst_10/test_inst_102/main.k | 4 ++++ kclvm/cmd/src/test_data/instances/test_inst_9/expected | 4 ++++ kclvm/cmd/src/test_data/instances/test_inst_9/kcl.yaml | 7 +++++++ .../test_data/instances/test_inst_9/test_inst_91/kcl.mod | 5 +++++ .../test_data/instances/test_inst_9/test_inst_91/main.k | 5 +++++ .../test_data/instances/test_inst_9/test_inst_92/kcl.mod | 5 +++++ .../test_data/instances/test_inst_9/test_inst_92/main.k | 3 +++ .../instances/test_inst_9/test_inst_92/sub/main.k | 2 ++ kclvm/cmd/src/tests.rs | 2 ++ kclvm/parser/src/lib.rs | 2 +- 15 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 kclvm/cmd/src/test_data/instances/test_inst_10/expected create mode 100644 kclvm/cmd/src/test_data/instances/test_inst_10/kcl.yaml create mode 100644 kclvm/cmd/src/test_data/instances/test_inst_10/test_inst_101/kcl.mod create mode 100644 kclvm/cmd/src/test_data/instances/test_inst_10/test_inst_101/main.k create mode 100644 kclvm/cmd/src/test_data/instances/test_inst_10/test_inst_102/kcl.mod create mode 100644 kclvm/cmd/src/test_data/instances/test_inst_10/test_inst_102/main.k create mode 100644 kclvm/cmd/src/test_data/instances/test_inst_9/expected create mode 100644 kclvm/cmd/src/test_data/instances/test_inst_9/kcl.yaml create mode 100644 kclvm/cmd/src/test_data/instances/test_inst_9/test_inst_91/kcl.mod create mode 100644 kclvm/cmd/src/test_data/instances/test_inst_9/test_inst_91/main.k create mode 100644 kclvm/cmd/src/test_data/instances/test_inst_9/test_inst_92/kcl.mod create mode 100644 kclvm/cmd/src/test_data/instances/test_inst_9/test_inst_92/main.k create mode 100644 kclvm/cmd/src/test_data/instances/test_inst_9/test_inst_92/sub/main.k diff --git a/kclvm/cmd/src/test_data/instances/test_inst_10/expected b/kclvm/cmd/src/test_data/instances/test_inst_10/expected new file mode 100644 index 000000000..7987170eb --- /dev/null +++ b/kclvm/cmd/src/test_data/instances/test_inst_10/expected @@ -0,0 +1,2 @@ +a: + id: 102 diff --git a/kclvm/cmd/src/test_data/instances/test_inst_10/kcl.yaml b/kclvm/cmd/src/test_data/instances/test_inst_10/kcl.yaml new file mode 100644 index 000000000..0dfc987fd --- /dev/null +++ b/kclvm/cmd/src/test_data/instances/test_inst_10/kcl.yaml @@ -0,0 +1,7 @@ +kcl_cli_configs: + file: + - ./test_inst_101/main.k + - ${test_inst_102:KCL_MOD}/main.k + package_maps: + test_inst_102: ./src/test_data/instances/test_inst_10/test_inst_102 + diff --git a/kclvm/cmd/src/test_data/instances/test_inst_10/test_inst_101/kcl.mod b/kclvm/cmd/src/test_data/instances/test_inst_10/test_inst_101/kcl.mod new file mode 100644 index 000000000..3040fb9e1 --- /dev/null +++ b/kclvm/cmd/src/test_data/instances/test_inst_10/test_inst_101/kcl.mod @@ -0,0 +1,5 @@ +[package] +name = "test_inst_101" +edition = "0.0.1" +version = "0.0.1" + diff --git a/kclvm/cmd/src/test_data/instances/test_inst_10/test_inst_101/main.k b/kclvm/cmd/src/test_data/instances/test_inst_10/test_inst_101/main.k new file mode 100644 index 000000000..12d2fe392 --- /dev/null +++ b/kclvm/cmd/src/test_data/instances/test_inst_10/test_inst_101/main.k @@ -0,0 +1,5 @@ +import test_inst_102 as k102 + +a = k102.K102 { + id: 102 +} \ No newline at end of file diff --git a/kclvm/cmd/src/test_data/instances/test_inst_10/test_inst_102/kcl.mod b/kclvm/cmd/src/test_data/instances/test_inst_10/test_inst_102/kcl.mod new file mode 100644 index 000000000..341192b5c --- /dev/null +++ b/kclvm/cmd/src/test_data/instances/test_inst_10/test_inst_102/kcl.mod @@ -0,0 +1,5 @@ +[package] +name = "test_inst_102" +edition = "0.0.1" +version = "0.0.1" + diff --git a/kclvm/cmd/src/test_data/instances/test_inst_10/test_inst_102/main.k b/kclvm/cmd/src/test_data/instances/test_inst_10/test_inst_102/main.k new file mode 100644 index 000000000..27b218bce --- /dev/null +++ b/kclvm/cmd/src/test_data/instances/test_inst_10/test_inst_102/main.k @@ -0,0 +1,4 @@ +schema K102: + id: int + +inst102 = K102.instances() \ No newline at end of file diff --git a/kclvm/cmd/src/test_data/instances/test_inst_9/expected b/kclvm/cmd/src/test_data/instances/test_inst_9/expected new file mode 100644 index 000000000..f27fc6f83 --- /dev/null +++ b/kclvm/cmd/src/test_data/instances/test_inst_9/expected @@ -0,0 +1,4 @@ +a: + id: 92 +inst92: +- id: 92 diff --git a/kclvm/cmd/src/test_data/instances/test_inst_9/kcl.yaml b/kclvm/cmd/src/test_data/instances/test_inst_9/kcl.yaml new file mode 100644 index 000000000..506e7a6d6 --- /dev/null +++ b/kclvm/cmd/src/test_data/instances/test_inst_9/kcl.yaml @@ -0,0 +1,7 @@ +kcl_cli_configs: + file: + - ./test_inst_91/main.k + - ${test_inst_92:KCL_MOD}/main.k + package_maps: + test_inst_92: ./src/test_data/instances/test_inst_9/test_inst_92 + diff --git a/kclvm/cmd/src/test_data/instances/test_inst_9/test_inst_91/kcl.mod b/kclvm/cmd/src/test_data/instances/test_inst_9/test_inst_91/kcl.mod new file mode 100644 index 000000000..3040fb9e1 --- /dev/null +++ b/kclvm/cmd/src/test_data/instances/test_inst_9/test_inst_91/kcl.mod @@ -0,0 +1,5 @@ +[package] +name = "test_inst_101" +edition = "0.0.1" +version = "0.0.1" + diff --git a/kclvm/cmd/src/test_data/instances/test_inst_9/test_inst_91/main.k b/kclvm/cmd/src/test_data/instances/test_inst_9/test_inst_91/main.k new file mode 100644 index 000000000..990f4bb24 --- /dev/null +++ b/kclvm/cmd/src/test_data/instances/test_inst_9/test_inst_91/main.k @@ -0,0 +1,5 @@ +import test_inst_92.sub as k92 + +a = k92.K92 { + id: 92 +} \ No newline at end of file diff --git a/kclvm/cmd/src/test_data/instances/test_inst_9/test_inst_92/kcl.mod b/kclvm/cmd/src/test_data/instances/test_inst_9/test_inst_92/kcl.mod new file mode 100644 index 000000000..341192b5c --- /dev/null +++ b/kclvm/cmd/src/test_data/instances/test_inst_9/test_inst_92/kcl.mod @@ -0,0 +1,5 @@ +[package] +name = "test_inst_102" +edition = "0.0.1" +version = "0.0.1" + diff --git a/kclvm/cmd/src/test_data/instances/test_inst_9/test_inst_92/main.k b/kclvm/cmd/src/test_data/instances/test_inst_9/test_inst_92/main.k new file mode 100644 index 000000000..1d27555ca --- /dev/null +++ b/kclvm/cmd/src/test_data/instances/test_inst_9/test_inst_92/main.k @@ -0,0 +1,3 @@ +import sub as s + +inst92 = s.K92.instances() \ No newline at end of file diff --git a/kclvm/cmd/src/test_data/instances/test_inst_9/test_inst_92/sub/main.k b/kclvm/cmd/src/test_data/instances/test_inst_9/test_inst_92/sub/main.k new file mode 100644 index 000000000..73354a6ef --- /dev/null +++ b/kclvm/cmd/src/test_data/instances/test_inst_9/test_inst_92/sub/main.k @@ -0,0 +1,2 @@ +schema K92: + id: int \ No newline at end of file diff --git a/kclvm/cmd/src/tests.rs b/kclvm/cmd/src/tests.rs index 662c3e31f..a6b549e08 100644 --- a/kclvm/cmd/src/tests.rs +++ b/kclvm/cmd/src/tests.rs @@ -469,6 +469,8 @@ fn test_instances_with_yaml() { "test_inst_6", "test_inst_7", "test_inst_8", + "test_inst_9", + "test_inst_10", ]; for case in &test_cases { diff --git a/kclvm/parser/src/lib.rs b/kclvm/parser/src/lib.rs index 17f9f10f1..ea841c936 100644 --- a/kclvm/parser/src/lib.rs +++ b/kclvm/parser/src/lib.rs @@ -307,7 +307,7 @@ impl Loader { self.load_import_package( &entry.path(), - kclvm_ast::MAIN_PKG.to_string(), + entry.name().to_string(), &mut pkg_files, &mut pkgs, )?;