From c61d8aa094212c5a51aa66dd543cd6c123ee9091 Mon Sep 17 00:00:00 2001 From: troeglazovamaria Date: Sat, 28 Dec 2024 16:32:11 +0300 Subject: [PATCH] Tests for Functions with Receiver Tests for Functions with Receiver Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/IBDF2R?from=project-issue Testing: All required pre-merge tests passed. Results are available in the ggwatcher Signed-off-by: troeglazovamaria --- .../functions_with_receiver.params.yaml | 124 ++++++++++++++++++ .../functions_with_receiver.sts | 28 ++++ ...nctions_with_receiver_negative.params.yaml | 32 +++++ .../functions_with_receiver_negative.sts | 26 ++++ .../functions_with_receiver.params.yaml | 26 ++++ .../functions_with_receiver.sts | 28 ++++ ...nctions_with_receiver_negative.params.yaml | 20 +++ .../functions_with_receiver_negative.sts | 26 ++++ 8 files changed, 310 insertions(+) create mode 100644 static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/01.functions_with_receiver/functions_with_receiver.params.yaml create mode 100644 static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/01.functions_with_receiver/functions_with_receiver.sts create mode 100644 static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/01.functions_with_receiver/functions_with_receiver_negative.params.yaml create mode 100644 static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/01.functions_with_receiver/functions_with_receiver_negative.sts create mode 100644 static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/02.receiver_types/functions_with_receiver.params.yaml create mode 100644 static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/02.receiver_types/functions_with_receiver.sts create mode 100644 static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/02.receiver_types/functions_with_receiver_negative.params.yaml create mode 100644 static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/02.receiver_types/functions_with_receiver_negative.sts diff --git a/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/01.functions_with_receiver/functions_with_receiver.params.yaml b/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/01.functions_with_receiver/functions_with_receiver.params.yaml new file mode 100644 index 0000000000..795eb72bc5 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/01.functions_with_receiver/functions_with_receiver.params.yaml @@ -0,0 +1,124 @@ +# Copyright (c) 2024 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: + - decl: | + class A {} + function f(this: A) {} + use: | + f(new A()) + - decl: | + class A {} + function f(this: A) {} + use: | + let a: A = new A() + f(a) + - decl: | + class A {} + function f(this: A, n: number) {} + use: | + let a: A = new A() + a.f(1) + - decl: | + class A {} + function f(this: A, n: number) {} + use: | + let a: A = new A() + f(a, 1) + - decl: | + class A { + foo() {} + } + function f(this: A) { + this.foo() + } + use: | + let a: A = new A() + a.f() + - decl: | + class A { + n: number = 1 + } + function f(this: A) { + return this.n + } + use: | + let a: A = new A() + a.f() + - decl: | + class A { + foo() {} + } + function f(this: A) { + this.foo() + } + use: | + let a: A = new A() + f(a) + - decl: | + class A { + n: number = 1 + } + function f(this: A):number { + return this.n + } + use: | + let a: A = new A() + f(a) + - decl: | + class A {} + function f(this: A) {} + use: | + let a: A = new A() + a.f() + - decl: | + class A {} + function f(this: A) {} + use: | + let a: A = new A() + f(a) + - decl: | + class A {} + class B extends A {} + function f(this: A): number { return 1 } + function f(this: B): number { return 2 } + use: | + let a: A = new A() + let b: B = new B() + assertEQ(a.f(), 1) + assertEQ(b.f(), 2) + a = new B() + assertEQ(a.f(), 2) + - decl: | + class A {} + class B extends A {} + function f(this: A): number { return 1 } + function f(this: B): number { return 2 } + use: | + let a: A = new A() + let b: B = new B() + assertEQ(f(a), 1) + assertEQ(f(b), 2) + a = new B() + assertEQ(f(b), 2) + - decl: | + class A {} + function f(this: A) {} + use: | + f(new A()) + - decl: | + class A {} + function f(this: A) {} + use: | + f(new A()) diff --git a/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/01.functions_with_receiver/functions_with_receiver.sts b/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/01.functions_with_receiver/functions_with_receiver.sts new file mode 100644 index 0000000000..279f649f0d --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/01.functions_with_receiver/functions_with_receiver.sts @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 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 function with receiver declaration is a top-level declaration (see Top-Level Declarations) that looks almost the same + as Function Declarations, except that the first parameter is mandatory, and the keyword this is used as its name +---*/ + +{{c.decl}} + +function main() { + {{c.use|indent}} +} +{%- endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/01.functions_with_receiver/functions_with_receiver_negative.params.yaml b/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/01.functions_with_receiver/functions_with_receiver_negative.params.yaml new file mode 100644 index 0000000000..6d0bf3047c --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/01.functions_with_receiver/functions_with_receiver_negative.params.yaml @@ -0,0 +1,32 @@ +# Copyright (c) 2024 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: + - decl: | + class A { + protected num: number = 1 + } + function f(this: A): number { + return this.num + } + - decl: | + class A { + private num: number = 1 + } + function f(this: A): number { + return this.num + } + - decl: | + class A {} + function f(this: A) {} diff --git a/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/01.functions_with_receiver/functions_with_receiver_negative.sts b/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/01.functions_with_receiver/functions_with_receiver_negative.sts new file mode 100644 index 0000000000..9a4d206157 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/01.functions_with_receiver/functions_with_receiver_negative.sts @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 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 function with receiver declaration is a top-level declaration (see Top-Level Declarations) that looks almost the same + as Function Declarations, except that the first parameter is mandatory, and the keyword this is used as its name +tags: [compile-only, negative] +---*/ + +{{c.decl}} + +{%- endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/02.receiver_types/functions_with_receiver.params.yaml b/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/02.receiver_types/functions_with_receiver.params.yaml new file mode 100644 index 0000000000..010c14f4e9 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/02.receiver_types/functions_with_receiver.params.yaml @@ -0,0 +1,26 @@ +# Copyright (c) 2024 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: + - decl: | + function f(this: number[]) {} + use: | + let n: number[] = [0, 1, 2] + f(n) + - decl: | + interface I {} + function f(this: I) {} + use: | + let i: I = {} + f(i) diff --git a/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/02.receiver_types/functions_with_receiver.sts b/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/02.receiver_types/functions_with_receiver.sts new file mode 100644 index 0000000000..279f649f0d --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/02.receiver_types/functions_with_receiver.sts @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 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 function with receiver declaration is a top-level declaration (see Top-Level Declarations) that looks almost the same + as Function Declarations, except that the first parameter is mandatory, and the keyword this is used as its name +---*/ + +{{c.decl}} + +function main() { + {{c.use|indent}} +} +{%- endfor %} diff --git a/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/02.receiver_types/functions_with_receiver_negative.params.yaml b/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/02.receiver_types/functions_with_receiver_negative.params.yaml new file mode 100644 index 0000000000..7b6efe77a8 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/02.receiver_types/functions_with_receiver_negative.params.yaml @@ -0,0 +1,20 @@ +# Copyright (c) 2024 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: + - decl: | + function f(this: number) {} + use: | + let n: number = 1 + f(n) diff --git a/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/02.receiver_types/functions_with_receiver_negative.sts b/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/02.receiver_types/functions_with_receiver_negative.sts new file mode 100644 index 0000000000..9a4d206157 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-templates/17.experimental_features/11.extension_functions/02.receiver_types/functions_with_receiver_negative.sts @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 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 function with receiver declaration is a top-level declaration (see Top-Level Declarations) that looks almost the same + as Function Declarations, except that the first parameter is mandatory, and the keyword this is used as its name +tags: [compile-only, negative] +---*/ + +{{c.decl}} + +{%- endfor %} -- Gitee