diff --git a/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_callable_return_value.js b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_callable_return_value.js index 8b3c4a52c1..a7124add07 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_callable_return_value.js +++ b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_callable_return_value.js @@ -15,7 +15,7 @@ const { getTestModule } = require('scenarios.test.js'); const etsMod = getTestModule('scenarios_test'); -const callableReturnValueFunctionEts = etsMod.getFunction('function_callable_return_value'); +const callableReturnValueFunctionEts = etsMod.getFunction('functionCallableReturnValue'); { let ret = callableReturnValueFunctionEts()(); diff --git a/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_function_arg_string_literal_type.js b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_function_arg_string_literal_type.js new file mode 100644 index 0000000000..672d2b9675 --- /dev/null +++ b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_function_arg_string_literal_type.js @@ -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. + */ +const { getTestModule } = require('scenarios.test.js'); + +const etsMod = getTestModule('scenarios_test'); +const functionArgStringLiteralTypeEts = etsMod.getFunction('functionArgStringLiteralType'); +const functionArgStringLiteralTypeUnionEts = etsMod.getFunction('functionArgStringLiteralTypeUnion'); + +{ + const VALUE1 = "1"; + const VALUE2 = "2"; + let ret = functionArgStringLiteralTypeEts(VALUE1); + ASSERT_EQ(ret, VALUE1); + + ret = functionArgStringLiteralTypeUnionEts(VALUE1); + ASSERT_EQ(ret, VALUE1); + + ret = functionArgStringLiteralTypeUnionEts(VALUE2); + ASSERT_EQ(ret, VALUE2); +} diff --git a/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_function_overload_set.js b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_function_overload_set.js index 2da315be5b..f01877b21e 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_function_overload_set.js +++ b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_function_overload_set.js @@ -15,7 +15,7 @@ const { getTestModule } = require('scenarios.test.js'); const etsMod = getTestModule('scenarios_test'); -const overloadFunctionEts = etsMod.getFunction('function_overload'); +const overloadFunctionEts = etsMod.getFunction('functionOverload'); { let ret = overloadFunctionEts(); diff --git a/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_intersection_type.js b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_intersection_type.js new file mode 100644 index 0000000000..4d2736cc68 --- /dev/null +++ b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_intersection_type.js @@ -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. + */ +const { getTestModule } = require('scenarios.test.js'); + +const etsMod = getTestModule('scenarios_test'); +const functionIntersectionTypePrimitiveEts = etsMod.getFunction('functionIntersectionTypePrimitive'); +const functionIntersectionTypeObjectEts = etsMod.getFunction('functionIntersectionTypeObject'); + +{ + const VALUE1 = "1"; + + let ret = functionIntersectionTypePrimitiveEts(1); + ASSERT_EQ(ret, 1); + + let res = functionIntersectionTypeObjectEts(); + ASSERT_EQ(res.a, 1); + ASSERT_EQ(res.b, VALUE1); + ASSERT_TRUE(typeof res.a === 'number'); + ASSERT_TRUE(typeof res.b === 'string'); +} diff --git a/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_rest_parameter.js b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_rest_parameter.js index 6d8ad37627..9ca36dc099 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_rest_parameter.js +++ b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_rest_parameter.js @@ -15,7 +15,7 @@ const { getTestModule } = require('scenarios.test.js'); const etsMod = getTestModule('scenarios_test'); -const restParameterFunctionEts = etsMod.getFunction('function_rest_parameter'); +const restParameterFunctionEts = etsMod.getFunction('functionRestParameter'); { const VALUE = 1; diff --git a/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_spread_parameter.js b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_spread_parameter.js index 199c15c1b7..c9ff5a450e 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_spread_parameter.js +++ b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/js_suites/test_spread_parameter.js @@ -15,7 +15,7 @@ const { getTestModule } = require('scenarios.test.js'); const etsMod = getTestModule('scenarios_test'); -const spreadParameterFunctionEts = etsMod.getFunction('function_spread_parameter'); +const spreadParameterFunctionEts = etsMod.getFunction('functionSpreadParameter'); { const EXPECTED_RET = 2; diff --git a/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/scenarios.cpp b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/scenarios.cpp index dfe70877c7..a80bf5a1b9 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/scenarios.cpp +++ b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/scenarios.cpp @@ -402,4 +402,16 @@ TEST_F(EtsInteropScenariosEtsToJs, test_callable_return_value) ASSERT_EQ(true, RunJsTestSuite("js_suites/test_callable_return_value.js")); } +// NOTE(nikitayegorov) #18198 enable this after literal types are fixed +TEST_F(EtsInteropScenariosEtsToJs, DISABLED_test_function_arg_string_literal_type) +{ + ASSERT_EQ(true, RunJsTestSuite("js_suites/test_function_arg_string_literal_type.js")); +} + +// NOTE(nikitayegorov) #18198 enable this after literal types are fixed +TEST_F(EtsInteropScenariosEtsToJs, DISABLED_test_intersection_type) +{ + ASSERT_EQ(true, RunJsTestSuite("js_suites/test_intersection_type.js")); +} + } // namespace ark::ets::interop::js::testing diff --git a/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/scenarios.sts b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/scenarios.sts index 48efdb0f49..810e1ae559 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/scenarios.sts +++ b/static_core/plugins/ets/tests/interop_js/tests/scenarios/ets_to_js/scenarios.sts @@ -420,27 +420,65 @@ async function asyncNewInterfaceWithMethodEts(): Promise async function asyncFunctionUserInterface(obj: InterfaceWithMethodEts): Promise { return obj.methodInInterface(); } -//function function_rest_parameter(...arg: number[]): number { + +//function functionRestParameter(...arg: number[]): number { // return arg[0]; //} -function function_spread_parameter(arg1: number, arg2: number): number { +function functionSpreadParameter(arg1: number, arg2: number): number { return arg1 + arg2; } -function function_overloaded(): void { +function functionOverloaded(): void { } -function function_overloaded(arg: number): void { +function functionOverloaded(arg: number): void { } -function function_overload(): number { - function_overloaded(); - function_overloaded(1); +function functionOverload(): number { + functionOverloaded(); + functionOverloaded(1); return 1; } -function function_callable_return_value(): Function { +function functionCallableReturnValue(): Function { const value = () => 1; return value; } + +// NOTE(nikitayegorov) #18198 enable this after literal types are fixed +//type TypeString = "1"; +//type TypeStringU = "1" | "2"; +//type PrimitiveA = 0 | 1; +//type PrimitiveB = 1 | 2; +//type PrimitiveAB = PrimitiveA & PrimitiveB; + +//interface A { +// a: number; +//} +//interface B { +// b: string; +//} +//type AB = A & B; + + +//function functionIntersectionTypePrimitive(arg: PrimitiveAB): PrimitiveAB { +// const ret: PrimitiveAB = arg; +// return ret; +//} + +//function functionIntersectionTypeObject(): AB { +// let ab: AB = { +// a: 1, +// b: "1" +// }; +// return ab; +//} + +//function functionArgStringLiteralType(arg: TypeString): TypeString { +// return arg; +//} + +//function functionArgStringLiteralTypeUnion(arg: TypeStringU): TypeStringU { +// return arg; +//} diff --git a/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/js_suites/scenarios.js b/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/js_suites/scenarios.js index 0b22d08bf0..dcabdee1c0 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/js_suites/scenarios.js +++ b/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/js_suites/scenarios.js @@ -247,11 +247,11 @@ class ClassWithStaticMethod { } } function functionRestParameter(...arg) { - return arg[0]; // transpiled from Typescript code: function function_rest_parameter(...arg: number[]) + return arg[0]; // transpiled from Typescript code: function functionRestParameter(...arg: number[]) } function functionSpreadParameter(arg1, arg2) { - return arg1 + arg2; // transpiled from Typescript code: function function_spread_parameter(arg1: number, arg2: number) + return arg1 + arg2; // transpiled from Typescript code: function functionSpreadParameter(arg1: number, arg2: number) } function functionOverloaded() { @@ -275,6 +275,17 @@ function functionCallableReturnValue() { } +function functionArgStringLiteralType(arg) { + return arg; + // transpiled from Typescript code: functionArgStringLiteralType(arg: TypeString): TypeString +} + +function functionIntersectionTypePrimitive(arg) { + const ret = arg; + return ret; + // transpiled from Typescript code: functionIntersectionTypePrimitive(arg: PrimitiveAB): PrimitiveAB +} + exports.standaloneFunctionJs = standaloneFunctionJs; exports.ClassWithMethodJs = ClassWithMethodJs; exports.newInterfaceWithMethod = newInterfaceWithMethod; @@ -315,3 +326,5 @@ exports.functionRestParameter = functionRestParameter; exports.functionSpreadParameter = functionSpreadParameter; exports.functionOverload = functionOverload; exports.functionCallableReturnValue = functionCallableReturnValue; +exports.functionArgStringLiteralType = functionArgStringLiteralType; +exports.functionIntersectionTypePrimitive = functionIntersectionTypePrimitive; diff --git a/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/scenarios.cpp b/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/scenarios.cpp index 5f0c265f9b..096fd72c54 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/scenarios.cpp +++ b/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/scenarios.cpp @@ -229,15 +229,27 @@ TEST_F(EtsInteropScenariosJsToEts, DISABLED_Test_function_spread_parameter) ASSERT_EQ(ret, true); } -TEST_F(EtsInteropScenariosJsToEts, Test_function_overload) +TEST_F(EtsInteropScenariosJsToEts, testFunctionOverload) { - auto ret = CallEtsMethod("Test_function_overload"); + auto ret = CallEtsMethod("testFunctionOverload"); ASSERT_EQ(ret, true); } -TEST_F(EtsInteropScenariosJsToEts, Test_function_callable_return_value) +TEST_F(EtsInteropScenariosJsToEts, testFunctionCallableReturnValue) { - auto ret = CallEtsMethod("Test_function_callable_return_value"); + auto ret = CallEtsMethod("testFunctionCallableReturnValue"); + ASSERT_EQ(ret, true); +} + +TEST_F(EtsInteropScenariosJsToEts, testFunctionArgStringLiteralType) +{ + auto ret = CallEtsMethod("testFunctionArgStringLiteralType"); + ASSERT_EQ(ret, true); +} + +TEST_F(EtsInteropScenariosJsToEts, testFunctionIntersectionTypePrimitive) +{ + auto ret = CallEtsMethod("testFunctionIntersectionTypePrimitive"); ASSERT_EQ(ret, true); } diff --git a/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/scenarios.sts b/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/scenarios.sts index be0c28d782..c531912a39 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/scenarios.sts +++ b/static_core/plugins/ets/tests/interop_js/tests/scenarios/js_to_ets/scenarios.sts @@ -20,14 +20,17 @@ import { functionArgTypeTuple, functionReturnTypeAny, functionReturnTypeUnknown, functionReturnTypeUndefined, functionArgTypeCallable, functionDefaultParameterFunction, functionDefaultIntParameterFunction, functionDefaultStringParameterFunction, functionDefaultFloatParameterFunction, genericTypeParameter, - genericTypeReturnValue, functionRestParameter, functionSpreadParameter, - functionOverload, functionCallableReturnValue } from "pure_js" + functionRestParameter, functionSpreadParameter, functionOverload, functionCallableReturnValue, + genericTypeReturnValue, functionArgStringLiteralType, functionIntersectionTypePrimitive +} from "pure_js" import { optionalCall, singleRequired, } from "decl_js" +// NOTE(nikitayegorov) #17339 enable after rest\spread is fixed +const FIXED_17339 = false; function testOptionals() { let x = optionalCall(123, 321, 5) @@ -261,20 +264,28 @@ function Test_function_rest_parameter(): boolean { } function Test_function_spread_parameter(): boolean { - // NOTE(nikitayegorov) #17339 enable after rest\spread is fixed - //const arr = [1, 1]; - //return functionSpreadParameter(...arr) as int == 2; + if (FIXED_17339) { + const arr = [1, 1]; + return functionSpreadParameter(...arr) as int == 2; + } return false; } -function Test_function_overload(): boolean { +function testFunctionOverload(): boolean { return functionOverload() as int == 1; } -function Test_function_callable_return_value(): boolean { +function testFunctionCallableReturnValue(): boolean { const fn = functionCallableReturnValue; return fn()(1) as int == 2; } +function testFunctionArgStringLiteralType(): boolean { + let arg: JSValue = 1; + return functionArgStringLiteralType(arg) as int == 1; +} - +function testFunctionIntersectionTypePrimitive(): boolean { + let arg: JSValue = 1; + return functionIntersectionTypePrimitive(arg) as int == 1; +}