mirror of
https://gitee.com/openharmony/arkcompiler_runtime_core
synced 2024-11-23 14:50:51 +00:00
!2367 uniform code style in few recently merged ArkTS interop tests
Merge pull request !2367 from ignatenkooleg/codecheck0827
This commit is contained in:
commit
c35330dfde
@ -93,27 +93,27 @@ TEST_F(EtsIndexedType, DISABLED_checkRecordValue)
|
||||
auto ret = CallEtsMethod<bool>("checkRecordValue");
|
||||
ASSERT_EQ(ret, true);
|
||||
}
|
||||
TEST_F(EtsIndexedType, getTypedArreyValueByIndex)
|
||||
TEST_F(EtsIndexedType, getTypedArrayValueByIndex)
|
||||
{
|
||||
auto ret = CallEtsMethod<bool>("getTypedArreyValueByIndex");
|
||||
auto ret = CallEtsMethod<bool>("getTypedArrayValueByIndex");
|
||||
ASSERT_EQ(ret, true);
|
||||
}
|
||||
// NOTE(andreypetukhov) enable after fixibng #18131
|
||||
TEST_F(EtsIndexedType, DISABLED_changeTypedArreyValueByIndex)
|
||||
TEST_F(EtsIndexedType, DISABLED_changeTypedArrayValueByIndex)
|
||||
{
|
||||
auto ret = CallEtsMethod<bool>("changeTypedArreyValueByIndex");
|
||||
auto ret = CallEtsMethod<bool>("changeTypedArrayValueByIndex");
|
||||
ASSERT_EQ(ret, true);
|
||||
}
|
||||
// NOTE(andreypetukhov) enable after fixibng #18131
|
||||
TEST_F(EtsIndexedType, DISABLED_checkLengthTypedArrey)
|
||||
TEST_F(EtsIndexedType, DISABLED_checkLengthTypedArray)
|
||||
{
|
||||
auto ret = CallEtsMethod<bool>("checkLengthTypedArrey");
|
||||
auto ret = CallEtsMethod<bool>("checkLengthTypedArray");
|
||||
ASSERT_EQ(ret, true);
|
||||
}
|
||||
// NOTE(andreypetukhov) enable after fixibng #18131
|
||||
TEST_F(EtsIndexedType, DISABLED_checkAllTypedArreyValue)
|
||||
TEST_F(EtsIndexedType, DISABLED_checkAllTypedArrayValue)
|
||||
{
|
||||
auto ret = CallEtsMethod<bool>("checkAllTypedArreyValue");
|
||||
auto ret = CallEtsMethod<bool>("checkAllTypedArrayValue");
|
||||
ASSERT_EQ(ret, true);
|
||||
}
|
||||
TEST_F(EtsIndexedType, getValueFromProxyRecord)
|
||||
|
@ -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;
|
||||
|
@ -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 = {
|
||||
|
@ -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<T> extends Array<T> {
|
||||
@ -29,9 +29,9 @@ export function returnCustomArray<T>(array: CustomArray<T>): CustomArray<T> {
|
||||
|
||||
export function createStringRecord(): Record<string, string> {
|
||||
const data: Record<string, string> = {
|
||||
'key1': "A",
|
||||
'key2': "B",
|
||||
'key3': "C"
|
||||
'key1': 'A',
|
||||
'key2': 'B',
|
||||
'key3': 'C'
|
||||
};
|
||||
return data;
|
||||
}
|
||||
@ -46,16 +46,17 @@ export function createInt8Array(length: number): Int8Array {
|
||||
|
||||
type RecordObject = Record<string, string>;
|
||||
|
||||
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;
|
||||
return true;
|
||||
|
@ -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');
|
||||
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -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,
|
||||
}
|
||||
};
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
@ -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;
|
||||
|
@ -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<string, number>
|
||||
export type TTuple = [string, number, boolean];
|
||||
export type TRecord = Record<string, number>;
|
||||
|
||||
export type TFunctionReturningValue<T> = () => T
|
||||
export type TFunctionReturningValue<T> = () => T;
|
||||
|
||||
export type TReturnsTuple = TFunctionReturningValue<TTuple>
|
||||
export type TReturnsStrArray = TFunctionReturningValue<string[]>
|
||||
export type TReturnsNumArray = TFunctionReturningValue<number[]>
|
||||
export type TReturnsRecord = TFunctionReturningValue<TRecord>
|
||||
export type TReturnsTuple = TFunctionReturningValue<TTuple>;
|
||||
export type TReturnsStrArray = TFunctionReturningValue<string[]>;
|
||||
export type TReturnsNumArray = TFunctionReturningValue<number[]>;
|
||||
export type TReturnsRecord = TFunctionReturningValue<TRecord>;
|
||||
|
||||
export const isTTupleTS = (testedVar: any): testedVar is TTuple => {
|
||||
return Array.isArray(<any>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(<AnyType>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();
|
@ -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]);
|
||||
|
Loading…
Reference in New Issue
Block a user