Skip to content

Commit

Permalink
feat: replace "__main__" by package name when parse import statments …
Browse files Browse the repository at this point in the history
…in entry.
  • Loading branch information
zong-zhe committed Aug 15, 2023
1 parent a8cabd2 commit 8b96cf3
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 1 deletion.
2 changes: 2 additions & 0 deletions kclvm/cmd/src/test_data/instances/test_inst_10/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a:
id: 102
7 changes: 7 additions & 0 deletions kclvm/cmd/src/test_data/instances/test_inst_10/kcl.yaml
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "test_inst_101"
edition = "0.0.1"
version = "0.0.1"

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import test_inst_102 as k102

a = k102.K102 {
id: 102
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "test_inst_102"
edition = "0.0.1"
version = "0.0.1"

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
schema K102:
id: int

inst102 = K102.instances()
4 changes: 4 additions & 0 deletions kclvm/cmd/src/test_data/instances/test_inst_9/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
a:
id: 92
inst92:
- id: 92
7 changes: 7 additions & 0 deletions kclvm/cmd/src/test_data/instances/test_inst_9/kcl.yaml
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "test_inst_101"
edition = "0.0.1"
version = "0.0.1"

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import test_inst_92.sub as k92

a = k92.K92 {
id: 92
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "test_inst_102"
edition = "0.0.1"
version = "0.0.1"

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import sub as s

inst92 = s.K92.instances()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema K92:
id: int
2 changes: 2 additions & 0 deletions kclvm/cmd/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion kclvm/parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)?;
Expand Down

0 comments on commit 8b96cf3

Please sign in to comment.