From 3be737c70daeed74007b70a87764fb53a36220c7 Mon Sep 17 00:00:00 2001 From: ignatenkooleg Date: Fri, 30 Aug 2024 15:31:54 +0300 Subject: [PATCH] uniform coding style in interop tests Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/IAMRH1 Test: build Signed-off-by: ignatenkooleg --- .../tests/indexed_type/indexed_type.cpp | 16 +-- .../tests/indexed_type/indexed_type.js | 49 ++++---- .../tests/indexed_type/indexed_type.sts | 64 +++++------ .../tests/indexed_type/indexed_type.ts | 17 +-- .../objects_passing/class_passing_sts.js | 21 ++-- .../tests/objects_passing/objects_passing.js | 41 ++++--- .../tests/objects_passing/objects_passing.sts | 4 +- .../tests/objects_passing/objects_passing.ts | 85 ++++++-------- .../objects_passing/objects_passing_sts.js | 19 +-- .../objects_passing_sts.test.js | 14 +-- .../tests/test_callable/test_callable.js | 8 +- .../tests/test_callable/test_callable.ts | 12 +- .../test_composite_types.js | 21 ++-- .../test_composite_types.ts | 108 +++++++++--------- .../interop_js/tests/timer/run_timer_test.js | 18 +-- 15 files changed, 245 insertions(+), 252 deletions(-) diff --git a/static_core/plugins/ets/tests/interop_js/tests/indexed_type/indexed_type.cpp b/static_core/plugins/ets/tests/interop_js/tests/indexed_type/indexed_type.cpp index e19d56d71a..81b49f1bdd 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/indexed_type/indexed_type.cpp +++ b/static_core/plugins/ets/tests/interop_js/tests/indexed_type/indexed_type.cpp @@ -93,27 +93,27 @@ TEST_F(EtsIndexedType, DISABLED_checkRecordValue) auto ret = CallEtsMethod("checkRecordValue"); ASSERT_EQ(ret, true); } -TEST_F(EtsIndexedType, getTypedArreyValueByIndex) +TEST_F(EtsIndexedType, getTypedArrayValueByIndex) { - auto ret = CallEtsMethod("getTypedArreyValueByIndex"); + auto ret = CallEtsMethod("getTypedArrayValueByIndex"); ASSERT_EQ(ret, true); } // NOTE(andreypetukhov) enable after fixibng #18131 -TEST_F(EtsIndexedType, DISABLED_changeTypedArreyValueByIndex) +TEST_F(EtsIndexedType, DISABLED_changeTypedArrayValueByIndex) { - auto ret = CallEtsMethod("changeTypedArreyValueByIndex"); + auto ret = CallEtsMethod("changeTypedArrayValueByIndex"); ASSERT_EQ(ret, true); } // NOTE(andreypetukhov) enable after fixibng #18131 -TEST_F(EtsIndexedType, DISABLED_checkLengthTypedArrey) +TEST_F(EtsIndexedType, DISABLED_checkLengthTypedArray) { - auto ret = CallEtsMethod("checkLengthTypedArrey"); + auto ret = CallEtsMethod("checkLengthTypedArray"); ASSERT_EQ(ret, true); } // NOTE(andreypetukhov) enable after fixibng #18131 -TEST_F(EtsIndexedType, DISABLED_checkAllTypedArreyValue) +TEST_F(EtsIndexedType, DISABLED_checkAllTypedArrayValue) { - auto ret = CallEtsMethod("checkAllTypedArreyValue"); + auto ret = CallEtsMethod("checkAllTypedArrayValue"); ASSERT_EQ(ret, true); } TEST_F(EtsIndexedType, getValueFromProxyRecord) diff --git a/static_core/plugins/ets/tests/interop_js/tests/indexed_type/indexed_type.js b/static_core/plugins/ets/tests/interop_js/tests/indexed_type/indexed_type.js index 7c83d2f0e7..b60e604a4d 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/indexed_type/indexed_type.js +++ b/static_core/plugins/ets/tests/interop_js/tests/indexed_type/indexed_type.js @@ -1,17 +1,18 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { +'use strict'; +let __extends = (this && this.__extends) || (function () { + let extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + function (d, b) { for (let p in b) { if (Object.prototype.hasOwnProperty.call(b, p)) { d[p] = b[p]; } }; }; return extendStatics(d, b); }; return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + if (typeof b !== 'function' && b !== null) { + throw new TypeError('Class extends value ' + String(b) + ' is not a constructor or null'); + } extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + function Ctor() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (Ctor.prototype = b.prototype, new Ctor()); }; })(); exports.__esModule = true; @@ -30,38 +31,38 @@ exports.handler = exports.createInt8Array = exports.createStringRecord = exports * See the License for the specific language governing permissions and * limitations under the License. */ -function getArrey(arr) { +function getArray(arr) { return arr; } -exports.getArrey = getArrey; -var CustomArray = /** @class */ (function (_super) { - __extends(CustomArray, _super); - function CustomArray() { - var items = []; - for (var _i = 0; _i < arguments.length; _i++) { - items[_i] = arguments[_i]; +exports.getArray = getArray; +let customArray = /** @class */ (function (_super) { + __extends(customArray, _super); + function customArray(...args) { + let items = []; + for (let _i = 0; _i < args.length; _i++) { + items[_i] = args[_i]; } return _super.apply(this, items) || this; } - return CustomArray; + return customArray; }(Array)); -exports.CustomArray = CustomArray; +exports.CustomArray = customArray; function returnCustomArray(array) { return array; } exports.returnCustomArray = returnCustomArray; function createStringRecord() { - var data = { - 'key1': "A", - 'key2': "B", - 'key3': "C" + let data = { + 'key1': 'A', + 'key2': 'B', + 'key3': 'C' }; return data; } exports.createStringRecord = createStringRecord; function createInt8Array(length) { - var array = new Int8Array(length); - for (var i = 0; i < length; i++) { + let array = new Int8Array(length); + for (let i = 0; i < length; i++) { array[i] = i; } return array; diff --git a/static_core/plugins/ets/tests/interop_js/tests/indexed_type/indexed_type.sts b/static_core/plugins/ets/tests/interop_js/tests/indexed_type/indexed_type.sts index b8301b91ac..828ec6903f 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/indexed_type/indexed_type.sts +++ b/static_core/plugins/ets/tests/interop_js/tests/indexed_type/indexed_type.sts @@ -12,50 +12,50 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { getArrey, returnCustomArray, createStringRecord,createInt8Array, RecordObject,handler} from "indexed_type" +import { getArray, returnCustomArray, createStringRecord,createInt8Array, RecordObject,handler} from "indexed_type" import {createProxy} from "proxy" const arr = ['A','B','C']; function getArrValueByIndex():boolean{ - const jsArrey = getArrey(arr) as string[]; - return jsArrey[0] == 'A'; + const jsArray = getArray(arr) as string[]; + return jsArray[0] == 'A'; } function changeArrValueByIndex():boolean{ - let jsArrey = getArrey(arr) as string[]; - jsArrey[0] = 'D'; - return jsArrey[0] == 'D'; + let jsArray = getArray(arr) as string[]; + jsArray[0] = 'D'; + return jsArray[0] == 'D'; } function checkLengthArr():boolean{ - const jsArrey:string[] = getArrey(arr) as string[]; - return jsArrey.length as number == arr.length as number + const jsArray:string[] = getArray(arr) as string[]; + return jsArray.length as number == arr.length as number } function checkAllArrValue():boolean{ - const jsArrey:string[] = getArrey(arr) as string[]; - return jsArrey[0] == 'A' && jsArrey[1] == 'B' && jsArrey[2] == 'C' + const jsArray:string[] = getArray(arr) as string[]; + return jsArray[0] == 'A' && jsArray[1] == 'B' && jsArray[2] == 'C' } function getCustomArrValueByIndex():boolean{ - const jsArrey = returnCustomArray(arr); - return jsArrey[0] == 'A'; + const jsArray = returnCustomArray(arr); + return jsArray[0] == 'A'; } function changeCustomArrValueByIndex():boolean{ - let jsArrey = returnCustomArray(arr) as string[]; - jsArrey[0] = 'D'; - return jsArrey[0] == 'D'; + let jsArray = returnCustomArray(arr) as string[]; + jsArray[0] = 'D'; + return jsArray[0] == 'D'; } function checkLengthCustomArr():boolean{ - const jsArrey:string[] = returnCustomArray(arr); - return jsArrey.length as number == arr.length as number; + const jsArray:string[] = returnCustomArray(arr); + return jsArray.length as number == arr.length as number; } function checkAllCustomArrValue():boolean{ - const jsArrey:string[] = returnCustomArray(arr); - return jsArrey[0] == 'A' && jsArrey[1] == 'B' && jsArrey[2] == 'C'; + const jsArray:string[] = returnCustomArray(arr); + return jsArray[0] == 'A' && jsArray[1] == 'B' && jsArray[2] == 'C'; } function getRecordValue():boolean{ @@ -91,25 +91,25 @@ function changeRecordValue():boolean{ // return recordObj['key1'] === 'A' && recordObj['key2'] === 'B' && recordObj['key3'] === 'C' // } -function getTypedArreyValueByIndex():boolean{ - const jsTypedArrey = createInt8Array(3); - return jsTypedArrey[0] as number == 0; +function getTypedArrayValueByIndex():boolean{ + const jsTypedArray = createInt8Array(3); + return jsTypedArray[0] as number == 0; } // NOTE(andreypetukhov) enable after fixibng #18131 -// function changeTypedArreyValueByIndex():boolean{ -// const jsTypedArrey = createInt8Array(3) as Int8Array; -// jsTypedArrey[1] = 99; -// return jsTypedArrey[1] as number == 99; +// function changeTypedArrayValueByIndex():boolean{ +// const jsTypedArray = createInt8Array(3) as Int8Array; +// jsTypedArray[1] = 99; +// return jsTypedArray[1] as number == 99; // } -function checkLengthTypedArrey():boolean{ - const jsTypedArrey = createInt8Array(3) as Int8Array; - return jsTypedArrey.length as number == 3 as number +function checkLengthTypedArray():boolean{ + const jsTypedArray = createInt8Array(3) as Int8Array; + return jsTypedArray.length as number == 3 as number } -function checkAllTypedArreyValue():boolean{ - const jsTypedArrey = createInt8Array(3) as Int8Array; - return jsTypedArrey[0] as number == 0 && jsTypedArrey[1] as number == 1 && jsTypedArrey[2] as number == 2 +function checkAllTypedArrayValue():boolean{ + const jsTypedArray = createInt8Array(3) as Int8Array; + return jsTypedArray[0] as number == 0 && jsTypedArray[1] as number == 1 && jsTypedArray[2] as number == 2 } const testObj:RecordObject = { diff --git a/static_core/plugins/ets/tests/interop_js/tests/indexed_type/indexed_type.ts b/static_core/plugins/ets/tests/interop_js/tests/indexed_type/indexed_type.ts index e7885653a0..423ad66573 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/indexed_type/indexed_type.ts +++ b/static_core/plugins/ets/tests/interop_js/tests/indexed_type/indexed_type.ts @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export function getArrey(arr:string[]):string[]{ - return arr +export function getArray(arr:string[]): string[] { + return arr; } export class CustomArray extends Array { @@ -29,9 +29,9 @@ export function returnCustomArray(array: CustomArray): CustomArray { export function createStringRecord(): Record { const data: Record = { - 'key1': "A", - 'key2': "B", - 'key3': "C" + 'key1': 'A', + 'key2': 'B', + 'key3': 'C' }; return data; } @@ -46,18 +46,19 @@ export function createInt8Array(length: number): Int8Array { type RecordObject = Record; +type AnyType = {}; export const handler = { - get: function(target: RecordObject, property: string) { + get: function(target: RecordObject, property: string): Object { if (property in target) { return target[property]; } else { return undefined; } }, - set: function(target: RecordObject, property: string, value: any) { + set: function(target: RecordObject, property: string, value: AnyType): Object { if (typeof value === 'string') { - target[property] = value; + target[property] = value; return true; } else { throw new TypeError('The value must be a string'); diff --git a/static_core/plugins/ets/tests/interop_js/tests/objects_passing/class_passing_sts.js b/static_core/plugins/ets/tests/interop_js/tests/objects_passing/class_passing_sts.js index 089f19b334..1d768419c4 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/objects_passing/class_passing_sts.js +++ b/static_core/plugins/ets/tests/interop_js/tests/objects_passing/class_passing_sts.js @@ -24,14 +24,14 @@ const getUserInfo = etsMod.getFunction('getClassUserInfo'); // Passing class to ets function -class TestUser{ - constructor(name, age){ - this.name = name - this.age = age +class TestUser { + Constructor(name, age) { + this.name = name; + this.age = age; } - showInfo(){ - return `User name: ${this.name}, age: ${this.age}` + showInfo() { + return `User name: ${this.name}, age: ${this.age}`; } } @@ -40,22 +40,19 @@ const testUser = new TestUser('TestName', 30); { let ret = getUserName(testUser); - console.log(ret) + console.log(ret); ASSERT_EQ(ret, 'TestName'); - } { let ret = getUserAge(testUser); - console.log(ret) + console.log(ret); ASSERT_EQ(ret, 30); - } { let ret = getUserInfo(testUser); - console.log(ret) + console.log(ret); ASSERT_EQ(ret, 'User name: TestName, age: 30'); - } diff --git a/static_core/plugins/ets/tests/interop_js/tests/objects_passing/objects_passing.js b/static_core/plugins/ets/tests/interop_js/tests/objects_passing/objects_passing.js index 133fb2fc78..04b96570bd 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/objects_passing/objects_passing.js +++ b/static_core/plugins/ets/tests/interop_js/tests/objects_passing/objects_passing.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; /** * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,24 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { +let __extends = (this && this.__extends) || (function () { + let extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + function (d, b) { for (let p in b) { if (Object.prototype.hasOwnProperty.call(b, p)) { d[p] = b[p]; } } }; return extendStatics(d, b); }; return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + if (typeof b !== 'function' && b !== null) { + throw new TypeError('Class extends value ' + String(b) + ' is not a constructor or null'); + } extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + function Ctor() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (Ctor.prototype = b.prototype, new Ctor()); }; })(); exports.__esModule = true; -exports.updateObjectId = exports.getOuterObj = exports.testOuterObject = exports.testSecondObjCls = exports.testObjCls = exports.getObjectId = exports.getObjectName = exports.getId = exports.getEdu = exports.changeName = exports.getDetailse = exports.getName = exports.testObject = exports.TestSecondClass = exports.TestUserClass = void 0; -var TestUserClass = /** @class */ (function () { +exports.updateObjectId = exports.getOuterObj = exports.testOuterObject = exports.testSecondObjCls = + exports.testObjCls = exports.getObjectId = exports.getObjectName = exports.getId = exports.getEdu = + exports.changeName = exports.getDetails = exports.getName = exports.testObject = exports.TestSecondClass = + exports.TestUserClass = void 0; +let TestUserClass = /** @class */ (function () { function TestUserClass(name, age, id, education, description) { this.name = name; this.age = age; @@ -39,18 +43,19 @@ var TestUserClass = /** @class */ (function () { this.education = education; } TestUserClass.prototype.getDetails = function () { - return "Name: ".concat(this.name, ", Age: ").concat(this.age, ", ID: ").concat(this.id, ", Description: ").concat(this.description); + return 'Name: '.concat(this.name, ', Age: ').concat(this.age, ', ID: '). + concat(this.id, ', Description: ').concat(this.description); }; TestUserClass.prototype.getProtectedInfo = function () { - return "ID: ".concat(this.id); + return 'ID: '.concat(this.id); }; return TestUserClass; }()); exports.TestUserClass = TestUserClass; -var TestSecondClass = /** @class */ (function (_super) { +let TestSecondClass = /** @class */ (function (_super) { __extends(TestSecondClass, _super); - function TestSecondClass() { - return _super !== null && _super.apply(this, arguments) || this; + function TestSecondClass(...args) { + return _super !== null && _super.apply(this, args) || this; } TestSecondClass.prototype.getProtectedId = function () { return this.id; @@ -69,10 +74,10 @@ function getName(obj) { return obj.name; } exports.getName = getName; -function getDetailse(obj) { +function getDetails(obj) { return obj.getDetails(); } -exports.getDetailse = getDetailse; +exports.getDetails = getDetails; function changeName(obj, name) { obj.name = name; return obj.name; @@ -96,7 +101,7 @@ function getObjectId(obj) { exports.getObjectId = getObjectId; exports.testObjCls = new TestUserClass('TestName', 30, 456, 'testEdu', 'testDescription'); exports.testSecondObjCls = new TestSecondClass('TestNameTwo', 40, 789, 'testEdu1', 'testDescription1'); -var testInnerObject = { 'id': 123 }; +let testInnerObject = { 'id': 123 }; exports.testOuterObject = { 'id': 456, testInnerObject: testInnerObject }; function getOuterObj(obj) { return obj.testInnerObject.id; diff --git a/static_core/plugins/ets/tests/interop_js/tests/objects_passing/objects_passing.sts b/static_core/plugins/ets/tests/interop_js/tests/objects_passing/objects_passing.sts index 29fd3a2387..f2b7b1d7e7 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/objects_passing/objects_passing.sts +++ b/static_core/plugins/ets/tests/interop_js/tests/objects_passing/objects_passing.sts @@ -15,7 +15,7 @@ // Pass ArkTS object to JS (wrapping) (ArkTS calls TS) -import {updateObjectId, getOuterObj, testOuterObject, testSecondObjCls, testObjCls, testObject, getName, getDetailse, changeName, getEdu, getObjectId, getId, getObjectName} from "/plugins/ets/tests/interop_js/tests/objects_passing/objects_passing.js" +import {updateObjectId, getOuterObj, testOuterObject, testSecondObjCls, testObjCls, testObject, getName, getDetails, changeName, getEdu, getObjectId, getId, getObjectName} from "/plugins/ets/tests/interop_js/tests/objects_passing/objects_passing.js" //Test 1 Get public property function getPublicProperty():string{ @@ -26,7 +26,7 @@ import {updateObjectId, getOuterObj, testOuterObject, testSecondObjCls, testObjC // Test 2 Use public method function usePublicMethod():string{ - return getDetailse(testObjCls) + return getDetails(testObjCls) } // Test 3 Change public propeerty diff --git a/static_core/plugins/ets/tests/interop_js/tests/objects_passing/objects_passing.ts b/static_core/plugins/ets/tests/interop_js/tests/objects_passing/objects_passing.ts index 3c0d068161..f7db11cb00 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/objects_passing/objects_passing.ts +++ b/static_core/plugins/ets/tests/interop_js/tests/objects_passing/objects_passing.ts @@ -30,21 +30,18 @@ export class TestUserClass { this.id = id; this.description = description; this.education = education; - } public getDetails(): string { return `Name: ${this.name}, Age: ${this.age}, ID: ${this.id}, Description: ${this.description}`; } - protected getProtectedInfo(): string { return `ID: ${this.id}`; } +}; -} - -export class TestSecondClass extends TestUserClass{ +export class TestSecondClass extends TestUserClass { public getProtectedId(): number { return this.id; } @@ -52,70 +49,62 @@ export class TestSecondClass extends TestUserClass{ public getInfo(): string { return this.getProtectedInfo(); } -} +}; export interface TestObjectType { name: string; - id: number - -} + id: number; +}; export const testObject:TestObjectType = { name:'TestName', id: 555 - +}; + + + + +export function getName(obj: TestUserClass): string { + return obj.name; +} + +export function getDetails(obj: TestUserClass): string { + return obj.getDetails(); +} + +export function changeName(obj: TestUserClass, name: string): Object { + obj.name = name; + return obj.name; +} + +export function getEdu(obj: TestUserClass): string { + return obj.education; } - - -export function getName(obj:TestUserClass):string{ - return obj.name +export function getId(obj: TestSecondClass): number { + return obj.getProtectedId(); } -export function getDetailse(obj:TestUserClass):string{ - return obj.getDetails() +export function getObjectName(obj: TestObjectType): Object { + return obj.name; } -export function changeName(obj:TestUserClass, name:string){ - obj.name = name - return obj.name +export function getObjectId(obj: TestSecondClass): Object { + return obj.getProtectedId(); } -export function getEdu(obj:TestUserClass):string{ - return obj.education -} - - -export function getId(obj:TestSecondClass):number{ - return obj.getProtectedId() -} - - -export function getObjectName(obj:TestObjectType){ - return obj.name -} - -export function getObjectId(obj:TestSecondClass){ - return obj.getProtectedId() -} - - - - - export const testObjCls = new TestUserClass('TestName', 30, 456, 'testEdu', 'testDescription'); export const testSecondObjCls = new TestSecondClass('TestNameTwo', 40, 789, 'testEdu1', 'testDescription1'); -const testInnerObject = {'id':123} +const testInnerObject = {'id': 123}; -export const testOuterObject = {'id':456, testInnerObject:testInnerObject} +export const testOuterObject = {'id':456, testInnerObject:t estInnerObject}; -export function getOuterObj(obj){ - return obj.testInnerObject.id +export function getOuterObj(obj): Object { + return obj.testInnerObject.id; } -export function updateObjectId(obj:TestObjectType, newId:number){ - obj.id = newId - +export function updateObjectId(obj:TestObjectType, newId:number): void { + obj.id = newId; } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/interop_js/tests/objects_passing/objects_passing_sts.js b/static_core/plugins/ets/tests/interop_js/tests/objects_passing/objects_passing_sts.js index c836290e73..aa8fd63ea3 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/objects_passing/objects_passing_sts.js +++ b/static_core/plugins/ets/tests/interop_js/tests/objects_passing/objects_passing_sts.js @@ -23,37 +23,28 @@ const getOuterObject = etsMod.getFunction('getOuterObject'); const testObject = { - name:'TestName' - + name: 'TestName'; } const testInnerObject = { - id:123 - + id: 123; } const testOuterObject = { - id:456, + id: 456, testInnerObject:testInnerObject - } - - { - let ret = getValueObject(testObject); - console.log(ret) + console.log(ret); ASSERT_EQ(ret, 'TestName'); - } { - let ret = getOuterObject(testOuterObject); - console.log(ret) + console.log(ret); ASSERT_EQ(ret, 456); - } diff --git a/static_core/plugins/ets/tests/interop_js/tests/objects_passing/objects_passing_sts.test.js b/static_core/plugins/ets/tests/interop_js/tests/objects_passing/objects_passing_sts.test.js index 6affa4fb3d..6e26c6882a 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/objects_passing/objects_passing_sts.test.js +++ b/static_core/plugins/ets/tests/interop_js/tests/objects_passing/objects_passing_sts.test.js @@ -13,22 +13,22 @@ * limitations under the License. */ -const etsVm = require("lib/module/ets_interop_js_napi"); +const etsVm = require('lib/module/ets_interop_js_napi'); class TestModule { constructor(name) { - this.descriptor_prefix = 'L' + name.replaceAll('.', '/') + '/'; + this.descriptorPrefix = 'L' + name.replaceAll('.', '/') + '/'; } - getClass(name) { return etsVm.getClass(this.descriptor_prefix + name + ";") } - getFunction(name) { return etsVm.getFunction(this.descriptor_prefix + "ETSGLOBAL;", name) } + getClass(name) { return etsVm.getClass(this.descriptorPrefix + name + ';'); } + getFunction(name) { return etsVm.getFunction(this.descriptorPrefix + 'ETSGLOBAL;', name); } - static descriptor_prefix; + static descriptorPrefix; }; -function getTestModule(name) { return new TestModule(name) } +function getTestModule(name) { return new TestModule(name); } module.exports = { etsVm, getTestModule, -} +}; diff --git a/static_core/plugins/ets/tests/interop_js/tests/test_callable/test_callable.js b/static_core/plugins/ets/tests/interop_js/tests/test_callable/test_callable.js index b5c151c6da..33a0e205bf 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/test_callable/test_callable.js +++ b/static_core/plugins/ets/tests/interop_js/tests/test_callable/test_callable.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; /** * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the 'License'); @@ -13,8 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -Object.defineProperty(exports, "__esModule", { value: true }); -exports.callableTestClassInstance = exports.CallableTestClass = exports.callBoundFunction = exports.callConstructedFunction = exports.callArrowFunction = exports.callAnonymousFunction = exports.callNamedFunction = void 0; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.callableTestClassInstance = exports.CallableTestClass = exports.callBoundFunction = + exports.callConstructedFunction = exports.callArrowFunction = exports.callAnonymousFunction = + exports.callNamedFunction = void 0; function callNamedFunction(x, y) { return x + y; } diff --git a/static_core/plugins/ets/tests/interop_js/tests/test_callable/test_callable.ts b/static_core/plugins/ets/tests/interop_js/tests/test_callable/test_callable.ts index a1f4c129f3..7ba8e3c576 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/test_callable/test_callable.ts +++ b/static_core/plugins/ets/tests/interop_js/tests/test_callable/test_callable.ts @@ -22,7 +22,7 @@ export let callAnonymousFunction = function (x: number, y: number): number { return x + y; }; -export let callArrowFunction = (x: number, y: number) => x + y; +export let callArrowFunction = (x: number, y: number): Object => x + y; export const callConstructedFunction = new Function('a', 'b', 'return a + b'); @@ -36,17 +36,17 @@ export class CallableTestClass { public callBoundFunction = callBoundFunction.bind(this); } -export type TCallableTestClass = CallableTestClass -export const callableTestClassInstance = new CallableTestClass() +export type TCallableTestClass = CallableTestClass; +export const callableTestClassInstance = new CallableTestClass(); -const test = () => { +const test = (): void => { console.log([ callNamedFunction, callAnonymousFunction, callArrowFunction, callConstructedFunction, callBoundFunction - ].map(x => x(10,5))) -} + ].map(x => x(10, 5))); +}; test(); \ No newline at end of file diff --git a/static_core/plugins/ets/tests/interop_js/tests/test_composite_types/test_composite_types.js b/static_core/plugins/ets/tests/interop_js/tests/test_composite_types/test_composite_types.js index 8ca1df8eb7..5d09228867 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/test_composite_types/test_composite_types.js +++ b/static_core/plugins/ets/tests/interop_js/tests/test_composite_types/test_composite_types.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; /** * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the 'License'); @@ -13,17 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -Object.defineProperty(exports, "__esModule", { value: true }); -exports.compositeTypesTestClassInstance = exports.CompositeTypesTestClass = exports.returnInterface = exports.returnRecord = exports.returnNumArray = exports.returnStrArray = exports.returnTuple = exports.isTTupleTS = void 0; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.compositeTypesTestClassInstance = exports.CompositeTypesTestClass = exports.returnInterface = + exports.returnRecord = exports.returnNumArray = exports.returnStrArray = exports.returnTuple = + exports.isTTupleTS = void 0; + const TEST_STRING = 'This is a test string'; const TEST_INT = 100; const TEST_BOOLEAN = true; const isTTupleTS = (testedVar) => { - return Array.isArray(testedVar) - && testedVar.length === 3 - && typeof testedVar[0] === 'string' - && typeof testedVar[1] === 'number' - && typeof testedVar[2] === 'boolean'; + return Array.isArray(testedVar) && + testedVar.length === 3 && + typeof testedVar[0] === 'string' && + typeof testedVar[1] === 'number' && + typeof testedVar[2] === 'boolean'; }; exports.isTTupleTS = isTTupleTS; const testTuple = [TEST_STRING, TEST_INT, TEST_BOOLEAN]; @@ -32,7 +35,7 @@ const returnTuple = function returnTuple() { }; exports.returnTuple = returnTuple; const returnStrArray = function returnArray() { - const testArray = ["One", "Two", "Three"]; + const testArray = ['One', 'Two', 'Three']; return testArray; }; exports.returnStrArray = returnStrArray; diff --git a/static_core/plugins/ets/tests/interop_js/tests/test_composite_types/test_composite_types.ts b/static_core/plugins/ets/tests/interop_js/tests/test_composite_types/test_composite_types.ts index f3b3da96a5..67cb89482b 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/test_composite_types/test_composite_types.ts +++ b/static_core/plugins/ets/tests/interop_js/tests/test_composite_types/test_composite_types.ts @@ -13,79 +13,83 @@ * limitations under the License. */ -const TEST_STRING = 'This is a test string' -const TEST_INT = 100 -const TEST_BOOLEAN = true +const TEST_STRING = 'This is a test string'; +const TEST_INT = 100; +const TEST_BOOLEAN = true; -export type TTuple = [ string, number, boolean ] -export type TRecord = Record +export type TTuple = [string, number, boolean]; +export type TRecord = Record; -export type TFunctionReturningValue = () => T +export type TFunctionReturningValue = () => T; -export type TReturnsTuple = TFunctionReturningValue -export type TReturnsStrArray = TFunctionReturningValue -export type TReturnsNumArray = TFunctionReturningValue -export type TReturnsRecord = TFunctionReturningValue +export type TReturnsTuple = TFunctionReturningValue; +export type TReturnsStrArray = TFunctionReturningValue; +export type TReturnsNumArray = TFunctionReturningValue; +export type TReturnsRecord = TFunctionReturningValue; -export const isTTupleTS = (testedVar: any): testedVar is TTuple => { - return Array.isArray(testedVar) - && testedVar.length === 3 - && typeof testedVar[0] === 'string' - && typeof testedVar[1] === 'number' - && typeof testedVar[2] === 'boolean' -} +type AnyType = {}; -const testTuple: TTuple = [ TEST_STRING, TEST_INT, TEST_BOOLEAN ] -export const returnTuple: TReturnsTuple = function returnTuple(){ - return testTuple -} +export const isTTupleTS = (testedVar: AnyType): testedVar is TTuple => { + return Array.isArray(testedVar) && + testedVar.length === 3 && + typeof testedVar[0] === 'string' && + typeof testedVar[1] === 'number' && + typeof testedVar[2] === 'boolean'; +}; -export const returnStrArray: TReturnsStrArray = function returnArray(){ - const testArray: string[] = ["One", "Two", "Three"] - return testArray -} -export const returnNumArray: TReturnsNumArray = function returnArrayNum(){ - const testArray: number[] = [1, 2, 3] - return testArray -} +const testTuple: TTuple = [TEST_STRING, TEST_INT, TEST_BOOLEAN]; +export const returnTuple: TReturnsTuple = function returnTuple(): Object { + return testTuple; +}; -export const returnRecord: TReturnsRecord = function returnRecord(){ +export const returnStrArray: TReturnsStrArray = function returnArray(): Object { + const testArray: string[] = ['One', 'Two', 'Three']; + return testArray; +}; + +export const returnNumArray: TReturnsNumArray = function returnArrayNum(): Object { + const testArray: number[] = [1, 2, 3]; + return testArray; +}; + +export const returnRecord: TReturnsRecord = function returnRecord(): Object { const testRecord: TRecord = { one: 1, two: 2, three: 3 - } - return testRecord -} + }; + return testRecord; +}; interface Shape { - width: number + width: number; } interface TwoDimensioned extends Shape { - length: number + length: number; } interface ThreeDimensioned extends Shape { - length: number - height: number + length: number; + height: number; } -export const returnInterface = function returnInterface(returnThreeDimensioned: boolean): TwoDimensioned|ThreeDimensioned { +export const returnInterface = function returnInterface(returnThreeDimensioned: boolean): + TwoDimensioned | ThreeDimensioned { const testTwoDimensioned: TwoDimensioned = { width: 100, length: 40, - } + }; const testThreeDimensioned: ThreeDimensioned = { width: 100, length: 50, height: 25, - } + }; if (returnThreeDimensioned) { - return testThreeDimensioned + return testThreeDimensioned; } - return testTwoDimensioned -} + return testTwoDimensioned; +}; export class CompositeTypesTestClass { public returnTuple = returnTuple.bind(this); @@ -93,26 +97,26 @@ export class CompositeTypesTestClass { public returnNumArray = returnNumArray.bind(this); public returnRecord = returnRecord.bind(this); public returnInterface = returnInterface.bind(this); -} +}; -export type TCompositeTypesTestClass = CompositeTypesTestClass -export const compositeTypesTestClassInstance = new CompositeTypesTestClass() +export type TCompositeTypesTestClass = CompositeTypesTestClass; +export const compositeTypesTestClassInstance = new CompositeTypesTestClass(); -const test = () => { +const test = (): void => { console.log([ returnTuple, returnStrArray, returnNumArray, returnRecord - ].map(x => x())) -} + ].map(x => x())); +}; -const testInterface = () => { +const testInterface = (): void => { console.log( returnInterface(true), returnInterface(false) - ) -} + ); +}; test(); testInterface(); \ No newline at end of file diff --git a/static_core/plugins/ets/tests/interop_js/tests/timer/run_timer_test.js b/static_core/plugins/ets/tests/interop_js/tests/timer/run_timer_test.js index c6fd54d477..fea0d8bce5 100644 --- a/static_core/plugins/ets/tests/interop_js/tests/timer/run_timer_test.js +++ b/static_core/plugins/ets/tests/interop_js/tests/timer/run_timer_test.js @@ -14,10 +14,10 @@ */ function runTest(test) { - console.log("Running test " + test); - let etsVm = require(process.env.MODULE_PATH + "/ets_interop_js_napi.node"); + console.log('Running test ' + test); + let etsVm = require(process.env.MODULE_PATH + '/ets_interop_js_napi.node'); if (!etsVm.createEtsRuntime(process.env.ARK_ETS_STDLIB_PATH, process.env.ARK_ETS_INTEROP_JS_GTEST_ABC_PATH, false, false)) { - console.log("Cannot create ETS runtime"); + console.log('Cannot create ETS runtime'); process.exit(1); } let res = etsVm.call(test); @@ -26,20 +26,20 @@ function runTest(test) { const checkDelay = 1000; let checkCallback = () => { ++counter; - if (counter == maxCounter) { - throw new Error("Test failed: timeout."); + if (counter === maxCounter) { + throw new Error('Test failed: timeout.'); } - let result = etsVm.call("check"); + let result = etsVm.call('check'); if (!result) { setTimeout(checkCallback, checkDelay); } - } + }; setTimeout(checkCallback, checkDelay); } let args = process.argv; -if (args.length != 3) { - console.log("Expected test name"); +if (args.length !== 3) { + console.log('Expected test name'); process.exit(1); } runTest(args[2]);