From ee90c3832c6f9e3a0890dc415def1a02a4d16902 Mon Sep 17 00:00:00 2001 From: michaelfrost Date: Fri, 12 Sep 2025 12:17:57 +0300 Subject: [PATCH] Update tests for 8.5 Description: Tests for 8.5 if Statements were updated. Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICXR64 Test: All pre-merge tests passed. Results are available in the ggwatcher. Signed-off-by: michaelfrost Change-Id: I685add9f94fed3839f21e6e9b7fa33ac8bddfbee --- .../05.if_statements/spec_if_1.ets | 26 ++++++++++++ .../05.if_statements/spec_if_1.params.yaml | 19 +++++++++ .../05.if_statements/spec_if_2.ets | 27 +++++++++++++ .../05.if_statements/spec_if_2.params.yaml | 19 +++++++++ .../05.if_statements/spec_if_3.ets | 37 +++++++++++++++++ .../05.if_statements/spec_if_3.params.yaml | 17 ++++++++ .../05.if_statements/spec_if_3_negative.ets | 40 +++++++++++++++++++ .../spec_if_3_negative.params.yaml | 17 ++++++++ 8 files changed, 202 insertions(+) create mode 100644 static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_1.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_1.params.yaml create mode 100644 static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_2.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_2.params.yaml create mode 100644 static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_3.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_3.params.yaml create mode 100644 static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_3_negative.ets create mode 100644 static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_3_negative.params.yaml diff --git a/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_1.ets b/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_1.ets new file mode 100644 index 0000000000..209cc3424e --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_1.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. +---*/ + +{% for c in cases %} +/*--- +desc: Any else corresponds to the nearest preceding if of an if statement. +---*/ + +function main(): void { + if ({{c.cond1}}) + if ({{c.cond2}}) arktest.assertTrue({{c.bool1}}) + else arktest.assertTrue({{c.bool2}}) // Executes only if: Cond1 && !Cond2 +} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_1.params.yaml b/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_1.params.yaml new file mode 100644 index 0000000000..333c03d4fa --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_1.params.yaml @@ -0,0 +1,19 @@ +# 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: + - { cond1: 'true', cond2: 'true', bool1: 'true', bool2: 'false' } + - { cond1: 'true', cond2: 'false', bool1: 'false', bool2: 'true' } + - { cond1: 'false', cond2: 'true', bool1: 'false', bool2: 'false' } + - { cond1: 'false', cond2: 'false', bool1: 'false', bool2: 'false' } diff --git a/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_2.ets b/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_2.ets new file mode 100644 index 0000000000..6ce4d0e902 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_2.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. +---*/ + +{% for c in cases %} +/*--- +desc: A Block can be used to combine the else part with the initial if. +---*/ + +function main(): void { + if ({{c.cond1}}) { + if ({{c.cond2}}) arktest.assertTrue({{c.bool1}}); + } + else arktest.assertTrue({{c.bool2}}); // Executes if: !Cond1 +} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_2.params.yaml b/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_2.params.yaml new file mode 100644 index 0000000000..32569fd75b --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_2.params.yaml @@ -0,0 +1,19 @@ +# 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: + - { cond1: 'true', cond2: 'true', bool1: 'true', bool2: 'false' } + - { cond1: 'true', cond2: 'false', bool1: 'false', bool2: 'false' } + - { cond1: 'false', cond2: 'true', bool1: 'false', bool2: 'true' } + - { cond1: 'false', cond2: 'false', bool1: 'false', bool2: 'true' } diff --git a/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_3.ets b/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_3.ets new file mode 100644 index 0000000000..0223fa8bd6 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_3.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. +---*/ + +{% for c in cases %} +/*--- +desc: >- + If thenStatement or elseStatement is any kind of a statement but not a block, + then no block scope is created for such a statement. +---*/ + +function main(): void { + if ({{c.cond}}) let x: number = 1; + x = 2; // OK + + if ({{c.cond}}) { + let x: number = 10; // OK, then-block scope + let y: number = x; + } + else { + let x: number = 20; // OK, no conflict, else-block scope + } + + arktest.assertEQ(x, 2); +} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_3.params.yaml b/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_3.params.yaml new file mode 100644 index 0000000000..61823acc9c --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_3.params.yaml @@ -0,0 +1,17 @@ +# 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: + - cond: 'true' + - cond: 'false' diff --git a/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_3_negative.ets b/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_3_negative.ets new file mode 100644 index 0000000000..5a86521e25 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_3_negative.ets @@ -0,0 +1,40 @@ +/*--- +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: >- + If thenStatement or elseStatement is any kind of a statement but not a block, + then no block scope is created for such a statement. +tags: [compile-only, negative] +---*/ + +function main(): void { + if (true) let x: number = 1; + x = 2; // OK + + if (false) { + let x: number = 10; // OK, then-block scope + let y: number = x; + } + else { + let x: number = 20; // OK, no conflict, else-block scope + {{c.cte1}}; + } + + arktest.assertEQ(x, 2); + {{c.cte2}} +} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_3_negative.params.yaml b/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_3_negative.params.yaml new file mode 100644 index 0000000000..3f1822c87a --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/08.statements/05.if_statements/spec_if_3_negative.params.yaml @@ -0,0 +1,17 @@ +# 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: + - { cte1: 'y = x; // CTE, no y in scope', cte2: '' } + - { cte1: '', cte2: 'x = y; // CTE, y unknown' } -- Gitee