From 15b2479b3e0e301eb0b16477e048297663aa0473 Mon Sep 17 00:00:00 2001 From: pogromist Date: Wed, 3 Sep 2025 11:46:42 +0300 Subject: [PATCH] ICUXUZ cts update compilation module tests Description: Updated tests for: - 13.2 Import Directives - 13.2.1 Bind All with Qualified Access - 13.2.2 Default Import Binding - 13.2.5 Import Path - 13.4 Declaration Modules - 13.5.1 Exported Declarations Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICUXUZ Test: All required pre-merge tests passed. Results are available in the ggwatcher. Signed-off-by: pogromist --- .../declare_import_all_multiple_files.ets | 35 +++++++++ .../import_all_as.params.yaml | 2 +- .../import_all_multiple_files.ets | 33 +++++++++ .../modules/mod1.d.ets | 25 +++++++ .../modules/mod1.ets | 31 ++++++++ .../modules/mod2.d.ets | 25 +++++++ .../modules/mod2.ets | 31 ++++++++ .../default_import_const_var_binding.ets | 26 +++++++ .../default_import_const_var_binding_neg.ets | 27 +++++++ .../default_import_function_same_name.ets | 2 - ...ts => default_import_variable_binding.ets} | 14 ++-- .../multiple_default_export_2.ets | 5 +- .../multiple_levels_default_export_2.ets | 1 - .../multiple_levels_default_export_3.ets | 1 - .../02.import_directives/import.ets | 2 +- .../02.import_directives/import_self.ets | 24 +++++++ .../02.import_directives/import_utf16.ets | 26 +++++++ .../02.import_directives/modules/mod1.d.ets | 21 ++++++ .../02.import_directives/modules/mod1.ets | 21 ++++++ .../02.import_directives/modules/mod2.d.ets | 21 ++++++ .../02.import_directives/modules/mod2.ets | 21 ++++++ .../02.import_directives/modules/mod3.d.ets | 21 ++++++ .../02.import_directives/modules/mod3.ets | 21 ++++++ .../02.import_directives/modules/mod_def.ets | 21 ++++++ .../02.import_directives/modules/mod_def1.ets | 21 ++++++ .../not_distinguishable_import.ets | 24 +++++++ .../not_distinguishable_import.params.yaml | 44 ++++++++++++ .../02.import_directives/test.ets | 21 ++++++ .../\346\226\207\344\273\266\345\220\215.ets" | 23 ++++++ .../declaration_module.d.ets | 71 +++++++++++++++++++ .../declaration_module.ets | 59 ++++++++++----- .../declaration_modules.ets | 1 + .../declaration_modules.params.yaml | 13 ++-- .../declaration_usage.ets | 6 +- .../declaration_usage2.ets | 6 +- .../declaration_usage3.ets | 18 ++--- .../declaration_usage4.ets | 13 ++-- .../declaration_usage5.ets | 13 ++-- .../declaration_usage6.ets | 13 ++-- .../declaration_usage_neg.ets | 3 +- .../declaration_usage_neg2.ets | 3 +- .../export_target/default_export_1.ets | 30 ++++++++ .../export_target/default_export_2.ets | 30 ++++++++ .../export_target/default_export_3.ets | 30 ++++++++ .../export_target/default_export_4.ets | 30 ++++++++ .../export_target/default_export_neg_1.ets | 27 +++++++ .../export_target/default_export_neg_2.ets | 31 ++++++++ ...fault_export_target_custom_constructor.ets | 36 ++++++++++ ...ault_export_target_default_constructor.ets | 33 +++++++++ .../default_export_target_static_init.ets | 36 ++++++++++ .../multiple_default_declarations.ets | 24 +++++++ .../multiple_default_declarations_declare.ets | 24 +++++++ .../05.top-level_declarations/exported.ets | 28 ++++++++ .../modules/partial_export.d.ets | 25 +++++++ .../modules/partial_export.ets | 35 +++++++++ .../not_exported_n.ets | 29 ++++++++ .../not_exported_n_2.ets | 25 +++++++ .../not_exported_n_3.ets | 30 ++++++++ .../not_exported_n_4.ets | 26 +++++++ .../test-lists/ets-cts/ets-cts-ignored.txt | 10 +++ 60 files changed, 1274 insertions(+), 74 deletions(-) create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/declare_import_all_multiple_files.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/import_all_multiple_files.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/modules/mod1.d.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/modules/mod1.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/modules/mod2.d.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/modules/mod2.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_const_var_binding.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_const_var_binding_neg.ets rename static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/{multiple_default_export_neg_2.ets => default_import_variable_binding.ets} (66%) create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/import_self.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/import_utf16.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod1.d.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod1.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod2.d.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod2.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod3.d.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod3.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod_def.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod_def1.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/not_distinguishable_import.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/not_distinguishable_import.params.yaml create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/test.ets create mode 100644 "static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/\346\226\207\344\273\266\345\220\215.ets" create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_module.d.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_1.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_2.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_3.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_4.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_neg_1.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_neg_2.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_target_custom_constructor.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_target_default_constructor.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_target_static_init.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/multiple_default_declarations.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/multiple_default_declarations_declare.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/exported.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/modules/partial_export.d.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/modules/partial_export.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/not_exported_n.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/not_exported_n_2.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/not_exported_n_3.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/not_exported_n_4.ets diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/declare_import_all_multiple_files.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/declare_import_all_multiple_files.ets new file mode 100644 index 0000000000..251d81cecc --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/declare_import_all_multiple_files.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: ambient import entities from multiple modules using bind all method +files: +- ./modules/mod1.ets +- ./modules/mod1.d.ets +- ./modules/mod2.ets +- ./modules/mod2.d.ets +---*/ + +import * as A from "./modules/mod1.d" +import * as B from "./modules/mod2.d" + +function main() { + arktest.assertEQ(A.foo(), 1) + arktest.assertEQ(A.f, 2) + arktest.assertEQ(new A.C().foo(), 3) + arktest.assertEQ(B.foo(), 4) + arktest.assertEQ(B.f, 5) + arktest.assertEQ(new B.C().foo(), 6) +} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/import_all_as.params.yaml b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/import_all_as.params.yaml index 256ab38c5f..271d702126 100644 --- a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/import_all_as.params.yaml +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/import_all_as.params.yaml @@ -1,4 +1,4 @@ - # Copyright (c) 2021-2025 Huawei Device Co., Ltd. +# Copyright (c) 2021-2025 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/import_all_multiple_files.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/import_all_multiple_files.ets new file mode 100644 index 0000000000..3ac2aeda53 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/import_all_multiple_files.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: import entities from multiple modules using bind all method +files: +- ./modules/mod1.ets +- ./modules/mod2.ets +---*/ + +import * as A from "./modules/mod1" +import * as B from "./modules/mod2" + +function main() { + arktest.assertEQ(A.foo(), 1) + arktest.assertEQ(A.f, 2) + arktest.assertEQ(new A.C().foo(), 3) + arktest.assertEQ(B.foo(), 4) + arktest.assertEQ(B.f, 5) + arktest.assertEQ(new B.C().foo(), 6) +} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/modules/mod1.d.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/modules/mod1.d.ets new file mode 100644 index 0000000000..0dc2dbc6b6 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/modules/mod1.d.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: Module with declarations +tags: [compile-only, not-a-test] +---*/ + +export declare function foo(): int +export declare let f: int +export declare class C { + foo(): int +} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/modules/mod1.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/modules/mod1.ets new file mode 100644 index 0000000000..187bcc0379 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/modules/mod1.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: export multiple different entities +tags: [compile-only, not-a-test] +---*/ + +export function foo(): int { + return 1 +} + +export let f: int = 2 + +export class C { + foo(): int { + return 3 + } +} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/modules/mod2.d.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/modules/mod2.d.ets new file mode 100644 index 0000000000..0dc2dbc6b6 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/modules/mod2.d.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: Module with declarations +tags: [compile-only, not-a-test] +---*/ + +export declare function foo(): int +export declare let f: int +export declare class C { + foo(): int +} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/modules/mod2.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/modules/mod2.ets new file mode 100644 index 0000000000..8cdf8d2925 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/01.bind_all_with_qualified_access/modules/mod2.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: export multiple different entities +tags: [compile-only, not-a-test] +---*/ + +export function foo(): int { + return 4 +} + +export let f: int = 5 + +export class C { + foo(): int { + return 6 + } +} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_const_var_binding.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_const_var_binding.ets new file mode 100644 index 0000000000..ac03e52b47 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_const_var_binding.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: Import default const variable. +files: +- ../../05.top-level_declarations/01.exported_declarations/default_exported_declarations/default_export_const.ets +---*/ + +import {default as const_var} from "../../05.top-level_declarations/01.exported_declarations/default_exported_declarations/default_export_const" + +function main(): void { + arktest.assertEQ(const_var, 2); +} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_const_var_binding_neg.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_const_var_binding_neg.ets new file mode 100644 index 0000000000..44ac1386a2 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_const_var_binding_neg.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: Edit import default const variable. +files: +- ../../05.top-level_declarations/01.exported_declarations/default_exported_declarations/default_export_const.ets +tags: [compile-only, negative] +---*/ + +import {default as const_var} from "../../05.top-level_declarations/01.exported_declarations/default_exported_declarations/default_export_const" + +function main(): void { + const_var = 3 +} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_function_same_name.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_function_same_name.ets index 5135605ddd..cdf81743d1 100644 --- a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_function_same_name.ets +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_function_same_name.ets @@ -17,8 +17,6 @@ desc: Import a default exported function with namespace import. files: - ../../05.top-level_declarations/01.exported_declarations/default_exported_declarations/default_export_function.ets -tags: -- compile-only ---*/ import {default as TestFunc} from "../../05.top-level_declarations/01.exported_declarations/default_exported_declarations/default_export_function" diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/multiple_default_export_neg_2.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_variable_binding.ets similarity index 66% rename from static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/multiple_default_export_neg_2.ets rename to static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_variable_binding.ets index ddc62cfa90..f1bbc6190c 100644 --- a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/multiple_default_export_neg_2.ets +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/default_import_variable_binding.ets @@ -14,15 +14,15 @@ */ /*--- -desc: |- - Export 2 default entities from the same module, one entity imported from another module. - Only one default export is allowed in a module. -tags: [compile-only] +desc: Import a default exported variable. files: - ../../05.top-level_declarations/01.exported_declarations/default_exported_declarations/default_export_variable.ets ---*/ -import test_var from "../../05.top-level_declarations/01.exported_declarations/default_exported_declarations/default_export_variable" +import {default as i_test_var} from "../../05.top-level_declarations/01.exported_declarations/default_exported_declarations/default_export_variable" -export test_var; -export default let i: string = test_var; +function main(): void { + arktest.assertEQ(i_test_var, "default_variable"); + i_test_var = "updated" + arktest.assertEQ(i_test_var, "updated"); +} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/multiple_default_export_2.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/multiple_default_export_2.ets index 98b8a310c4..262142eb2b 100644 --- a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/multiple_default_export_2.ets +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/multiple_default_export_2.ets @@ -17,7 +17,6 @@ desc: |- Module imports default entity A from another module, then exports own default entity B. Only one default export is allowed in a module. -tags: [compile-only] files: - ../../05.top-level_declarations/01.exported_declarations/default_exported_declarations/default_export_variable.ets ---*/ @@ -25,3 +24,7 @@ files: import test_var from "../../05.top-level_declarations/01.exported_declarations/default_exported_declarations/default_export_variable" export default let i: string = test_var; + +function main() { + arktest.assertEQ(i, test_var) +} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/multiple_levels_default_export_2.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/multiple_levels_default_export_2.ets index aee3ec322f..aa7ee7e059 100644 --- a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/multiple_levels_default_export_2.ets +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/multiple_levels_default_export_2.ets @@ -15,7 +15,6 @@ /*--- desc: Import default entity from module A, imported from module B being non-default. -tags: [compile-only] files: - ../../05.top-level_declarations/01.exported_declarations/default_exported_declarations/default_export_type_2_level_2.ets ---*/ diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/multiple_levels_default_export_3.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/multiple_levels_default_export_3.ets index f813de7fac..fc79e68de9 100644 --- a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/multiple_levels_default_export_3.ets +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/02.default_import_binding/multiple_levels_default_export_3.ets @@ -15,7 +15,6 @@ /*--- desc: Import default entity from module A, imported from module B. -tags: [compile-only] files: - ../../05.top-level_declarations/01.exported_declarations/default_exported_declarations/default_export_type_2_level_3.ets ---*/ diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/import.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/import.ets index 7216d0e0d0..7be0b69e54 100644 --- a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/import.ets +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/import.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025-2025 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/import_self.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/import_self.ets new file mode 100644 index 0000000000..d131a732d6 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/import_self.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: >- + A compile-time error occurs if compilation unit imports itself directly. + importPath refers to the file in which the current module is stored. +tags: [compile-only, negative] +---*/ + +import foo from "./import_self" +export function foo() { } diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/import_utf16.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/import_utf16.ets new file mode 100644 index 0000000000..4a50ce3a7c --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/import_utf16.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: Import from file with utf-16 chars +files: +- ./文件名.ets +---*/ + +import A from "./文件名.ets" + +function main() { + arktest.assertEQ(new A().foo(), 7) +} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod1.d.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod1.d.ets new file mode 100644 index 0000000000..0656210ae2 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod1.d.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: Export single function +tags: [compile-only, not-a-test] +---*/ + +export declare function foo() diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod1.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod1.ets new file mode 100644 index 0000000000..91a44c3e25 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod1.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: Export single function +tags: [compile-only, not-a-test] +---*/ + +export function foo() { } diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod2.d.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod2.d.ets new file mode 100644 index 0000000000..bfc72e769d --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod2.d.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: Ambient export single function +tags: [compile-only, not-a-test] +---*/ + +export declare function foo() diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod2.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod2.ets new file mode 100644 index 0000000000..066539f412 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod2.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: export single function +tags: [compile-only, not-a-test] +---*/ + +export function foo() { } diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod3.d.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod3.d.ets new file mode 100644 index 0000000000..02a7212a6a --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod3.d.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: Ambient export single function +tags: [compile-only, not-a-test] +---*/ + +export declare function boo() diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod3.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod3.ets new file mode 100644 index 0000000000..de4f72ec24 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod3.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: export single function +tags: [compile-only, not-a-test] +---*/ + +export function boo() { } diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod_def.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod_def.ets new file mode 100644 index 0000000000..a90b6052c1 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod_def.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: Export default function +tags: [compile-only, not-a-test] +---*/ + +export default function foo() { } diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod_def1.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod_def1.ets new file mode 100644 index 0000000000..3828b8c785 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/modules/mod_def1.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: Export default function +tags: [compile-only, not-a-test] +---*/ + +export default function boo() { } diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/not_distinguishable_import.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/not_distinguishable_import.ets new file mode 100644 index 0000000000..839230bcb9 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/not_distinguishable_import.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{% for c in cases %} +/*--- +desc: CTE if declaration added to the scope of a module or a package by a binding is not distinguishable +tags: [compile-only, negative] +---*/ + +{{c.decl}} + +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/not_distinguishable_import.params.yaml b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/not_distinguishable_import.params.yaml new file mode 100644 index 0000000000..c9f8aa500b --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/not_distinguishable_import.params.yaml @@ -0,0 +1,44 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +cases: + - doc: import different files with the same function names. Used all and selective bindings + decl: |- + import {foo} as A from "./modules/mod1" + import * as A from "./modules/mod2" + + - doc: import all, same function names from different files + decl: |- + import * as A from "./modules/mod2" + import * as A from "./modules/mod3" + + - doc: import default + decl: |- + import * as A from "./modules/mod_def" + import {default as A} from "./modules/mod_def1" + + - doc: import default in a different order + decl: |- + import {default as A} from "./modules/mod_def1" + import * as A from "./modules/mod_def" + + - doc: ambient import same function + decl: |- + import foo from "./modules/mod1.d" + import foo from "./modules/mod2.d" + + - doc: ambient import same function with selective binding + decl: |- + import {foo as A} from "./modules/mod2.d" + import {boo as A} from "./modules/mod3.d" diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/test.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/test.ets new file mode 100644 index 0000000000..3f30c74673 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/test.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: Self imported file +tags: [compile-only, negative] +---*/ + +import * as __main from "./test" diff --git "a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/\346\226\207\344\273\266\345\220\215.ets" "b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/\346\226\207\344\273\266\345\220\215.ets" new file mode 100644 index 0000000000..f3ba13652b --- /dev/null +++ "b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/02.import_directives/\346\226\207\344\273\266\345\220\215.ets" @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/*--- +tags: [not-a-test, compile-only] +---*/ + +export class A { + foo(): int { + return 7 + } +} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_module.d.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_module.d.ets new file mode 100644 index 0000000000..9617bdd650 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_module.d.ets @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/*--- +desc: >- + Sample from spec, Namespaces with identical namespace names in a single compilation unit + merge their exported declarations into a single namespace. +tags: [compile-only, not-a-test] +---*/ + +export declare namespace NS_A { + export function foo(): int +} + +export declare namespace NS_B { + export function foo(): int +} + +export declare class A { + f: int +} + +export declare class B { + a: A +} + +declare class C { } + +declare class DD { + public static fdd(): int +} + +declare class EE { + fee(): string +} + +export {DD, EE as ZZ} + +export declare class Person { + name: string + age: number + constructor(name: string, age: number) + getName(): string + getAge(): number + static createDefault(): Person +} + +export declare function process_field(p: A): int + +export declare type Matrix = number[][] +export declare type Handler = (s: string, no: number) => string + +export declare type Predicate = (x: T) => Boolean +export declare type NullableNumber = Number | null | undefined +export declare type Dictionary = Map +export declare type MapOfString = Map +export declare type AAA = Array> +export declare type AAA2 = string | Array> diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_module.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_module.ets index 5df927be26..07a1b15d62 100644 --- a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_module.ets +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_module.ets @@ -21,40 +21,61 @@ desc: >- tags: [compile-only, not-a-test] ---*/ -export declare namespace NS_A{ - export function foo(): void +export namespace NS_A{ + export function foo(): int { + return 1 + } } export namespace NS_B{ - export declare function foo(): void + export function foo(): int { + return 2 + } } -export declare class A {} +export class A { + f: int = 7 +} -export declare class B { - public a: A // the field is exported but its type is not +export class B { + public a: A = new A() // the field is exported but its type is not } -declare class C {} +export class C {} -declare class DD { - public static fdd(): void +export class DD { + public static fdd(): int { + return 3 + } } -declare class EE { - public fee(): string +export class EE { + public fee(): string { + return "EE str" + } } -export {DD, EE as ZZ} - -export declare class Person { - constructor(name: string, age: number); - getName(): string; - getAge(): number; - static createDefault(): Person; +export class Person { + name: string + age: number + constructor(name: string, age: number) { + this.name = name + this.age = age + } + getName(): string { + return this.name + } + getAge(): number { + return this.age + } + static createDefault(): Person { + return new Person("name not set", 999) + } } -export declare function process_field(p: A): void +export function process_field(p: A): int { + return 4 +} export type Matrix = number[][] export type Handler = (s: string, no: number) => string diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_modules.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_modules.ets index f25b92d68c..44d5c96b87 100644 --- a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_modules.ets +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_modules.ets @@ -19,6 +19,7 @@ desc: >- A namespace declaration introduces the qualified name to be used as a qualifier for access to each exported entity of a namespace. Next cases tests basic top-level declarations. files: + - ./declaration_module.d.ets - ./declaration_module.ets ---*/ diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_modules.params.yaml b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_modules.params.yaml index 7ac976556f..151305b84c 100644 --- a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_modules.params.yaml +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_modules.params.yaml @@ -15,28 +15,28 @@ cases: #0. Type parameter number[][] - imp: |- - import * as dm from "./declaration_module.ets" + import * as dm from "./declaration_module.d.ets" use: |- let myMatrix: dm.Matrix = [[0.0]]; arktest.assertTrue(typeof myMatrix == 'object' ) ; #1. Type parameter with arrow function - imp: |- - import * as dm from "./declaration_module.ets" + import * as dm from "./declaration_module.d.ets" use: |- let myHandler: dm.Handler = (s: string, no: number) => "ret_string"; arktest.assertTrue(typeof myHandler == 'function' ) #2. Type parameter with generic and arrow function - imp: |- - import * as dm from "./declaration_module.ets" + import * as dm from "./declaration_module.d.ets" use: |- let myPredicate: dm.Predicate = (s: string) => true; arktest.assertTrue(typeof myPredicate == 'function' ) #3. Type parameter Nullable - imp: |- - import * as dm from "./declaration_module.ets" + import * as dm from "./declaration_module.d.ets" use: |- let myNumber: dm.NullableNumber; arktest.assertTrue( (typeof myNumber as string) == 'undefined' ); @@ -47,15 +47,14 @@ cases: #4. Type parameter with generic - imp: |- - import * as dm from "./declaration_module.ets" + import * as dm from "./declaration_module.d.ets" use: |- let myMapOfString: dm.MapOfString = new Map(); arktest.assertTrue(typeof myMapOfString == 'object' ); #5. Type parameter with generic - imp: |- - import * as dm from "./declaration_module.ets" + import * as dm from "./declaration_module.d.ets" use: |- let myAAA: dm.AAA = new Array>; arktest.assertTrue(typeof myAAA == 'object' ); - diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage.ets index d60f189687..5e8d290119 100644 --- a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage.ets +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage.ets @@ -15,14 +15,14 @@ /*--- desc: First simple sample from spec -tags: [compile-only] files: - ./declaration_module.ets +- ./declaration_module.d.ets ---*/ // Module which uses B and process_field -import * as m from "./declaration_module.ets" +import * as m from "./declaration_module.d" function main() { - m.NS_A.foo(); + arktest.assertEQ(m.NS_A.foo(), 1); } diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage2.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage2.ets index 7c9147477b..9671014e38 100644 --- a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage2.ets +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage2.ets @@ -15,14 +15,14 @@ /*--- desc: First simple sample from spec -tags: [compile-only] files: - ./declaration_module.ets +- ./declaration_module.d.ets ---*/ // Module which uses B and process_field -import * as m from "./declaration_module.ets" +import * as m from "./declaration_module.d" function main() { - m.NS_B.foo(); + arktest.assertEQ(m.NS_B.foo(), 2); } diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage3.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage3.ets index 1ed086709c..beadb143c8 100644 --- a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage3.ets +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage3.ets @@ -14,20 +14,22 @@ */ /*--- -desc: A namespace declaration introduces the qualified name to be used as a qualifier - for access to each exported entity of a namespace. Next cases tests basic top-level - declarations. -tags: [compile-only] +desc: >- + A namespace declaration introduces the qualified name to be used as a qualifier + for access to each exported entity of a namespace. Next cases tests basic top-level + declarations. files: - ./declaration_module.ets +- ./declaration_module.d.ets ---*/ -import * as dm from "./declaration_module.ets" +import * as dm from "./declaration_module.d" function main() { let myPerson = new dm.Person("Name", 41); - myPerson.getName(); - myPerson.getAge(); + arktest.assertEQ(myPerson.getName(), "Name"); + arktest.assertEQ(myPerson.getAge(), 41); let default_myPerson = dm.Person.createDefault(); - arktest.assertEQ(default_myPerson, 'function'); + arktest.assertEQ(default_myPerson.name, "name not set"); + arktest.assertEQ(default_myPerson.age, 999); } diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage4.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage4.ets index 7635c3492c..0b175ec2ee 100644 --- a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage4.ets +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage4.ets @@ -14,17 +14,18 @@ */ /*--- -desc: A namespace declaration introduces the qualified name to be used as a qualifier - for access to each exported entity of a namespace. Next cases tests basic top-level - declarations. -tags: [compile-only] +desc: >- + A namespace declaration introduces the qualified name to be used as a qualifier + for access to each exported entity of a namespace. Next cases tests basic top-level + declarations. files: - ./declaration_module.ets +- ./declaration_module.d.ets ---*/ -import * as dm from "./declaration_module.ets" +import * as dm from "./declaration_module.d" function main() { let myZZ = new dm.ZZ(); - arktest.assertEQ(typeof myZZ.fee(), 'function'); + arktest.assertEQ(myZZ.fee(), "EE str"); } diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage5.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage5.ets index a49ed68cea..a9f9aee86a 100644 --- a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage5.ets +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage5.ets @@ -14,16 +14,17 @@ */ /*--- -desc: A namespace declaration introduces the qualified name to be used as a qualifier - for access to each exported entity of a namespace. Next cases tests basic top-level - declarations. -tags: [compile-only] +desc: >- + A namespace declaration introduces the qualified name to be used as a qualifier + for access to each exported entity of a namespace. Next cases tests basic top-level + declarations. files: - ./declaration_module.ets +- ./declaration_module.d.ets ---*/ -import * as m from "./declaration_module.ets" +import * as m from "./declaration_module.d" function main() { - let aa = new m.A() // A instance is created + arktest.assertEQ(new m.A().f, 7) } diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage6.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage6.ets index f76b0e6094..f56e4cf381 100644 --- a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage6.ets +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage6.ets @@ -14,17 +14,18 @@ */ /*--- -desc: A namespace declaration introduces the qualified name to be used as a qualifier - for access to each exported entity of a namespace. Next cases tests basic top-level - declarations. -tags: [compile-only] +desc: >- + A namespace declaration introduces the qualified name to be used as a qualifier + for access to each exported entity of a namespace. Next cases tests basic top-level + declarations. files: - ./declaration_module.ets +- ./declaration_module.d.ets ---*/ -import * as dm from "./declaration_module.ets" +import * as dm from "./declaration_module.d" function main() { let b = new dm.B() // B instance is created - dm.process_field(b.a) // exported field is passed to function as an argument + arktest.assertEQ(dm.process_field(b.a), 4) // exported field is passed to function as an argument } diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage_neg.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage_neg.ets index d1b989a107..4d83418bd6 100644 --- a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage_neg.ets +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage_neg.ets @@ -18,9 +18,10 @@ desc: ES2PANDA_FAIL, TypeError, C type does not exist. tags: [compile-only, negative] files: - ./declaration_module.ets +- ./declaration_module.d.ets ---*/ // Module describes C, but C not exported -import * as m from "./declaration_module.ets" +import * as m from "./declaration_module.d" let c = new m.C // compile-time error as C is not exported diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage_neg2.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage_neg2.ets index f3bd2c0e98..7633d6f554 100644 --- a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage_neg2.ets +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/04.declaration_modules/declaration_usage_neg2.ets @@ -18,10 +18,11 @@ desc: ES2PANDA_FAIL, TypeError, fdd is a static property of DD tags: [compile-only, negative] files: - ./declaration_module.ets +- ./declaration_module.d.ets ---*/ // public static fdd(): void -import * as dm from "./declaration_module.ets" +import * as dm from "./declaration_module.d" let myDD = new dm.DD() myDD.fdd() diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_1.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_1.ets new file mode 100644 index 0000000000..cd5523b4cd --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_1.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: >- + Export default target effectively means that an anonymous constant variable is created with a value + equal to the value of the expression evaluation result. The export can be imported only by providing + a name for the constant variable that is exported by using this export directive. + Otherwise, a compile-time error occurs. +files: +- ./default_export_target_custom_constructor.ets +---*/ + +import {default as a} from "./default_export_target_custom_constructor" + +function main() { + arktest.assertEQ(a.foo(), 7) +} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_2.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_2.ets new file mode 100644 index 0000000000..bd88e5d86e --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_2.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: >- + Export default target effectively means that an anonymous constant variable is created with a value + equal to the value of the expression evaluation result. The export can be imported only by providing + a name for the constant variable that is exported by using this export directive. + Otherwise, a compile-time error occurs. +files: +- ./default_export_target_default_constructor.ets +---*/ + +import {default as a} from "./default_export_target_default_constructor" + +function main() { + arktest.assertEQ(a.foo(), 9) +} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_3.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_3.ets new file mode 100644 index 0000000000..bbaddb89a5 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_3.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: >- + Export default target effectively means that an anonymous constant variable is created with a value + equal to the value of the expression evaluation result. The export can be imported only by providing + a name for the constant variable that is exported by using this export directive. + Otherwise, a compile-time error occurs. +files: +- ./default_export_target_static_init.ets +---*/ + +import {default as a} from "./default_export_target_static_init" + +function main() { + arktest.assertEQ(a.foo(), 5) +} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_4.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_4.ets new file mode 100644 index 0000000000..cd5523b4cd --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_4.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: >- + Export default target effectively means that an anonymous constant variable is created with a value + equal to the value of the expression evaluation result. The export can be imported only by providing + a name for the constant variable that is exported by using this export directive. + Otherwise, a compile-time error occurs. +files: +- ./default_export_target_custom_constructor.ets +---*/ + +import {default as a} from "./default_export_target_custom_constructor" + +function main() { + arktest.assertEQ(a.foo(), 7) +} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_neg_1.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_neg_1.ets new file mode 100644 index 0000000000..336d1ef0bd --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_neg_1.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: >- + Export default target effectively means that an anonymous constant variable is created with a value + equal to the value of the expression evaluation result. The export can be imported only by providing + a name for the constant variable that is exported by using this export directive. + Otherwise, a compile-time error occurs. +files: +- ./default_export_target_custom_constructor.ets +tags: [compile-only, negative] +---*/ + +import * as a from "./default_export_target_custom_constructor" diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_neg_2.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_neg_2.ets new file mode 100644 index 0000000000..48787bb60e --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_neg_2.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: >- + Export default target effectively means that an anonymous constant variable is created with a value + equal to the value of the expression evaluation result. The export can be imported only by providing + a name for the constant variable that is exported by using this export directive. + Otherwise, a compile-time error occurs. +files: +- ./default_export_target_custom_constructor.ets +tags: [compile-only, negative] +---*/ + +import {default as a} from "./default_export_target_default_constructor" + +function main() { + a = new A() +} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_target_custom_constructor.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_target_custom_constructor.ets new file mode 100644 index 0000000000..d5f7930d11 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_target_custom_constructor.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: >- + Export default target effectively means that an anonymous constant variable is created with a value + equal to the value of the expression evaluation result. The export can be imported only by providing + a name for the constant variable that is exported by using this export directive. + Otherwise, a compile-time error occurs. +tags: +- compile-only +- not-a-test +---*/ + +class A { + c: int + constructor(c: int) { + this.c = c + } + foo () { + return this.c + } +} +export default new A(7) diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_target_default_constructor.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_target_default_constructor.ets new file mode 100644 index 0000000000..350d66b984 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_target_default_constructor.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: >- + Export default target effectively means that an anonymous constant variable is created with a value + equal to the value of the expression evaluation result. The export can be imported only by providing + a name for the constant variable that is exported by using this export directive. + Otherwise, a compile-time error occurs. +tags: +- compile-only +- not-a-test +---*/ + +class A { + c: int = 9 + foo(): int { + return this.c + } +} +export default new A() diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_target_static_init.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_target_static_init.ets new file mode 100644 index 0000000000..8f9a98ba8b --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/export_target/default_export_target_static_init.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: >- + Export default target effectively means that an anonymous constant variable is created with a value + equal to the value of the expression evaluation result. The export can be imported only by providing + a name for the constant variable that is exported by using this export directive. + Otherwise, a compile-time error occurs. +tags: +- compile-only +- not-a-test +---*/ + +class A { + static c: int + static { + A.c = 5 + } + foo() { + return A.c + } +} +export default new A() diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/multiple_default_declarations.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/multiple_default_declarations.ets new file mode 100644 index 0000000000..ddeba0d4ec --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/multiple_default_declarations.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: A compile-time error occurs if more than one top-level declaration is marked as default. +tags: +- compile-only +- negative +---*/ + +export default let i: int +export default class TestClass {} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/multiple_default_declarations_declare.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/multiple_default_declarations_declare.ets new file mode 100644 index 0000000000..64303bf0e8 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/01.exported_declarations/default_exported_declarations/multiple_default_declarations_declare.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: A compile-time error occurs if more than one top-level declaration is marked as default. +tags: +- compile-only +- negative +---*/ + +export declare default let i: int +export declare default class TestClass {} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/exported.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/exported.ets new file mode 100644 index 0000000000..7b62626ec4 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/exported.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: Not exported item could still be used inside the module. +tags: [compile-only, negative] +files: +- ./modules/partial_export.ets +- ./modules/partial_export.d.ets +---*/ + +import * as A from "./modules/partial_export.d" + +function main() { + arktest.assertEQ(A.goo(), 2) +} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/modules/partial_export.d.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/modules/partial_export.d.ets new file mode 100644 index 0000000000..bdcaa7b64a --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/modules/partial_export.d.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: The declarations not marked as exported can be used only inside the compilation unit they are declared in. +tags: [compile-only, not-a-test] +---*/ + +declare function boo(): int + +export declare function goo(): int { + return boo() +} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/modules/partial_export.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/modules/partial_export.ets new file mode 100644 index 0000000000..d56758fc40 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/modules/partial_export.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: The declarations not marked as exported can be used only inside the compilation unit they are declared in. +tags: [compile-only, not-a-test] +---*/ + +export function boo(): int { + return 1 +} + +function foo(): int { + return 2 +} + +export function goo(): int { + return 3 +} + +function noo(): int { + return 4 +} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/not_exported_n.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/not_exported_n.ets new file mode 100644 index 0000000000..78fe632465 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/not_exported_n.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: >- + The declarations not marked as exported can be used only inside the compilation unit they are declared in. + Import all, call not exported item. +tags: [compile-only, negative] +files: +- ./modules/partial_export.ets +---*/ + +import * as A from "./modules/partial_export" + +function main() { + A.foo() +} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/not_exported_n_2.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/not_exported_n_2.ets new file mode 100644 index 0000000000..d70b554a3a --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/not_exported_n_2.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: >- + The declarations not marked as exported can be used only inside the compilation unit they are declared in. + Import not exported item using selective binding. +tags: [compile-only, negative] +files: +- ./modules/partial_export.ets +---*/ + +import {foo} from "./modules/partial_export" diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/not_exported_n_3.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/not_exported_n_3.ets new file mode 100644 index 0000000000..620b3cda15 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/not_exported_n_3.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: >- + The declarations not marked as exported can be used only inside the compilation unit they are declared in. + Call not exported declared item using import all directive. +tags: [compile-only, negative] +files: +- ./modules/partial_export.ets +- ./modules/partial_export.d.ets +---*/ + +import * as A from "./modules/partial_export.d" + +function main() { + A.foo() +} diff --git a/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/not_exported_n_4.ets b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/not_exported_n_4.ets new file mode 100644 index 0000000000..38c8be9324 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/13.compilation_units/05.top-level_declarations/not_exported_n_4.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*--- +desc: >- + The declarations not marked as exported can be used only inside the compilation unit they are declared in. + Import not exported declared item using selective binding. +tags: [compile-only, negative] +files: +- ./modules/partial_export.ets +- ./modules/partial_export.d.ets +---*/ + +import {foo} from "./modules/partial_export.d" diff --git a/static_core/plugins/ets/tests/test-lists/ets-cts/ets-cts-ignored.txt b/static_core/plugins/ets/tests/test-lists/ets-cts/ets-cts-ignored.txt index a94893f7da..d1b02d6323 100644 --- a/static_core/plugins/ets/tests/test-lists/ets-cts/ets-cts-ignored.txt +++ b/static_core/plugins/ets/tests/test-lists/ets-cts/ets-cts-ignored.txt @@ -1554,6 +1554,16 @@ 11.enumerations/01.enumeration_integer_values/enum_long_22.ets 11.enumerations/01.enumeration_integer_values/enum_long_23.ets +#29393 +13.compilation_units/02.import_directives/import_utf16.ets + +#29515 +13.compilation_units/02.import_directives/not_distinguishable_import_2.ets +13.compilation_units/02.import_directives/not_distinguishable_import_3.ets + +#26714 +13.compilation_units/02.import_directives/test.ets + #29393 13.compilation_units/07.export_directives/02.single_export_directive/re_export_test_3.ets 13.compilation_units/07.export_directives/02.single_export_directive/re_export_test_4.ets -- Gitee