From 3b0e53c2bac85068e6abfb124647e7d70d53b7ae Mon Sep 17 00:00:00 2001 From: Vladimir Lind Date: Thu, 11 Sep 2025 15:10:26 +0300 Subject: [PATCH] CTS tests chapter 4.3 Reason: CTS tests development Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICXOS1 Signed-off-by: Vladimir Lind --- .../module_level_scope/module_level.ets | 43 +++++++++++++ .../module_level_scope/module_to_export.ets | 63 +++++++++++++++++++ .../module_level_scope/module_to_import.ets | 31 +++++++++ .../module_to_import.params.yaml | 48 ++++++++++++++ .../module_level_scope/module_to_import_n.ets | 26 ++++++++ .../module_to_import_n.params.yaml | 25 ++++++++ .../namespace_to_export.ets | 37 +++++++++++ .../namespace_to_import.ets | 31 +++++++++ .../namespace_to_import.params.yaml | 56 +++++++++++++++++ 9 files changed, 360 insertions(+) create mode 100644 static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_level.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_to_export.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_to_import.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_to_import.params.yaml create mode 100644 static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_to_import_n.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_to_import_n.params.yaml create mode 100644 static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/namespace_level_scope/namespace_to_export.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/namespace_level_scope/namespace_to_import.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/namespace_level_scope/namespace_to_import.params.yaml diff --git a/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_level.ets b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_level.ets new file mode 100644 index 0000000000..db3122611e --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_level.ets @@ -0,0 +1,43 @@ +/*--- +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 + +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: Separate module scope +---*/ + +let x = 1; + +function foo(): int { + return x - 1; +} + +class C { + y: int = x + 1; +} + +interface I { + z(): int { + return x * 3; + } +} + +class D implements I {} + +function main(): void { + arktest.assertEQ( x, 1 ) + arktest.assertEQ( new C().y, 2 ) + arktest.assertEQ( new D().z(), 3 ) + arktest.assertEQ( foo(), 0 ) +} diff --git a/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_to_export.ets b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_to_export.ets new file mode 100644 index 0000000000..aa282431e4 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_to_export.ets @@ -0,0 +1,63 @@ +/*--- +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 scope to export +tags: [not-a-test, compily-only] +---*/ + +export let x = 1; + +const y = 2; + +export function foo(): int { + let y = x + return y - 1; +} + +function bar(): void { + let b = x; +}; + +export class C { + y: int = x + 1; +} + +class Z { + z: int; +} + +export interface I { + zzz(): int { + let y = x + return y * 3; + } +} + +export class D implements I { + f: int = 4 +} + +interface J { + zz(): int { + let j = x + return j * 3; + } +} + +class F implements J { + f: int; +} + diff --git a/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_to_import.ets b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_to_import.ets new file mode 100644 index 0000000000..9dcc96d882 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_to_import.ets @@ -0,0 +1,31 @@ +/*--- +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 + +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 m in modules %} +/*--- +desc: module scope to import but not exported +files: ['./module_to_export.ets'] +---*/ + +import { {{m.entity}} } from './module_to_export' + +{{m.decl}} + +function main() { + arktest.assertEQ({{m.use}}, {{m.expected}}) +} + +{% endfor %} + diff --git a/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_to_import.params.yaml b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_to_import.params.yaml new file mode 100644 index 0000000000..1479dc64b0 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_to_import.params.yaml @@ -0,0 +1,48 @@ +# 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. + +modules: + - entity: |- + x + use: |- + x + expected: |- + 1 + - entity: |- + foo + use: |- + foo() + expected: |- + 0 + - entity: |- + C + use: |- + (new C()).y + expected: |- + 2 + - entity: |- + I + decl: |- + class A implements I {} + let a: I = new A() + use: |- + a.zzz() + expected: |- + 3 + - entity: |- + D + use: |- + (new D()).f + expected: |- + 4 + diff --git a/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_to_import_n.ets b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_to_import_n.ets new file mode 100644 index 0000000000..e7947c308d --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_to_import_n.ets @@ -0,0 +1,26 @@ +/*--- +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 + +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 entity in modules %} +/*--- +desc: module scope to import but not exported +tags: [compily-only, negative] +files: ['./module_to_export.ets'] +---*/ + +import { {{entity}} } from './module_to_export' + +{% endfor %} + diff --git a/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_to_import_n.params.yaml b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_to_import_n.params.yaml new file mode 100644 index 0000000000..36e5728075 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/module_level_scope/module_to_import_n.params.yaml @@ -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. + +modules: + - y + - bar + - b + - Z + - z + - J + - zz + - j + - zz + - F + - f diff --git a/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/namespace_level_scope/namespace_to_export.ets b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/namespace_level_scope/namespace_to_export.ets new file mode 100644 index 0000000000..074c3a29b5 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/namespace_level_scope/namespace_to_export.ets @@ -0,0 +1,37 @@ +/*--- +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: namespaces scope +tags: [not-a-test, compily-only] +---*/ + +export namespace ExternalSpace { + let x1 = 1 + export let x2 = x1 + const y1 = x1 + 1 + export const y2 = y1 + export function foo(): int { + return x2 + y2; + } + + export namespace EmbeddedSpace { + export let z1 = foo() + export const z2 = y2 + export function bar(): int { + return z1 + z2 + } + } +} diff --git a/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/namespace_level_scope/namespace_to_import.ets b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/namespace_level_scope/namespace_to_import.ets new file mode 100644 index 0000000000..5aac93144c --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/namespace_level_scope/namespace_to_import.ets @@ -0,0 +1,31 @@ +/*--- +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 + +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 n in namespaces %} +/*--- +desc: module scope to import but not exported +files: ['./namespace_to_export.ets'] +---*/ + +import { {{n.entity}} } from './namespace_to_export' + +{{n.decl}} + +function main() { + arktest.assertEQ({{n.use}}, {{n.expected}}) +} + +{% endfor %} + diff --git a/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/namespace_level_scope/namespace_to_import.params.yaml b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/namespace_level_scope/namespace_to_import.params.yaml new file mode 100644 index 0000000000..cacf63ef26 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/04.names_declarations_and_scopes/03.scopes/namespace_level_scope/namespace_to_import.params.yaml @@ -0,0 +1,56 @@ +# 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. + +namespaces: + - entity: |- + ExternalSpace as Ex + use: |- + Ex.x2 + expected: |- + 1 + - entity: |- + ExternalSpace as Ex + use: |- + Ex.y1 + expected: |- + 2 + - entity: |- + ExternalSpace as Ex + use: |- + Ex.y2 + expected: |- + 2 + - entity: |- + ExternalSpace as Ex + use: |- + Ex.foo() + expected: |- + 3 + - entity: |- + ExternalSpace as Ex + use: |- + Ex.EmbeddedSpace.z1 + expected: |- + 3 + - entity: |- + ExternalSpace as Ex + use: |- + Ex.EmbeddedSpace.z2 + expected: |- + 2 + - entity: |- + ExternalSpace as Ex + use: |- + Ex.EmbeddedSpace.bar() + expected: |- + 5 -- Gitee