!2081 Add interoperability test cases for string literal type and intersection type.

Merge pull request !2081 from nikitayegorov/smirn/interop_scenarios_tests_4
This commit is contained in:
openharmony_ci 2024-09-10 22:57:24 +00:00 committed by Gitee
commit 3fc3e06774
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
11 changed files with 176 additions and 26 deletions

View File

@ -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()();

View File

@ -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);
}

View File

@ -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();

View File

@ -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');
}

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -420,27 +420,65 @@ async function asyncNewInterfaceWithMethodEts(): Promise<InterfaceWithMethodEts>
async function asyncFunctionUserInterface(obj: InterfaceWithMethodEts): Promise<int> {
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<int> {
function functionCallableReturnValue(): Function<int> {
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;
//}

View File

@ -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;

View File

@ -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<bool>("Test_function_overload");
auto ret = CallEtsMethod<bool>("testFunctionOverload");
ASSERT_EQ(ret, true);
}
TEST_F(EtsInteropScenariosJsToEts, Test_function_callable_return_value)
TEST_F(EtsInteropScenariosJsToEts, testFunctionCallableReturnValue)
{
auto ret = CallEtsMethod<bool>("Test_function_callable_return_value");
auto ret = CallEtsMethod<bool>("testFunctionCallableReturnValue");
ASSERT_EQ(ret, true);
}
TEST_F(EtsInteropScenariosJsToEts, testFunctionArgStringLiteralType)
{
auto ret = CallEtsMethod<bool>("testFunctionArgStringLiteralType");
ASSERT_EQ(ret, true);
}
TEST_F(EtsInteropScenariosJsToEts, testFunctionIntersectionTypePrimitive)
{
auto ret = CallEtsMethod<bool>("testFunctionIntersectionTypePrimitive");
ASSERT_EQ(ret, true);
}

View File

@ -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;
}