diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record17.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/dynamic_record_index.ets similarity index 82% rename from static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record17.ets rename to static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/dynamic_record_index.ets index cde42b2a131b24bdfde9ec49f84077ea5b448187..57a334076e6a876e39a19d7e7bbda01317de797c 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record17.ets +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/dynamic_record_index.ets @@ -13,18 +13,20 @@ * limitations under the License. */ +{% for c in cases %} /*--- desc: Record index expression - the keys of the record are dynamically generated. ---*/ -let dynamicKeyRecord: Record = {}; +let dynamicRecord: Record = {}; function setValue(key: string, value: number) { - dynamicKeyRecord[key] = value; + dynamicRecord[key] = value; } function main(): void { setValue("key1", 10); setValue("key2", 20); - arktest.assertEQ(dynamicKeyRecord["key1"], 10); -} \ No newline at end of file + arktest.assertEQ(dynamicRecord["{{c.index}}"], {{c.value}}); +} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/dynamic_record_index.params.yaml b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/dynamic_record_index.params.yaml new file mode 100644 index 0000000000000000000000000000000000000000..82fdb028cbd732bad52069a53907b88a83821a75 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/dynamic_record_index.params.yaml @@ -0,0 +1,18 @@ +# 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: + - { index: 'key1', value: 10 } + - { index: 'key2', value: 20 } + - { index: 'key3', value: undefined } diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/ind.params.yaml b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/ind.params.yaml index f02abe58e6b7d0a6bef97b67e11373c978158eb6..490fb80842da3829c008076822f4c1e210c582c0 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/ind.params.yaml +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/ind.params.yaml @@ -29,8 +29,7 @@ cases: r["3"] = new Short(30) arktest.assertTrue(r["1"] == 10 && r["2"] == 20 && r["3"] == 30) - - tags: 'compile-only, negative' - use: |- + - use: |- // key is a union of literal types let idx: Short = 0 let r: Record<"11"|"12"|"13", Short> = { @@ -39,46 +38,9 @@ cases: "13": idx, } let i = "11" - arktest.assertTrue(r[i] == 0) // CTE expected, expression is not permitted in index - - - tags: 'compile-only, negative' - decl: |- - function foo(p: string): string { - return p + "2" - } - use: |- - // key is a union of literal types - let idx: Short = 0 - let r: Record<"11"|"12"|"13", Short> = { - "11": idx, - "12": idx, - "13": idx, - } - r[foo("1")] = 99 // CTE expected, expression is not permitted in index - arktest.assertTrue(r["12"] == 99) - - - tags: 'compile-only, negative' - use: |- - // key is a union of literal types - let idx: Byte = 0 - let r: Record<" "|" "|" ", Byte> = { - " " : idx, - " " : idx, - " " : idx, - } - arktest.assertTrue(r["?"] == undefined) // CTE expected, unknown key - - - tags: 'compile-only, negative' - use: |- - // key is a union of literal types - let idx: Byte = 0 - let r: Record<" "|" "|" ", Byte> = { - " " : idx, - " " : idx, - " " : idx, - } - r[""] = ++idx; // CTE expected, unknown key - arktest.assertTrue(r[" "] == idx) + arktest.assertEQ(r[i], 0) + arktest.assertEQ(r["12"], 0) + arktest.assertEQ(r["13"], 0) # Record key is a union of string literal types and string - use: |- @@ -119,27 +81,6 @@ cases: r[foo(1)] = 99 arktest.assertTrue(r["1"] == 99 && r["2"] == 2 && r["3"] == undefined) - - tags: 'compile-only, negative' - use: |- - // key is a union of literal types and string - let idx: int = 0 - let r: Record<"1"|"2"|"3"|string, Int> = { - "1": idx + 1, - "2": idx + 2, - } - arktest.assertTrue(r[1] == undefined) // CTE: wrong key type - - - tags: 'compile-only, negative' - use: |- - // key is a union of literal types and string - let idx: int = 0 - let r: Record<"1"|"2"|"3"|string, Int> = { - "1": idx + 1, - "2": idx + 2, - } - r[2] = 99 // CTE: wrong key type - arktest.assertTrue(r["2"] == 2) - # Record key is of numeric type - use: |- // key is of numeric type diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/ind2.params.yaml b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/ind2.params.yaml index 8ad3f8a3fee343ef16043951c45b2027825e0742..1e74b547d6189c37f3977a6a36fc39984c3aca56 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/ind2.params.yaml +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/ind2.params.yaml @@ -13,8 +13,8 @@ --- cases: - - { ref_fail: 'false', idx_fail: 'false', idx: '"1"', res: '" ref idx passed 42"' } + - { ref_fail: 'false', idx_fail: 'false', idx: '"1"', res: '" ref idx passed 42"' } - { ref_fail: 'false', idx_fail: 'false', idx: '"2"', res: '" ref idx passed undefined"' } - - { ref_fail: 'false', idx_fail: 'true', idx: '"1"', res: '" ref idx failed 99"' } - - { ref_fail: 'true', idx_fail: 'false', idx: '"1"', res: '" ref failed 99"' } - - { ref_fail: 'true', idx_fail: 'true', idx: '"1"', res: '" ref failed 99"' } + - { ref_fail: 'false', idx_fail: 'true', idx: '"1"', res: '" ref idx failed 99"' } + - { ref_fail: 'true', idx_fail: 'false', idx: '"1"', res: '" ref failed 99"' } + - { ref_fail: 'true', idx_fail: 'true', idx: '"1"', res: '" ref failed 99"' } diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx1c.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx1c.ets deleted file mode 100644 index 2b3677251ac1fb094eaaf9610a18b906028ce461..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx1c.ets +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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: >- - If no ‘?.’ is present in an indexing expression, then the type of object reference - expression must be an array type, or the Record type; a compile-time error occurs otherwise. -tags: [compile-only, negative] ----*/ - -function refNullish(): Record | undefined { - let res: Record | undefined = { "magic": 42 } - return res -} - -function main() { - arktest.assertTrue(refNullish()["magic"] == 42) // CTE expected -} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx1e.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx1e.ets deleted file mode 100644 index 577049d0450ea70de094a19f65cb40b2f0d931f0..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx1e.ets +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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: >- - If no ‘?.’ is present in an indexing expression, then the type of object reference - expression must be an array type, or the Record type; a compile-time error occurs otherwise. -tags: [compile-only, negative] ----*/ - -function refNullish(): Record | undefined { - let res: Record | undefined = undefined - return res -} - -function main() { - arktest.assertTrue(refNullish()["magic"] == 42) // CTE expected -} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx3b.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx3b.ets deleted file mode 100644 index 54a6c374a5cfa2c1fb5bf44884cd4366f18d09c5..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx3b.ets +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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: >- - The object reference expression must be checked to evaluate to nullish value; - if it does, then the entire indexing-Expression equals undefined. ----*/ - -function refNullish(): Record | undefined { - let res: Record | undefined = { "magic": 42 } - return res -} - -function main() { - arktest.assertTrue(refNullish()?.["magic"] == 42) -} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx3d.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx3d.ets deleted file mode 100644 index 02f5fefb638b4618f3a15d823ea36949670b661d..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx3d.ets +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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: >- - The object reference expression must be checked to evaluate to nullish value; - if it does, then the entire indexing-Expression equals undefined. ----*/ - -function refNullish(): Record | undefined { - let res: Record | undefined = undefined - return res -} - -function main() { - arktest.assertTrue(refNullish()?.["magic"] === undefined) -} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx1d.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/nullable_record_access.ets similarity index 78% rename from static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx1d.ets rename to static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/nullable_record_access.ets index 78f8f67de90df6a719cc23d96c720e99368170fb..51e0a4238ec63c575719e26eef74238314f8cb30 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx1d.ets +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/nullable_record_access.ets @@ -13,18 +13,19 @@ * limitations under the License. */ +{% for c in cases %} /*--- desc: >- If no ‘?.’ is present in an indexing expression, then the type of object reference expression must be an array type, or the Record type; a compile-time error occurs otherwise. -tags: [compile-only, negative] ---*/ -function refNullish(): Record | null { - let res: Record | null = null - return res +function refNullish(): Record | {{c.type}} { + let res: Record | {{c.type}} = {{c.value}}; + return res; } function main() { - arktest.assertTrue(refNullish()["magic"] == 42) // CTE expected + arktest.assertEQ(refNullish()?.["magic"], {{c.result}}); } +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/nullable_record_access.params.yaml b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/nullable_record_access.params.yaml new file mode 100644 index 0000000000000000000000000000000000000000..595cd6af731deb6fcde034af72b57fabe26cda96 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/nullable_record_access.params.yaml @@ -0,0 +1,19 @@ +# 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. + +--- +cases: + - { type: 'null', value: '{ "magic": 42 }', result: 42 } + - { type: 'undefined', value: '{ "magic": 42 }', result: 42 } + - { type: 'null', value: 'null', result: 'undefined' } + - { type: 'undefined', value: 'undefined', result: 'undefined' } diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx1b.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/nullable_record_access_n.ets similarity index 79% rename from static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx1b.ets rename to static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/nullable_record_access_n.ets index 9d64f0fe760a1c9fc972407ee6922cb6ee4b1571..2fcad76aeecba74b882da664e158a7e8c0f89035 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx1b.ets +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/nullable_record_access_n.ets @@ -13,6 +13,7 @@ * limitations under the License. */ +{% for c in cases %} /*--- desc: >- If no ‘?.’ is present in an indexing expression, then the type of object reference @@ -20,11 +21,12 @@ desc: >- tags: [compile-only, negative] ---*/ -function refNullish(): Record | null { - let res: Record | null = { "magic": 42 } - return res +function refNullish(): Record | {{c.type}} { + let res: Record | {{c.type}} = {{c.value}}; + return res; } function main() { - arktest.assertTrue(refNullish()["magic"] == 42) // CTE expected + let a = refNullish()["magic"]; // CTE expected } +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/nullable_record_access_n.params.yaml b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/nullable_record_access_n.params.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7e2c81e9530a812b6da3b153666a950173581341 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/nullable_record_access_n.params.yaml @@ -0,0 +1,19 @@ +# 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. + +--- +cases: + - { type: 'null', value: '{ "magic": 42 }' } + - { type: 'undefined', value: '{ "magic": 42 }' } + - { type: 'null', value: 'null' } + - { type: 'undefined', value: 'undefined' } diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record04.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record04.ets deleted file mode 100644 index a8fcaf73ea991bc18745f45b91a44e4c96ab6b34..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record04.ets +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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: Record index expression - there are no restrictions on the index expression no. ----*/ - -let x: Record = { - 1: "hello", - 2: "buy", -}; - -function bar(n: number): string { - let s = x[n]; - if (s == undefined) { return "no"; } - return s!; -} - -function main(): void { - arktest.assertEQ(bar(3), "no"); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record07.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record07.ets deleted file mode 100644 index 4b6a40e84de9ff9183cb5f079ba704d9ad078b65..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record07.ets +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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: Record index expression - key is of other types. ----*/ - -type Keys = 'key1' | 'key2' | 'key3'; - -let x2: Record = { - 1: "hello", - 2: "buy", -}; - -function foo(n: number): string | undefined { - return x2[n]; -} - -function main(): void { - let x = foo(3); - arktest.assertEQ(x, undefined); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record08.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record08.ets deleted file mode 100644 index b0c5bcc5a2f7c29fcf3812cc4a7a5023e1c195c4..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record08.ets +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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: Record index expression - key is of other types. ----*/ - -type Keys = 'key1' | 'key2' | 'key3'; - -let x2: Record = { - 1: "hello", - 2: "buy", -}; - -function bar(n: number): string { - let s = x2[n]; - if (s == undefined) { return "no"; } - return s!; -} - -function main(): void { - let x = bar(3); - arktest.assertEQ(x, "no"); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record09.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record09.ets deleted file mode 100644 index c6fdd0b577572e40538f1cddc139e2b961323598..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record09.ets +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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: Record index expression - record with dynamic keys. ----*/ - -let dynamicRecord: Record = { - "a": 1, - "b": 2, - "c": 3, -}; - -function getValue(key: string): number | undefined { - return dynamicRecord[key]; -} - -function main(): void { - arktest.assertEQ(getValue("a"), 1); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record10.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record10.ets deleted file mode 100644 index 06c17f5a6866199c82775233baa865398ae414b7..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record10.ets +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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: Record index expression - record with dynamic keys -undefined. ----*/ - -let dynamicRecord: Record = { - "a": 1, - "b": 2, - "c": 3, -}; - -function getValue(key: string): number | undefined { - return dynamicRecord[key]; -} - -function main(): void { - arktest.assertEQ(getValue("d"), undefined); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record11.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record11.ets deleted file mode 100644 index 2bccde9e62156203bd2b8718f0b3f54b7964429d..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record11.ets +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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: Record index expression - record with optional keys. ----*/ - -let optionalRecord: Record = { - "name": "Alice", - "age": "30", -}; - -function main(): void { - arktest.assertEQ(optionalRecord["name"], "Alice"); - arktest.assertEQ(optionalRecord["age"], "30"); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record12.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record12.ets deleted file mode 100644 index bb00cdf3ece9e591bc685c49bb2068239a18a406..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record12.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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: Record index expression - record with optional keys - undefined. ----*/ - -let optionalRecord: Record = { - "name": "Alice", - "age": "30", -}; - -function main(): void { - arktest.assertEQ(optionalRecord["gender"], undefined); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record14.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record14.ets deleted file mode 100644 index 095a258bb448629292ab62eb30d663bf18069721..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record14.ets +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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: Record index expression - record and default values. ----*/ - -let recordWithDefaults: Record = { - "a": 1, - "b": 2, -}; - -function getValueOrDefault(key: string, defaultValue: number): number { - return recordWithDefaults[key] ?? defaultValue; -} - -function main(): void { - arktest.assertEQ(getValueOrDefault("c", 0), 0); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record15.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record15.ets deleted file mode 100644 index 07790377d93534bc699f122035acd30c810d52f5..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record15.ets +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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: Record index expression - the keys of the record are number. ----*/ - -let numberRecord: Record = { - 1: "one", - 2: "two", - 3: "three", -}; - -function main(): void { - arktest.assertEQ(numberRecord[1], "one"); - arktest.assertEQ(numberRecord[2], "two"); - arktest.assertEQ(numberRecord[3], "three"); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record16.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record16.ets deleted file mode 100644 index 8f3decddf8343144310c7500e295c496898f0ede..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record16.ets +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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: Record index expression - the keys of the record are number. ----*/ - -let numberRecord: Record = { - 1: "one", - 2: "two", - 3: "three", -}; - -function main(): void { - arktest.assertEQ(numberRecord[4], undefined); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record18.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record18.ets deleted file mode 100644 index 648bff215c6db19ef8627503b28623063ece96e0..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record18.ets +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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: Record index expression - the keys of the record are dynamically generated. ----*/ - -let dynamicKeyRecord: Record = {}; - -function setValue(key: string, value: number) { - dynamicKeyRecord[key] = value; -} - -function main(): void { - setValue("key1", 10); - setValue("key2", 20); - arktest.assertEQ(dynamicKeyRecord["key3"], undefined); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record19.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record19.ets deleted file mode 100644 index 403a925a69d02ab5a08c710434ac0b5e0c0e8388..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record19.ets +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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: Record index expression - record and default value filling. ----*/ - -let config: Record = { - "theme": "dark", - "language": "en", -}; - -function getConfigValue(key: string, defaultValue: string): string { - return config[key] ?? defaultValue; -} - -function main(): void { - arktest.assertEQ(getConfigValue("theme", "light"), "dark"); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record21.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record21.ets deleted file mode 100644 index b2c956f3dc14cf844a0e2b0e0ba31e79944eac86..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record21.ets +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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: Record index expression - type conversion of dynamic keys in a recordype conversion of dynamic keys in a record. -tags: [compile-only, positive] ----*/ - -let stringRecord: Record = { - "1": 10, - "2": 20, - "3": 30, -}; - -function main(): void { - let numberRecord: Record = {}; -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record22.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record22.ets deleted file mode 100644 index ae640c4824a64f303684e178e929ee2238f9d459..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record22.ets +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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: Record index expression - default values for optional keys in a Record. ----*/ - -let optionalRecord: Record = { - "a": 1, - "b": 2, -}; - -function getValueWithDefault(key: string, defaultValue: number): number { - return optionalRecord[key] ?? defaultValue; -} - -function main(): void { - arktest.assertEQ(getValueWithDefault("a", 0), 1); - arktest.assertEQ(getValueWithDefault("b", 0), 2); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record23.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record23.ets deleted file mode 100644 index 87a116bd8d8cc42d1c243fad02beee4a5d914e38..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record23.ets +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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: Record index expression - default values for optional keys in a record. ----*/ - -let optionalRecord: Record = { - "a": 1, - "b": 2, -}; - -function getValueWithDefault(key: string, defaultValue: number): number { - return optionalRecord[key] ?? defaultValue; -} - -function main(): void { - arktest.assertEQ(getValueWithDefault("c", 0), 0); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record24.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record24.ets deleted file mode 100644 index ddfacc25e6cb5119e094c74f7bac4837e5ebbc39..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record24.ets +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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: Record index expression - record and default values for dynamic keys. ----*/ - -let dynamicRecord: Record = {}; - -function setValue(key: string, value: number) { - dynamicRecord[key] = value; -} - -function main(): void { - setValue("a", 1); - setValue("b", 2); - arktest.assertEQ(dynamicRecord["a"], 1); - arktest.assertEQ(dynamicRecord["b"], 2); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record25.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record25.ets deleted file mode 100644 index 373015ad899198aa7a5b5861eca5f328e876a136..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record25.ets +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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: Record index expression - runtime valid indexing. ----*/ - -let scores: Record = { - 90: "A", - 80: "B", - 70: "C", -}; - -function main(): void { - let gradeA = scores[90]; - arktest.assertEQ(gradeA, "A"); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record26.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record26.ets deleted file mode 100644 index f4fb531dc2140ceed9a513ef141a32ff868eb96d..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record26.ets +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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: Record index expression - invalid index (key does not exist). ----*/ - -let scores: Record = { - 90: "A", - 80: "B", - 70: "C", -}; - -function main(): void { - let gradeD = scores[60]; - arktest.assertEQ(gradeD, undefined); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record27.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record27.ets deleted file mode 100644 index 6db97a7e4becd4fcfc4a3db09056c87f8255161d..0000000000000000000000000000000000000000 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record27.ets +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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: Record index expression - runtime check. ----*/ - -let scores: Record = { - 90: "A", - 80: "B", - 70: "C", -}; - -function getGrade(score: number): string { - let grade = scores[score]; - return grade ?? "F"; -} - -function main(): void { - arktest.assertEQ(getGrade(90), "A"); - console.log(getGrade(60)); -} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx3c.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_access_wrong_key_n.ets similarity index 48% rename from static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx3c.ets rename to static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_access_wrong_key_n.ets index 26ed9af71965a28ea88d04dbffc1f19bf2b70fdb..b39df3c52e1063bdba15391777eff54e5eb59d2b 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx3c.ets +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_access_wrong_key_n.ets @@ -1,29 +1,36 @@ /* - * Copyright (c) 2021-2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Copyright (c) 2024-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, + * 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: >- - The object reference expression must be checked to evaluate to nullish value; - if it does, then the entire indexing-Expression equals undefined. + For a Record indexing, the index expression must be of type Key. +tags: [compile-only, negative] ---*/ -function refNullish(): Record | null { - let res: Record | null = null - return res +let r: Record<'11' | '12' | '13', {{c.type}}> = { + '11': 1, + '12': 2, + '13': 3 +} + +function foo(s: string): string { + return s + '2'; } function main() { - arktest.assertTrue(refNullish()?.["magic"] === undefined) + let a = r[{{c.call}}]; // CTE expected } +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_access_wrong_key_n.params.yaml b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_access_wrong_key_n.params.yaml new file mode 100644 index 0000000000000000000000000000000000000000..46861bafaa2829a3e93d37aa92d506c52edfae26 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_access_wrong_key_n.params.yaml @@ -0,0 +1,19 @@ +# Copyright (c) 2024-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: + - { type: Short, call: 'foo("1")' } + - { type: Byte, call: '""' } + - { type: Int, call: '12' } + - { type: Int, call: '"14"' } diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record28.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_cast_index.ets similarity index 75% rename from static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record28.ets rename to static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_cast_index.ets index ac655c72c92dafabad4eaa5434bc9f8bfa550c32..ee621f686091835b39c1e6d0dcbbbdca66362e3d 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record28.ets +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_cast_index.ets @@ -13,20 +13,28 @@ * limitations under the License. */ +{% for c in cases %} /*--- desc: Record index expression - spread from a record cast from Object. ---*/ +let y: Record = { + "name": "Alice", + "age": "30" +} + function spreadFromObject(y: Record): Record { let x: Record = { ...y }; return x; } -function main(): void { - let y: Record = { "a": "Ali", "e": "Elif" }; +function getValue(key: string, defaultValue: string): string { let x = spreadFromObject(y); - - arktest.assertEQ(x.get("a"), "Ali"); - arktest.assertEQ(x.get("e"), "Elif"); + return x[key] ?? defaultValue; } +function main(): void { + let x = spreadFromObject(y); + arktest.assertEQ({{c.call}}, {{c.value}}); +} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_cast_index.params.yaml b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_cast_index.params.yaml new file mode 100644 index 0000000000000000000000000000000000000000..21d786ef6f33f7fef62d5ec41d89b5660ea63eb7 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_cast_index.params.yaml @@ -0,0 +1,22 @@ +# 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: + - { call: 'x.get("name")', value: '"Alice"' } + - { call: 'x.get("age")', value: '"30"' } + - { call: 'x["name"]', value: '"Alice"' } + - { call: 'x["age"]', value: '"30"' } + - { call: 'x["gender"]', value: 'undefined' } + - { call: 'getValue("name", "none")', value: '"Alice"' } + - { call: 'getValue("id", "none")', value: '"none"' } diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record06.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_enum_index.ets similarity index 73% rename from static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record06.ets rename to static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_enum_index.ets index 893ed5eee0270be1dd94dfd013fa4c6b7a32246f..e15730ca0668d1ce796146ac2321cc85997773ec 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record06.ets +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_enum_index.ets @@ -13,19 +13,21 @@ * limitations under the License. */ +{% for c in cases %} /*--- -desc: Record index expression - key is literal union type. -tags: [compile-only, negative] +desc: Record index expression - record union type index. ---*/ -type Keys = 'key1' | 'key2' | 'key3'; +enum Keys { k1, k2, k3 }; let x: Record = { - 'key1': 1, - 'key2': 2, - 'key3': 4, -}; + Keys.k1: 1; + Keys.k2: 2; + Keys.k3: 4; +} function main(): void { - let y = x["key4"]; -} \ No newline at end of file + let s = {{c.call}}; + arktest.assertEQ({{c.value}}, {{c.result}}); +} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_enum_index.params.yaml b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_enum_index.params.yaml new file mode 100644 index 0000000000000000000000000000000000000000..fff5e21ebc6be297009462f04521da95a7569bcb --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_enum_index.params.yaml @@ -0,0 +1,20 @@ +# 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: + - { call: 0, value: 'x[Keys.k1]', result: 1 } + - { call: 0, value: 'x[Keys.k2]', result: 2 } + - { call: 0, value: 'x[Keys.k3]', result: 4 } + - { call: 'x[Keys.k1]', value: 's', result: 1 } + - { call: 'x[Keys.k3]', value: 's', result: 4 } diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record02.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_field_access.ets similarity index 68% rename from static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record02.ets rename to static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_field_access.ets index 720c2cb29986efbefd8518e78c0144ad76b9ad2a..dbfcdcaa1f54603b5482d92d0a8c37857b6973bf 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record02.ets +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_field_access.ets @@ -13,18 +13,22 @@ * limitations under the License. */ +{% for c in cases %} /*--- -desc: Record index expression - if the index expression is not a valid literal, a compile-time error will occur. -tags: [compile-only, negative] +desc: >- + The record indexing expression can be written by using a field access notation + if its index expression is formed as an identifier of type string. ---*/ -type Keys = 'key1' | 'key2' | 'key3'; +type Keys = 'key1' | 'key2' | 'key3' -function main(): void { - let x: Record = { +let x: Record = { 'key1': 1, 'key2': 2, 'key3': 4, - }; - console.log(x['key4']); -} \ No newline at end of file +} + +function main(): void { + arktest.assertEQ(x.{{c.index}}, {{c.value}}); +} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_field_access.params.yaml b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_field_access.params.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f0f6c0e9dc8bb5ed6bccf264505d0d47dd188157 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_field_access.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: + - { index: 'key1', value: 1 } + - { index: 'key2', value: 2 } + - { index: 'key3', value: 4 } + diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record01.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_field_set.ets similarity index 69% rename from static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record01.ets rename to static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_field_set.ets index be54fa461a37136869d73cc9bce78b58fdae7990..40d96bbb9ac97afb2de3ee9da3034402451fbf07 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record01.ets +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_field_set.ets @@ -13,19 +13,23 @@ * limitations under the License. */ +{% for c in cases %} /*--- -desc: Record index expression - the type Key is a union type that only contains literal types. +desc: >- + The record indexing expression can be written by using a field access notation + if its index expression is formed as an identifier of type string. ---*/ type Keys = 'key1' | 'key2' | 'key3'; -function main(): void { - let x: Record = { +let x: Record = { 'key1': 1, 'key2': 2, - 'key3': 4, - }; + 'key3': 4 +} - let y = x['key2']; - arktest.assertEQ(y, 2); -} \ No newline at end of file +function main(): void { + x.{{c.index}} = 42; + arktest.assertEQ(x[{{c.index}}], 42); +} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_field_set.params.yaml b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_field_set.params.yaml new file mode 100644 index 0000000000000000000000000000000000000000..77ecceefbe5b36f7deb404cd36c555e9b7355bd3 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_field_set.params.yaml @@ -0,0 +1,18 @@ +# 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: + - index: 'key1' + - index: 'key2' + - index: 'key3' diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record03.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_number_index.ets similarity index 65% rename from static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record03.ets rename to static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_number_index.ets index 9bb723dd35ddafa5a10adbf90fc9f823a8df0e3f..b918745c98fcdfb2eab830161e13a7af93a547e4 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record03.ets +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_number_index.ets @@ -13,20 +13,28 @@ * limitations under the License. */ +{% for c in cases %} /*--- -desc: Record index expression - there are no restrictions on the index expression undefined. +desc: An index expression has no restriction. The result of an indexing expression is of type Value | undefined. ---*/ let x: Record = { - 1: "hello", - 2: "buy", -}; + 1: "hello", + 2: "buy" +} function foo(n: number): string | undefined { - return x[n]; + return x[n]; +} + +function bar(n: number): string { + let s = x[n]; + if (s == undefined) { return "no" }; + return s!; } function main(): void { - let x = foo(3); - arktest.assertEQ(x, undefined); -} \ No newline at end of file + let s = {{c.call}}; + arktest.assertEQ({{c.value}}, {{c.result}}); +} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_number_index.params.yaml b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_number_index.params.yaml new file mode 100644 index 0000000000000000000000000000000000000000..39019dcf03db933574ed233e755f8a322c21cf96 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_number_index.params.yaml @@ -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. + +--- +cases: + - { call: 0, value: 'x[1]', result: '"hello"' } + - { call: 0, value: 'x[2]', result: '"buy"' } + - { call: 0, value: 'x[0]', result: 'undefined' } + - { call: 0, value: 'bar(1)', result: '"hello"' } + - { call: 0, value: 'bar(10)', result: '"no"' } + - { call: 0, value: 'foo(2)', result: '"buy"' } + - { call: 0, value: 'foo(5)', result: 'undefined' } + - { call: 'x[2]', value: 's', result: '"buy"' } + - { call: 'x[3]', value: 's', result: 'undefined' } + - { call: 'bar(1)', value: 's', result: '"hello"' } + - { call: 'bar(8)', value: 's', result: '"no"' } + - { call: 'foo(2)', value: 's', result: '"buy"' } + - { call: 'foo(6)', value: 's', result: 'undefined' } diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx3a.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_set_wrong_key_n.ets similarity index 47% rename from static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx3a.ets rename to static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_set_wrong_key_n.ets index 581cd4e3766017704149aa47f6985a18aedb84f1..be44a175daeece0bef09b408d196a854f180fa08 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/indx3a.ets +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_set_wrong_key_n.ets @@ -1,29 +1,36 @@ /* - * Copyright (c) 2021-2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Copyright (c) 2024-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, + * 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: >- - The object reference expression must be checked to evaluate to nullish value; - if it does, then the entire indexing-Expression equals undefined. + For a Record indexing, the index expression must be of type Key. +tags: [compile-only, negative] ---*/ -function refNullish(): Record | null { - let res: Record | null = { "magic": 42 } - return res +let r: Record<'11' | '12' | '13', {{c.type}}> = { + '11': 1, + '12': 2, + '13': 3 +} + +function foo(s: string): string { + return s + '2'; } function main() { - arktest.assertTrue(refNullish()?.["magic"] == 42) + r[{{c.call}}] = 10; // CTE expected } +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_set_wrong_key_n.params.yaml b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_set_wrong_key_n.params.yaml new file mode 100644 index 0000000000000000000000000000000000000000..46861bafaa2829a3e93d37aa92d506c52edfae26 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_set_wrong_key_n.params.yaml @@ -0,0 +1,19 @@ +# Copyright (c) 2024-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: + - { type: Short, call: 'foo("1")' } + - { type: Byte, call: '""' } + - { type: Int, call: '12' } + - { type: Int, call: '"14"' } diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record13.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_string_index.ets similarity index 71% rename from static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record13.ets rename to static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_string_index.ets index c63c0297a8d2b4a3bfecddf0a381c2d66a6d1505..aed2cd31e7f07fe318cb272e9f3abbe5b7cb657a 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record13.ets +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_string_index.ets @@ -13,19 +13,26 @@ * limitations under the License. */ +{% for c in cases %} /*--- -desc: Record index expression - record and default values. +desc: Record index expression - record string-number. ---*/ -let recordWithDefaults: Record = { +let rec: Record = { "a": 1, "b": 2, + "c": 3, }; +function getValue(key: string): number | undefined { + return rec[key]; +} + function getValueOrDefault(key: string, defaultValue: number): number { - return recordWithDefaults[key] ?? defaultValue; + return rec[key] ?? defaultValue; } function main(): void { - arktest.assertEQ(getValueOrDefault("a", 0), 1); -} \ No newline at end of file + arktest.assertEQ({{c.call}}, {{c.value}}); +} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_string_index.params.yaml b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_string_index.params.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1270dc6ff9f48a2797f27927e52acf95f0603fc2 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_string_index.params.yaml @@ -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. + +--- +cases: + - { call: 'rec["a"]', value: 1 } + - { call: 'rec["b"]', value: 2 } + - { call: 'rec["c"]', value: 3 } + - { call: 'rec["d"]', value: undefined } + - { call: 'getValue("c")', value: 3 } + - { call: 'getValue("d")', value: undefined } + - { call: 'getValueOrDefault("a", 0)', value: 1 } + - { call: 'getValueOrDefault("b", 0)', value: 2 } + - { call: 'getValueOrDefault("e", 0)', value: 0 } diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record05.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_union_type_index.ets similarity index 82% rename from static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record05.ets rename to static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_union_type_index.ets index 7a9938597138dbc590777fc57d345b7ceeea85ee..556b30388e1aa7fecce3d8e0ec7f903f281940ef 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record05.ets +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_union_type_index.ets @@ -13,8 +13,9 @@ * limitations under the License. */ +{% for c in cases %} /*--- -desc: Record index expression - literal union type. +desc: Record index expression - record union type index. ---*/ type Keys = 'key1' | 'key2' | 'key3'; @@ -23,9 +24,10 @@ let x: Record = { 'key1': 1, 'key2': 2, 'key3': 4, -}; +} function main(): void { - let y = x['key2']; - arktest.assertEQ(y, 2); -} \ No newline at end of file + let s = {{c.call}}; + arktest.assertEQ({{c.value}}, {{c.result}}); +} +{% endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_union_type_index.params.yaml b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_union_type_index.params.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8ff9d0ed3a27366c42ec84f5e78d784274f4e46e --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/03.record_indexing_expression/record_union_type_index.params.yaml @@ -0,0 +1,20 @@ +# 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: + - { call: 0, value: 'x["key1"]', result: 1 } + - { call: 0, value: 'x["key2"]', result: 2 } + - { call: 0, value: 'x["key3"]', result: 4 } + - { call: 'x["key1"]', value: 's', result: 1 } + - { call: 'x["key3"]', value: 's', result: 4 } 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 beca84746e07de7217fe65b57031f9a26c4a92d8..249b9a9197926af85048b67873da569c2896767b 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 @@ -1068,6 +1068,21 @@ #28526 07.expressions/11.function_call_expression/fcall_20.ets +#28679 +07.expressions/12.indexing_expression/03.record_indexing_expression/record_enum_index_0.ets +07.expressions/12.indexing_expression/03.record_indexing_expression/record_enum_index_1.ets +07.expressions/12.indexing_expression/03.record_indexing_expression/record_enum_index_2.ets +07.expressions/12.indexing_expression/03.record_indexing_expression/record_enum_index_3.ets +07.expressions/12.indexing_expression/03.record_indexing_expression/record_enum_index_4.ets + +#29719 +07.expressions/12.indexing_expression/03.record_indexing_expression/record_field_access_0.ets +07.expressions/12.indexing_expression/03.record_indexing_expression/record_field_access_1.ets +07.expressions/12.indexing_expression/03.record_indexing_expression/record_field_access_2.ets +07.expressions/12.indexing_expression/03.record_indexing_expression/record_field_set_0.ets +07.expressions/12.indexing_expression/03.record_indexing_expression/record_field_set_1.ets +07.expressions/12.indexing_expression/03.record_indexing_expression/record_field_set_2.ets + #29202 CTE expected in `instanceof T` 07.expressions/15.instanceof_expression/instanceof-cte_0.ets @@ -2679,7 +2694,6 @@ 06.contexts_and_conversions/05.implicit_conversions/03.constant_narrowing_integer_conversion/call_func/call-func-n3_7.ets 06.contexts_and_conversions/05.implicit_conversions/03.constant_narrowing_integer_conversion/call_lmbd/call-lmbd-n3_7.ets 06.contexts_and_conversions/05.implicit_conversions/03.constant_narrowing_integer_conversion/call_meth/call-meth-n3_7.ets -07.expressions/12.indexing_expression/03.record_indexing_expression/ind_1.ets 07.expressions/25.equality_expressions/eq_neg_101.ets 07.expressions/25.equality_expressions/eq_neg_146.ets 07.expressions/25.equality_expressions/eq_neg_148.ets @@ -2759,8 +2773,6 @@ 09.classes/07.method_declarations/05.overriding_methods/override_method_with_default_params_12.ets # 21255 no type Exception -07.expressions/12.indexing_expression/01.array_indexing_expression/array_index3_n_0.ets -07.expressions/12.indexing_expression/01.array_indexing_expression/array_index3_n_1.ets 09.classes/07.method_declarations/05.overriding_methods/override_method_declaration_with_keywords_4.ets # 29337 no CTE in ambiguous narrowing