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 0000000000000000000000000000000000000000..251d81cecc9eb77fd1629424a2b5a256d391c1c9 --- /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 256ab38c5f67f53d34cbdcb62b2951cf4763a9a1..271d702126c578b7b2524346be0a31714aa98901 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 0000000000000000000000000000000000000000..3ac2aeda53c802105f702f36375362d3ee154072 --- /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 0000000000000000000000000000000000000000..0dc2dbc6b61c2a5a08563b4a4040f59696736313 --- /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 0000000000000000000000000000000000000000..187bcc0379f8929788b79009a284aa65c440178e --- /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 0000000000000000000000000000000000000000..0dc2dbc6b61c2a5a08563b4a4040f59696736313 --- /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 0000000000000000000000000000000000000000..8cdf8d2925079684845d05d80157a1ee7318dadc --- /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 0000000000000000000000000000000000000000..ac03e52b47a6a944c2f0084a74fb3e5f2967a4ba --- /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 0000000000000000000000000000000000000000..44ac1386a2dec7c0a390077a55ab0400caaff024 --- /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 5135605ddd10eed01df794155f7692a79ab9b361..cdf81743d14688fcc528a7200c7044635662e959 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 ddc62cfa902ff1fa7aea6fe6bea89b3aa570b0fb..f1bbc6190ca25bcf237a6a399291f1994662ae27 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 98b8a310c435e837fc5d70e12a8df899af5b7ec6..262142eb2b8b19ef2c69d79a6554b603bd391ba0 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 aee3ec322f51d541e353621cf751c034c769911b..aa7ee7e05975ec83b8cb961952a56f62a0ccbc53 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 f813de7fac5c62bb3c9e2705c7e92e25e9ba1cc8..fc79e68de9ab4a0eae596dd62cc547415a311ba9 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 7216d0e0d058e7ee4dda89edebf0167b55170228..7be0b69e54d2b237b87b63ee685b93b6f8904253 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 0000000000000000000000000000000000000000..d131a732d6742c60dd03bd766db31fa00d5f1711 --- /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 0000000000000000000000000000000000000000..4a50ce3a7c9a1941cf690c57b8add707e779d230 --- /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 0000000000000000000000000000000000000000..0656210ae26c1fb7df0c49cf2c5c3f97b3cefa06 --- /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 0000000000000000000000000000000000000000..91a44c3e256b529106c3821c85ecc08d6db529ee --- /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 0000000000000000000000000000000000000000..bfc72e769d5195537a44b4005494939099e2cae0 --- /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 0000000000000000000000000000000000000000..066539f412e57437071b095724772d38923283ee --- /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 0000000000000000000000000000000000000000..02a7212a6a697979caf641aa3402ca7f74a4fdca --- /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 0000000000000000000000000000000000000000..de4f72ec243b33459e044ccbfc762922fd98bf0e --- /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 0000000000000000000000000000000000000000..a90b6052c1a1c7c5c724937e6e2e0ff2da6c742a --- /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 0000000000000000000000000000000000000000..3828b8c7852040d51e2d2cc427902267d47c7c3c --- /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 0000000000000000000000000000000000000000..839230bcb92a991782b4aa9b1ac932cff6293f4b --- /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 0000000000000000000000000000000000000000..c9f8aa500bf03e431a4565ab535bef6cfed9d5f3 --- /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 0000000000000000000000000000000000000000..3f30c74673af738822037bc2cbdd3c7d0354f7ce --- /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 0000000000000000000000000000000000000000..f3ba13652bf4bd38d0a39fd9c3071cfe6f693507 --- /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 0000000000000000000000000000000000000000..9617bdd65075f0b892af25a1c782b42bfee1cd76 --- /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 5df927be264e7d60d0edaf70599d4c1d0dcd468b..07a1b15d62721593b15b0ffceaa93d270426f526 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 f25b92d68c45dbacd9aa6bb8e6bfb690ff8d5961..44d5c96b874b5572282cefa16e74b09fa9430dc5 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 7ac976556f0007b74c989f75209c4c74165fbfa9..151305b84ca324efd891d6bb52a2db566ad48cd4 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 d60f189687227f3291b65c947f597706431d357c..5e8d290119e55ebe3f5cb7c4e453b7e4b6569700 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 7c9147477b930ca08d56d861cadfd5548c00f55c..9671014e38604c87851fc26425cfa9cb9a1925c8 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 1ed086709c10b3c19b305989140a8fc3ac00cd84..beadb143c87fc1736c74abf354cc08971faca7c0 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 7635c3492ce335c45c3d15eda40984bd308b6179..0b175ec2eec6b705932a1ea88e8b20d0b5705662 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 a49ed68cea1ab67d5c66fb26749de664613f2b3c..a9f9aee86a4c5d5ec254c8163441af9f52ccc0a9 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 f76b0e609454970672b46ad2a7e1c06ca931fb9e..f56e4cf3810ea1b11178239a86a11562d23ebc72 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 d1b989a107437f65b4e16c3fa508b7dd0fe77649..4d83418bd6e426c98c33125144936bf6675dd3ad 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 f3bd2c0e98bf2f7324c8c8359711aaa42979854f..7633d6f55452aa9ea56130b837be05d652b420d3 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 0000000000000000000000000000000000000000..cd5523b4cd2ff7a996d2990e703aa88e12cfe5fe --- /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 0000000000000000000000000000000000000000..bd88e5d86e3c579d5294f61c714d1268b606e1fe --- /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 0000000000000000000000000000000000000000..bbaddb89a5df8c12848cc661a261397c55b53853 --- /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 0000000000000000000000000000000000000000..cd5523b4cd2ff7a996d2990e703aa88e12cfe5fe --- /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 0000000000000000000000000000000000000000..336d1ef0bdc7386ede69b574ac0435c085758c92 --- /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 0000000000000000000000000000000000000000..48787bb60e44815d32f2786a9c7da8560b3cca3e --- /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 0000000000000000000000000000000000000000..d5f7930d112284211ee6fe6878e55dcd13d1bfa4 --- /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 0000000000000000000000000000000000000000..350d66b9842a751f39fa17aae4733e2a93de15b7 --- /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 0000000000000000000000000000000000000000..8f9a98ba8b9cdfee2eca8ea83208ada56f5aee21 --- /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 0000000000000000000000000000000000000000..ddeba0d4ec94b1a642ea4a016da040f8a2a320d3 --- /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 0000000000000000000000000000000000000000..64303bf0e8d626ac932664581148afe59117d372 --- /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 0000000000000000000000000000000000000000..7b62626ec44337b4c1af1e9da8963aa358aaf24b --- /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 0000000000000000000000000000000000000000..bdcaa7b64a962dce9a75115958ee1cc2559e26c1 --- /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 0000000000000000000000000000000000000000..d56758fc40b681ed7754caaa44d4b92e345d9251 --- /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 0000000000000000000000000000000000000000..78fe632465ba73ba87381e2ea710aac26465781e --- /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 0000000000000000000000000000000000000000..d70b554a3a54d744ef08f2b8d33fcd5aede964e1 --- /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 0000000000000000000000000000000000000000..620b3cda15e81efbfaad095d5d3bde672ab28ade --- /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 0000000000000000000000000000000000000000..38c8be93243a77c3f2b21bea9bff23238f5718c6 --- /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 a94893f7dabfe1008c8788b45d0633e9a10ec63c..d1b02d6323ee2eb19a350a0e5004ed3eb23eab4b 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