diff --git a/src/cli/dts2cpp/src/gen/analyzeRaw.js b/src/cli/dts2cpp/src/gen/analyzeRaw.js index 28babcb2128eba39e2b55de946559f0b866dfb37..df61eee39b742016718af6026bb6f6ae27f2fbdc 100644 --- a/src/cli/dts2cpp/src/gen/analyzeRaw.js +++ b/src/cli/dts2cpp/src/gen/analyzeRaw.js @@ -21,9 +21,6 @@ const { NapiLog } = require("./tools/NapiLog"); // 读取和解析.d.ts文件 const filePath = '@ohos.test.d.ts'; -// const sourceCode = fs.readFileSync(filePath, 'utf-8'); -// const sourceFile = ts.createSourceFile(filePath, sourceCode, ts.ScriptTarget.Latest, true); -// let statements = sourceFile.statements // 打印语法树 function stringifyWithoutCircular(obj) { @@ -45,8 +42,6 @@ function analyzeFileRaw(fn) { const sourceFile = ts.createSourceFile(filePath, sourceCode, ts.ScriptTarget.Latest, true); let statements = sourceFile.statements - // console.log(stringifyWithoutCircular(sourceFile)); - let result = { exportDefault: [], exports: [], @@ -73,22 +68,6 @@ function analyzeFileRaw(fn) { result.declareLicense.push(licenseData) } - // let impordts = statements[1].getText(); - - // let ff = statements[1].getChildren(); - // let ffa = statements[1].getChildAt(1); - // let ffb = statements[1].getChildCount(); - // let ffc = statements[1].getLastToken(); - // let xx = statements[1].getEnd(); - - // let exportsInfo = statements[2].getText(); - - // let ff = statements[2].end - // let gg = statements[2]. - // let exportName = statements[2].expression.escapedText - - // result.exportDefault.push(exportName); - return analyzeRaw(statements, result) } @@ -98,18 +77,9 @@ function analyzeRaw(statements, result) { let matchs = re.match("export default ([a-zA-Z0-9_]+);", exportsInfo); if (matchs != null) { let exportName = re.getReg(exportsInfo, matchs.regs[1]) - // data = re.removeReg(data, matchs.regs[0]); result.exportDefault.push(exportName) } - // data = re.replaceAll(data, "\n{", "{"); - // let matchType = analyzeMatchType(matchs, data, result) - // if (matchType != null) { - // data = matchType[0] - // if (matchType[1] != null) { - // result = matchType[1] - // } - // } let data = statements[1].getText(); let namespace = analyzeMatchNamespace(matchs, data, result) if (namespace != null) { @@ -128,11 +98,6 @@ function analyzeRaw(statements, result) { result = functionMatch[1] } - // if (oldData == data) { - // NapiLog.logError("\nvvv 解析文件失败 vvv"); - // NapiLog.logError("[", data.substring(0, data.length > 64 ? 64 : data.length), "]"); - // break; - // } return result; } diff --git a/src/cli/h2dtscpp/src/src/tsGen/tsMain.js b/src/cli/h2dtscpp/src/src/tsGen/tsMain.js index 67791de484b2d5ed0c86fd2a5c94b7e7a3459db8..e36bbe40df9662a08440912e0a957e403c6cebe9 100644 --- a/src/cli/h2dtscpp/src/src/tsGen/tsMain.js +++ b/src/cli/h2dtscpp/src/src/tsGen/tsMain.js @@ -36,7 +36,6 @@ function parseFileAll(hFilePath) { // call exe file (for real runtime) let sysInfo = os.platform() let execPath = path.dirname(process.execPath) - // console.info("execPath : " + execPath) let exeFile = sysInfo === 'win32' ? path.join(execPath, "header_parser.exe") : path.join(execPath, "header_parser") cmd = exeFile + " " + hFilePath @@ -187,7 +186,6 @@ function createFuncInfo(parseFuncInfo, isClassFunc) { } let parseParams = parseFuncInfo.parameters - // console.info("parseParams: " + JSON.stringify(parseParams)) for (var i = 0; i < parseParams.length; ++i) { let param = createParam(parseParams[i]) funcInfo.params.push(param) @@ -210,7 +208,6 @@ function putFuncIntoNamespace(funcInfo, namespaces) { return } } - // NapiLog.logError('The namespace [%s] of function %s is not found.'.format(funcInfo.namespace, funcInfo.name)); } function analyzeRootTypeDef(rootInfo, parseResult) { @@ -225,11 +222,9 @@ function analyzeRootTypeDef(rootInfo, parseResult) { function analyzeRootFunction(rootInfo, parseResult) { let parseFunctions = parseResult.functions - // console.info("parseFunctions: " + JSON.stringify(parseFunctions)) for (var i = 0; i < parseFunctions.length; ++i) { // 普通方法生成模板 let funcInfo = createFuncInfo(parseFunctions[i], false) - //rootInfo.functions.push(funcInfo) if (parseFunctions[i].namespace != '') { // function in namespace putFuncIntoNamespace(funcInfo, rootInfo.namespaces) @@ -283,7 +278,6 @@ function putClassIntoNamespace(classInfo, namespaces) { return } } - // NapiLog.logError('The namespace [%s] of class %s is not found.'.format(classInfo.namespace, classInfo.name)); } function analyzeClasses(rootInfo, parseResult) { @@ -462,8 +456,6 @@ function removeMarco(hFilePath, tempFilePath, macros) { let processedContent = ''; // 逐行读取文件内容并处理 去除方法中的宏 rl.on('line', (line) => { - // void *(CJSON_CDECL *malloc_fn)(size_t sz); - // CJSON_PUBLIC(const char*) cJSON_Version(void); // 替换使用宏的地方,保留#define宏定义 if (line.indexOf('#define') < 0 && line.indexOf('#ifndef') < 0 && line.indexOf('#ifdef') && line.indexOf('#elif') && line.indexOf('#if') < 0 && line.indexOf('#else')) { @@ -511,7 +503,6 @@ function extractMacros(headerFilePath) { // 匹配#define指令的正则表达式 const macroRegex = /^\s*#define\s+(\w+)/gm; - // const macroRegex = /^\s*#define\s+(\w+)(?:\s+([^\s]+))?.*$/gm; let match; const macros = []; diff --git a/test/storytest/test_$/test.js b/test/storytest/test_$/test.js index 58c678eaba526fbf8ee5f96833ba045439c20621..a53e35fa6b86e089551c16f67f6e06d60bb826e4 100644 --- a/test/storytest/test_$/test.js +++ b/test/storytest/test_$/test.js @@ -17,32 +17,36 @@ const { Test, Person } = require("./out/build/Release/napitest") var assert = require("assert"); describe('$', function () { - // interface Test { - // $name: string; - // $listInputMethod(V: string): void; - // } + /* 测试 + interface Test { + $name: string; + $listInputMethod(V: string): void; + } + */ it('test $listInputMethod', function () { let te = new Test(); let ret = te.$listInputMethod("1"); assert.deepStrictEqual(typeof ret, 'undefined'); }); - // class Person { - // static $getMaxAge(v1: string): number; - // } + /* 测试 + class Person { + static $getMaxAge(v1: string): number; + } + */ it('test $getMaxAge', function () { let pe = new Person(); let ret = pe.$getMaxAge("1"); assert.strictEqual(ret, 0); }); - // function $fun2(v: string): string; + // 测试:function $fun2(v: string): string; it('test $fun2', function () { let ret = test.$fun2("1"); assert.strictEqual(ret, ''); }); - // function fun3(v: Test): number; + // 测试:function fun3(v: Test): number; it('test fun3', function () { let ret = test.fun3('aaaaa'); assert.strictEqual(ret, 0); diff --git a/test/storytest/test_[]/test.js b/test/storytest/test_[]/test.js index 121c90aa0dc6cecd230cad4bf18eb3a439627bda..e67eb2f24c44e8ae4dad62f2ba0d9d4bcad4c2e4 100644 --- a/test/storytest/test_[]/test.js +++ b/test/storytest/test_[]/test.js @@ -16,25 +16,25 @@ const test = require("./out/build/Release/napitest") var assert = require("assert"); describe('[]', function () { - // function testArray(v: string[]): string[]; + // 测试:function testArray(v: string[]): string[]; it('test testArray', function () { let ret = test.testArray(['kkk', 'hhh']); assert.deepStrictEqual(ret, []); }); - // function testArray1(v: number[]): number[]; + // 测试:function testArray1(v: number[]): number[]; it('test testArray1', function () { let ret = test.testArray1([15, 18]); assert.deepStrictEqual(ret, []); }); - // function testArray2(v: boolean[]): boolean[]; + // 测试:function testArray2(v: boolean[]): boolean[]; it('test testArray2', function () { let ret = test.testArray2([true, false]); assert.deepStrictEqual(ret, []); }); - // function fun4(v1: string[], v2: Test[]): number[]; + // 测试:function fun4(v1: string[], v2: Test[]): number[]; it('test fun4', function () { let ret = test.fun4( ['kkk', 'hhh'], [{ 'name': 'kkk', 'age': 18 }, @@ -42,21 +42,21 @@ describe('[]', function () { assert.strictEqual(JSON.stringify(ret), '[]'); }); - // function fun5(v1: number[], v2: Test[]): string[]; + // 测试:function fun5(v1: number[], v2: Test[]): string[]; it('test fun5', function () { let ret = test.fun5([12, 18], [{ 'name': 'kkk', 'age': 18 }, { 'name': 'kkk', 'age': 18 }]); assert.strictEqual(JSON.stringify(ret), '[]'); }); - // function fun6(v1: boolean[], v2: Test[]): boolean[]; + // 测试:function fun6(v1: boolean[], v2: Test[]): boolean[]; it('test fun6', function () { let ret = test.fun6([true, false], [{ 'name': 'kkk', 'age': 18 }, { 'name': 'kkk', 'age': 18 }]); assert.strictEqual(JSON.stringify(ret), '[]'); }); - // function fun21(v: string, v1: Entry[]): Entry[]; + // 测试:function fun21(v: string, v1: Entry[]): Entry[]; it('test fun21', function () { let ret = test.fun21('sdfghjk', [{ key: [11,12],value: ['aa','bb'],isExit: [true,true]}, diff --git a/test/storytest/test_any/test.js b/test/storytest/test_any/test.js index c9c1ea0cc5276b920349606e241e74481bf8fde1..8d74593f46c7bfa6575a95559050a939672a88d6 100644 --- a/test/storytest/test_any/test.js +++ b/test/storytest/test_any/test.js @@ -16,7 +16,7 @@ const { fun1 } = require("./out/build/Release/napitest") const test = require("./out/build/Release/napitest") var assert = require("assert"); -// function fun1(v: any, v1: string): number; +// 测试:function fun1(v: any, v1: string): number; describe('Any fun1', function () { it('test fun1 any num string', function () { let ret = test.fun1("1", "aa"); @@ -93,7 +93,7 @@ describe('Any fun1 array map part', function () { }); }); -// function fun2(v: number, v1: TestClass1): number; +// 测试:function fun2(v: number, v1: TestClass1): number; describe('Any fun2', function () { it('test fun2 interface any string', function () { let ret = test.fun2(15, { 'any1': 'aaa', 'focused': 'aaa' }); @@ -146,7 +146,7 @@ describe('Any fun2', function () { }); }); -// function fun4(v: number, v1: Array): number; +// 测试:function fun4(v: number, v1: Array): number; describe('Any fun4', function () { it('test fun4 Array string', function () { let ret = test.fun4(15,['aaa', 'bbb']); @@ -164,7 +164,7 @@ describe('Any fun4', function () { }); }); -// function fun5(v: string, v1: any[]): number; +// 测试:function fun5(v: string, v1: any[]): number; describe('Any fun5', function () { it('test fun5 any string', function () { let ret = test.fun5('aaa',['aaa', 'bbb']); @@ -182,7 +182,7 @@ describe('Any fun5', function () { }); }); -// function $fun6(v: boolean, param: Array): number; +// 测试:function $fun6(v: boolean, param: Array): number; describe('Any fun6', function () { it('test fun6 array string', function () { let ret = test.$fun6(true,['aaa', 'bbb']); @@ -200,7 +200,7 @@ describe('Any fun6', function () { }); }); -// function fun8(v1: string[], v?: any): number; +// 测试:function fun8(v1: string[], v?: any): number; describe('Any fun8', function () { it('test fun8 option any null', function () { let ret = test.fun8(['aaa','bbb']); diff --git a/test/storytest/test_any[]/test.js b/test/storytest/test_any[]/test.js index 616d2578e0c8b7e22f74572dd4285d36adb45674..4be5c53fb93acc1acf2f97abf18cc1fff979caa3 100644 --- a/test/storytest/test_any[]/test.js +++ b/test/storytest/test_any[]/test.js @@ -17,31 +17,31 @@ var assert = require("assert"); describe('any[]', function () { - // function fun1(v1: any[]): number; + // 测试:function fun1(v1: any[]): number; it('test fun1', function () { let ret = fun1(['a', 'b', 'c', 'd']); assert.strictEqual(ret, 0); }); - // function fun1(v1: any[]): number; + // 测试:function fun1(v1: any[]): number; it('test fun1', function () { let ret = fun1([1, 2, 3, 4]); assert.strictEqual(ret, 0); }); - // function fun2(v1: Array): number; + // 测试:function fun2(v1: Array): number; it('test fun2', function () { let ret = fun2([true, true, false, false]); assert.strictEqual(ret, 0); }); - // function fun4(v1: Array, v: number): number; + // 测试:function fun4(v1: Array, v: number): number; it('test fun4 string', function () { let ret = fun4(['a', 'b', 'c', 'd'], 0); assert.strictEqual(ret, 0); }); - // function fun4(v1: Array, v: number): number; + // 测试:function fun4(v1: Array, v: number): number; it('test fun4 number', function () { let ret = fun4([1, 2, 3, 4], 0); assert.strictEqual(ret, 0); @@ -52,25 +52,25 @@ describe('any[]', function () { assert.strictEqual(ret, 0); }); - // function fun5(v: number, v1: Array): number; + // 测试:function fun5(v: number, v1: Array): number; it('test fun5', function () { let ret = fun5(0, ['a', 'b', 'c', 'd']); assert.strictEqual(ret, 0); }); - // function fun6(v: number, v1: any): number; + // 测试:function fun6(v: number, v1: any): number; it('test fun6 string', function () { let ret = fun6(0, 'd'); assert.strictEqual(ret, 0); }); - // function fun6(v: number, v1: any): number; + // 测试:function fun6(v: number, v1: any): number; it('test fun6 number', function () { let ret = fun6(0, 1); assert.strictEqual(ret, 0); }); - // function fun6(v: number, v1: any): number; + // 测试:function fun6(v: number, v1: any): number; it('test fun6 boolean', function () { let ret = fun6(0, true); assert.strictEqual(ret, 0); diff --git a/test/storytest/test_array/test.js b/test/storytest/test_array/test.js index 878f3216e3a58f891f9102cdfc9ce0701a176882..d656f403a464f38a47fc29fe1dd64e29a8e6d471 100755 --- a/test/storytest/test_array/test.js +++ b/test/storytest/test_array/test.js @@ -24,13 +24,13 @@ describe('AsyncCallback', function () { assert.deepStrictEqual(ret, []) } - // function fun1(v1: string, v2: AsyncCallback>): void; + // 测试:function fun1(v1: string, v2: AsyncCallback>): void; it('test fun1_callback', function () { test.fun1('a', asynFun1) test.fun1('a').then(def1) }); - // function fun1(v1: string): Promise>; + // 测试:function fun1(v1: string): Promise>; it('test fun1_promise', function () { let promiseObj = test.fun1('a'); promiseObj.then(ret => { def1(ret) }) @@ -45,13 +45,13 @@ describe('AsyncCallback', function () { assert.deepStrictEqual(ret, []); } - // function fun2(v1: Array, v2: AsyncCallback>): void; + // 测试:function fun2(v1: Array, v2: AsyncCallback>): void; it('test fun2_callback', function () { test.fun2([2, 3], asynFun2); test.fun2([2, 3]).then(def2); }); - // function fun2(v1: Array): Promise>; + // 测试:function fun2(v1: Array): Promise>; it('test fun2_promise', function () { let promiseObj = test.fun2([2, 3]); promiseObj.then(ret => { def2(ret) }); @@ -68,13 +68,13 @@ describe('AsyncCallback', function () { assert.deepStrictEqual(ret, []); } - // function fun3(v1: Array, v2: AsyncCallback>): void; + // 测试:function fun3(v1: Array, v2: AsyncCallback>): void; it('test fun3_callback', function () { test.fun3([true, false], asynFun3); test.fun3([true, false]).then(def3); }); - // function fun3(v1: Array): Promise>; + // 测试:function fun3(v1: Array): Promise>; it('test fun3_promise', function () { let promiseObj = test.fun3([true, false]); promiseObj.then(ret => { def3(ret) }); @@ -83,19 +83,19 @@ describe('AsyncCallback', function () { describe('array', function () { - // function testArray(v: Array): Array; + // 测试:function testArray(v: Array): Array; it('test testArray string', function () { let ret = test.testArray(['kkk', 'hhh']); assert.deepStrictEqual(ret, []); }); - // function testArray1(v: Array): Array; + // 测试:function testArray1(v: Array): Array; it('test testArray1 number', function () { let ret = test.testArray1([15, 18]); assert.deepStrictEqual(ret, []); }); - // function testArray2(v: Array): Array; + // 测试:function testArray2(v: Array): Array; it('test testArray2 boolean', function () { let ret = test.testArray2([true, false]); assert.deepStrictEqual(ret, []); @@ -103,61 +103,61 @@ describe('array', function () { }); describe('Array/map', function () { - // function fun4(v1: Array, v2: Array): Array; + // 测试:function fun4(v1: Array, v2: Array): Array; it('test fun4', function () { let ret = test.fun4(['kkk', 'hhh'], [{ 'name': 'kkk', 'age': 18 }, { 'name': 'kkk', 'age': 18 }]); assert.deepStrictEqual(ret, []); }); - // function fun5(v1: Array, v2: Array): Array; + // 测试:function fun5(v1: Array, v2: Array): Array; it('test fun5', function () { let ret = test.fun5([12, 18], [{ 'name': 'kkk', 'age': 18 }, { 'name': 'kkk', 'age': 18 }]); assert.deepStrictEqual(ret, []); }); - // function fun6(v1: Array, v2: Array): Array; + // 测试:function fun6(v1: Array, v2: Array): Array; it('test fun6', function () { let ret = test.fun6([true, false], [{ 'name': 'kkk', 'age': 18 }, { 'name': 'kkk', 'age': 18 }]); assert.deepStrictEqual(ret, []); }); - // function fun7(v0: Array, v1: { [key: string]: Array }): number; + // 测试:function fun7(v0: Array, v1: { [key: string]: Array }): number; it('test fun7', function () { let ret = test.fun7(['hhh', 'ooo'], { 'name': ['aaa', 'bbb'], 'age': ['ccc', 'ddd'] }); assert.strictEqual(ret, 0); }); - // function fun8(v0: Array, v1: { [key: string]: Array }): number; + // 测试:function fun8(v0: Array, v1: { [key: string]: Array }): number; it('test fun8', function () { let ret = test.fun8([13, 15], { 'name': [125, 126], 'age': [145, 146] }); assert.strictEqual(ret, 0); }); - // function fun9(v0: Array, v1: { [key: string]: Array }): number; + // 测试:function fun9(v0: Array, v1: { [key: string]: Array }): number; it('test fun9', function () { let ret = test.fun9([false, true], { 'name': [true, false], 'age': [false, true] }); assert.strictEqual(ret, 0); }); - // function fun11(v1: Map>): number; + // 测试:function fun11(v1: Map>): number; it('test fun11', function () { let ret = test.fun11({ 'name': ['aaa', 'bbb'], 'age': ['ccc', 'ddd'] }); assert.strictEqual(ret, 0); }); - // function fun12(v1: Map>): string; + // 测试:function fun12(v1: Map>): string; it('test fun12', function () { let ret = test.fun12({ 'name': [111, 222], 'age': [333, 444] }); assert.strictEqual(ret, ''); }); - // function fun13(v1: Map>): boolean; + // 测试:function fun13(v1: Map>): boolean; it('test fun13', function () { let ret = test.fun13({ 'name': [true, true], 'age': [false, false] }); assert.deepStrictEqual(ret, false); @@ -169,7 +169,7 @@ describe('map', function () { assert.deepStrictEqual(ret, []) } - // function fun14(v1: Array, callback: Callback>): void; + // 测试:function fun14(v1: Array, callback: Callback>): void; it('test fun14', function () { test.fun14(['aaa', 'bbb', 'ccc'], cb1); }); @@ -178,7 +178,7 @@ describe('map', function () { assert.deepStrictEqual(ret, []) } - // function fun15(v1: Array, callback: Callback>): void; + // 测试:function fun15(v1: Array, callback: Callback>): void; it('test fun15', function () { test.fun15([12, 15, 18], cb2); }); @@ -187,7 +187,7 @@ describe('map', function () { assert.deepStrictEqual(ret, []) } - // function fun16(v1: Array, callback: Callback>): void; + // 测试:function fun16(v1: Array, callback: Callback>): void; it('test fun16', function () { test.fun16([true, true, false], cb3); }); @@ -196,12 +196,12 @@ describe('map', function () { assert.deepStrictEqual(ret, []) } - // function fun17(callback: Callback>): void; + // 测试:function fun17(callback: Callback>): void; it('test fun17', function () { test.fun17(cb4); }); - // function fun21(v: string, v1: Array): Array; + // 测试:function fun21(v: string, v1: Array): Array; it('test fun21', function () { let ret = test.fun21('sdfghjk', [{ 'key': [15, 18], 'value': ['aa', 'bb'], 'isExit': [true, true] }, diff --git a/test/storytest/test_array_map/test.js b/test/storytest/test_array_map/test.js index 3d49053e443d68771a9412e88980848bb4ef1b67..df188e653f7d81ec58208ef822863ed3cd9366cd 100644 --- a/test/storytest/test_array_map/test.js +++ b/test/storytest/test_array_map/test.js @@ -17,37 +17,37 @@ var assert = require("assert"); describe('array_map', function () { - // function fun1(v: Array<{[key: string]:string}>): number; + // 测试:function fun1(v: Array<{[key: string]:string}>): number; it('test fun1', function () { let ret = fun1([{"age":"a"}, {"name":"b"}]); assert.strictEqual(ret, 0); }); - // function fun2(v: Array<{[key: string]:number}>): number; + // 测试:function fun2(v: Array<{[key: string]:number}>): number; it('test fun2', function () { let ret = fun2([{"age":1}, {"name":2}]); assert.strictEqual(ret, 0); }); - // function fun3(v: Array<{[key: string]:boolean}>): number; + // 测试:function fun3(v: Array<{[key: string]:boolean}>): number; it('test fun3', function () { let ret = fun3([{"age":true}, {"name":false}]); assert.strictEqual(ret, 0); }); - // function fun8(v: Array>): number; + // 测试:function fun8(v: Array>): number; it('test fun8', function () { let ret = fun8([{"age":"a"}, {"name":"b"}]); assert.strictEqual(ret, 0); }); - // function fun9(v: Array>): number; + // 测试:function fun9(v: Array>): number; it('test fun9', function () { let ret = fun9([{"age":1}, {"name":2}]); assert.strictEqual(ret, 0); }); - // function fun10(v: Array>): number; + // 测试:function fun10(v: Array>): number; it('test fun10', function () { let ret = fun10([{"age":true}, {"name":false}]); assert.strictEqual(ret, 0); diff --git a/test/storytest/test_bool/test.js b/test/storytest/test_bool/test.js index 9e133260cd1bcd60544f226fb896198bff823dd9..167315cea66d67d19cac07caa22b3729a8f4b5c8 100644 --- a/test/storytest/test_bool/test.js +++ b/test/storytest/test_bool/test.js @@ -17,31 +17,31 @@ var assert = require("assert"); describe('boolean', function () { - // function fun1(v: boolean): boolean; + // 测试:function fun1(v: boolean): boolean; it('test fun1', function () { let ret = test.fun1(true); assert.deepStrictEqual(ret, false); }); - // function fun2(v1: boolean, v2: boolean[]): boolean[]; + // 测试:function fun2(v1: boolean, v2: boolean[]): boolean[]; it('test fun2', function () { let ret = test.fun2(true, [true, false]); assert.deepStrictEqual(ret, []); }); - // function fun3(v1: Array, v2: boolean): Array; + // 测试:function fun3(v1: Array, v2: boolean): Array; it('test fun3', function () { let ret = test.fun3([true, false], false); assert.deepStrictEqual(ret, []); }); - // function fun4(v: { [key: string]: boolean }): boolean; + // 测试:function fun4(v: { [key: string]: boolean }): boolean; it('test fun4', function () { let ret = test.fun4({ 'isTrue': true, 'isExit': false }); assert.deepStrictEqual(ret, false); }); - // function fun5(v1: Map, v2: boolean): boolean; + // 测试:function fun5(v1: Map, v2: boolean): boolean; it('test fun5', function () { let ret = test.fun5({ 'isTrue': true, 'isExit': false }, true); assert.deepStrictEqual(ret, false); @@ -56,13 +56,13 @@ describe('boolean', function () { assert.deepStrictEqual(ret, false); } - // function fun6(v1: number, callback: AsyncCallback): void; + // 测试:function fun6(v1: number, callback: AsyncCallback): void; it('test fun6_callback', function () { test.fun6(15, asynFun1); test.fun6(15).then(def1); }); - // function fun6(v1: number): Promise; + // 测试:function fun6(v1: number): Promise; it('test fun6_promise', function () { let promiseObj = test.fun6(15); promiseObj.then(ret => { def1(ret) }); @@ -80,13 +80,13 @@ describe('boolean', function () { assert.deepStrictEqual(ret, []); } - // function fun7(v: number, v1: AsyncCallback>): void; + // 测试:function fun7(v: number, v1: AsyncCallback>): void; it('test fun7_callback', function () { test.fun7(15, asynFun2); test.fun7(15).then(def2); }); - // function fun7(v: number): Promise>; + // 测试:function fun7(v: number): Promise>; it('test fun7_promise', function () { let promiseObj = test.fun7(15); promiseObj.then(ret => { def2(ret) }); @@ -96,12 +96,12 @@ describe('boolean', function () { assert.deepStrictEqual(ret, false) } - // function fun9(v1: number, callback: Callback): void; + // 测试:function fun9(v1: number, callback: Callback): void; it('test fun9', function () { test.fun9(15, cb1); }); - // function fun10(v1: Test): Test; + // 测试:function fun10(v1: Test): Test; it('test fun10', function () { let ret = test.fun10( { age: true, height: [false, false], width: [true, true] }); diff --git a/test/storytest/test_callback/test.js b/test/storytest/test_callback/test.js index b980892ccba911fa816fef1f72f07be360ea0967..a812f5bce23ae9e8d257258a2ff78e64c34acd72 100644 --- a/test/storytest/test_callback/test.js +++ b/test/storytest/test_callback/test.js @@ -43,12 +43,12 @@ function onCallbackVoid () { } -// cb: (wid: boolean, str: string, tc2:number) => string +// 测试:cb: (wid: boolean, str: string, tc2:number) => string function onCallbackfun9(wid, str, tc2) { return 'wid' + 'str' + 'tc2' } -// cb: (wid: boolean) => string +// 测试:cb: (wid: boolean) => string function onCallbackfun10nm(wid) { return 'fun10nm' } @@ -58,7 +58,6 @@ function onCallbackBooleanVStr (isOK) { if (isOK) { str = 'a' + 'b' } - // return 'test aaa' } function onCallbackBooleanVStrRet (isOK) { @@ -86,64 +85,64 @@ function onCallbackfun21nm(isOk) { } describe('Test interface callback', function () { - // fun11(cb: Callback): void; + // 测试:fun11(cb: Callback): void; it('test callback in interface fun11', function () { let testClass = new TestClass1(); testClass.fun11(onCallback); }); - // fun12(cb: Callback): void; + // 测试:fun12(cb: Callback): void; it('test callback in interface fun12', function () { let testClass = new TestClass1(); testClass.fun12(onVoidCallback); }); - // fun13(cb: AsyncCallback): void; + // 测试:fun13(cb: AsyncCallback): void; it('test callback in interface fun13', function () { let testClass = new TestClass1(); testClass.fun13(onAsyncCallback); }); - // fun14(cb: AsyncCallback): void; + // 测试:fun14(cb: AsyncCallback): void; it('test callback in interface fun14', function () { let testClass = new TestClass1(); testClass.fun14(onVoidAsyncCallback); }); - // function fun15(cb: Callback): string; + // 测试:function fun15(cb: Callback): string; it('test common func callback fun15', function () { let testClass = new TestClass1(); testClass.fun15(onCallbackNumStr); }); - // fun16(tt: function): void; + // 测试:fun16(tt: function): void; it('test common func callback fun16', function () { let testClass = new TestClass1(); testClass.fun16(onCallbackVoid); }); - // fun17(tt: Function): string; + // 测试:fun17(tt: Function): string; it('test common func callback fun17', function () { let testClass = new TestClass1(); let ret = testClass.fun17(onCallbackVoid); assert.strictEqual(ret, ''); }); - // fun110(cb: (wid: boolean) => string): string; + // 测试:fun110(cb: (wid: boolean) => string): string; it('test common func callback fun110', function () { let testClass = new TestClass1(); let ret = testClass.fun110(onCallbackBooleanVStrRet); assert.strictEqual(ret, ''); }); - // fun111(cb: (wid: boolean) => string): boolean; + // 测试:fun111(cb: (wid: boolean) => string): boolean; it('test common func callback fun111', function () { let testClass = new TestClass1(); let ret = testClass.fun111(onCallbackBooleanVStrRet); assert.strictEqual(ret, false); }); - // fun112(cb: (wid: boolean) => string): number; + // 测试:fun112(cb: (wid: boolean) => string): number; it('test common func callback fun112', function () { let testClass = new TestClass1(); let ret = testClass.fun112(onCallbackBooleanVStrRet); @@ -151,43 +150,43 @@ describe('Test interface callback', function () { }); // 待补充用例 - // fun210(cb: (wid: boolean) => string): boolean; - // fun211(cb: (wid: boolean) => boolean): string; - // fun212(cb: (wid: boolean) => number): string; + // 测试:fun210(cb: (wid: boolean) => string): boolean; + // 测试:fun211(cb: (wid: boolean) => boolean): string; + // 测试:fun212(cb: (wid: boolean) => number): string; }); describe('Test callback', function () { - // function fun1(cb: Callback): void; + // 测试:function fun1(cb: Callback): void; it('test common func callback fun1', function () { testObj.fun1(onCallback); }); - // function fun2(cb: Callback): void; + // 测试:function fun2(cb: Callback): void; it('test common func callback fun2', function () { testObj.fun2(onVoidCallback); }); - // function fun3(cb: AsyncCallback): void; + // 测试:function fun3(cb: AsyncCallback): void; it('test common func callback fun3', function () { testObj.fun3(onAsyncCallback); }); - // function fun4(cb: AsyncCallback): void; + // 测试:function fun4(cb: AsyncCallback): void; it('test common func callback fun4', function () { testObj.fun4(onVoidAsyncCallback); }); - // function fun5(cb: Callback): string; + // 测试:function fun5(cb: Callback): string; it('test common func callback fun5', function () { testObj.fun5(onCallbackNumStr); }); - // function fun6(tt: function): void; + // 测试:function fun6(tt: function): void; it('test common func callback fun6', function () { testObj.fun5(onCallbackVoid); }); - // fun7(tt: Function): string; + // 测试:fun7(tt: Function): string; it('test common func callback fun7', function () { let ret = testObj.fun7(onCallbackVoid); assert.strictEqual(ret, ''); @@ -195,56 +194,56 @@ describe('Test callback', function () { }); describe('Test namespace arrow callback ', function () { - // function fun8(cb: (wid: boolean) => void): string; + // 测试:function fun8(cb: (wid: boolean) => void): string; it('test common func callback fun8', function () { let ret = '' ret = testObj.fun8(onCallbackBooleanVStr); assert.strictEqual(ret, ''); }); -// function fun9(cb: (wid: boolean, str: string, tc2:number) => string): string; +// 测试:function fun9(cb: (wid: boolean, str: string, tc2:number) => string): string; it('test common func callback fun9', function () { let ret = '' ret = testObj.fun9(onCallbackfun9); assert.strictEqual(ret, ''); }); -// function fun10nm(cb: (wid: boolean) => string): string; +// 测试:function fun10nm(cb: (wid: boolean) => string): string; it('test common func callback fun10nm', function () { let ret = '' ret = testObj.fun10nm(onCallbackfun10nm); assert.strictEqual(ret, ''); }); -// function fun11nm(cb: (wid: boolean) => string): boolean; +// 测试:function fun11nm(cb: (wid: boolean) => string): boolean; it('test common func callback fun11nm', function () { let ret = '' ret = testObj.fun11nm(onCallbackfun10nm); assert.strictEqual(ret, false); }); -// function fun12nm(cb: (wid: boolean) => string): number; +// 测试:function fun12nm(cb: (wid: boolean) => string): number; it('test common func callback fun12nm', function () { let ret = '' ret = testObj.fun12nm(onCallbackfun10nm); assert.strictEqual(ret, 0); }); -// function fun20nm(cb: (wid: boolean) => string): boolean; +// 测试:function fun20nm(cb: (wid: boolean) => string): boolean; it('test common func callback fun20nm', function () { let ret = '' ret = testObj.fun20nm(onCallbackBooleanVStrRet); assert.strictEqual(ret, false); }); -// function fun21nm(cb: (wid: boolean) => boolean): string; +// 测试:function fun21nm(cb: (wid: boolean) => boolean): string; it('test common func callback fun21nm', function () { let ret = '' ret = testObj.fun21nm(onCallbackfun21nm); assert.strictEqual(ret, ''); }); -// function fun22nm(cb: (wid: boolean) => number): string; +// 测试:function fun22nm(cb: (wid: boolean) => number): string; it('test common func callback fun22nm', function () { let ret = '' ret = testObj.fun22nm(onCallbackfun22nm); diff --git a/test/storytest/test_class/test.js b/test/storytest/test_class/test.js index 3bfaf54b355181856eee638af442ef1ebf8196fe..d358ce234665d8693b3029a09e082b93fe48a0a6 100755 --- a/test/storytest/test_class/test.js +++ b/test/storytest/test_class/test.js @@ -48,13 +48,15 @@ describe('Class', function () { assert.strictEqual(retJson, '[]'); }); - // export class Woman { - // constructor(name_: string, age_: number, isMarried_: boolean, status_: TestStatus;); - // w_name: string; - // w_age: number; - // w_isMarried: boolean; - // w_status: TestStatus; - // } + /* 测试 + export class Woman { + constructor(name_: string, age_: number, isMarried_: boolean, status_: TestStatus;); + w_name: string; + w_age: number; + w_isMarried: boolean; + w_status: TestStatus; + } + */ it('test Woman constructor', function () { let tc = new Woman("haha", 22, true, test.TestStatus.START_ABILITY); console.info("w_name is " + tc.w_name); @@ -63,12 +65,14 @@ describe('Class', function () { console.info("w_status is " + tc.w_status); }); - // export class Child { - // constructor(name_: string, age_: number, status_: TestEnumString); - // w_name: string; - // w_age: number; - // w_status: TestEnumString; - // } + /* 测试 + export class Child { + constructor(name_: string, age_: number, status_: TestEnumString); + w_name: string; + w_age: number; + w_status: TestEnumString; + } + */ it('test Child constructor', function () { let tc = new Child("xixi", 10, test.TestEnumString.ACTION_SEARCH); console.info("w_name is " + tc.w_name); @@ -78,7 +82,6 @@ describe('Class', function () { }); describe('Class Exception Test', function () { - // 쳣ԣclass캯ֵöٵ쳣 it('test Woman constructor exception', function () { let ret = false; try { @@ -94,7 +97,6 @@ describe('Class Exception Test', function () { assert.strictEqual(ret, true); }); - // 쳣ԣclass캯ַöٵ쳣 it('test Child constructor exception', function () { let ret = false; try { @@ -142,101 +144,98 @@ describe('Class part2', function () { assert.deepStrictEqual(typeof ret, 'undefined'); }); - // fun9(manA: Man): string; - // class Man - // { - // name: string; - // age: number; - // } + /* 测试:fun9(manA: Man): string; + class Man + { + name: string; + age: number; + } + */ it('test TestClass1 fun9', function () { let tc = new test.TestClass1(); let ret = tc.fun9({ name: "testaa", age: 10}); assert.strictEqual(ret, ''); }); - // fun10(v: Image): Image; - // export class Image { - // width: number; - // height: number; - // toDataURL(type?: string, quality?: number): string; - // } + /* 测试:fun10(v: Image): Image; + export class Image { + width: number; + height: number; + toDataURL(type?: string, quality?: number): string; + } + */ it('test TestClass1 fun10', function () { let tc = new test.TestClass1(); let ret = tc.fun10({ width: 5, height: 10}); assert.strictEqual(ret, ''); }); - // fun11(v: LaunchReason): string; + // 测试:fun11(v: LaunchReason): string; it('test TestClass1 fun11', function () { let tc = new test.TestClass1(); let ret = tc.fun11(test.LaunchReason.START_ABILITY); assert.strictEqual(ret, ''); }); - // fun12(v: TestStatus): number; - // export enum TestStatus { - // UNKNOWN = 0, - // START_ABILITY = 1, - // CALL = 2, - // CONTINUATION = 3, - // } + /* 测试:fun12(v: TestStatus): number; + export enum TestStatus { + UNKNOWN = 0, + START_ABILITY = 1, + CALL = 2, + CONTINUATION = 3, + } + */ it('test TestClass1 fun12', function () { let tc = new test.TestClass1(); let ret = tc.fun12(test.TestStatus.CALL); assert.strictEqual(ret, ''); }); - // fun13(v: TestEnumString): number; - // export enum TestEnumString { - // ACTION_HOME = 'ohos.want.action.home', - // ACTION_DIAL = 'ohos.want.action.dial', - // ACTION_SEARCH = 'ohos.want.action.search', - // ACTION_WIRELESS_SETTINGS = 'ohos.settings.wireless', - // } + /* 测试:fun13(v: TestEnumString): number; + export enum TestEnumString { + ACTION_HOME = 'ohos.want.action.home', + ACTION_DIAL = 'ohos.want.action.dial', + ACTION_SEARCH = 'ohos.want.action.search', + ACTION_WIRELESS_SETTINGS = 'ohos.settings.wireless', + } + */ it('test TestClass1 fun13', function () { let tc = new test.TestClass1(); let ret = tc.fun13(test.TestEnumString.ACTION_DIAL); assert.strictEqual(ret, ''); }); - - // interface testClassUse { - // v0: string; - // //v1: testClassLater; - // // funceUse(n0: number): string; - // funceUse(n0: testClassLater): string; - // } }); describe('TestClass2', function () { - // func1(name : string, fp3: {nm: string, age: number}): string; + // 测试:func1(name : string, fp3: {nm: string, age: number}): string; it('test TestClass2 func1', function () { let tc = new TestClass2() let ret = tc.func1("func1p1", {nm:"aaa",age:18,flag:false}); //assert.strictEqual(ret.read, 0); }); - // func2(input: string): { read: number; written: number; flag: boolean }; + // 测试:func2(input: string): { read: number; written: number; flag: boolean }; it('test TestClass2 func2', function () { let tc = new TestClass2() let ret = tc.func2("name"); //assert.strictEqual(ret.read, 0); }); - // func3(from: string, to: string): Promise<{result: number, errMsg: string, isT: boolean}>; + // 测试:func3(from: string, to: string): Promise<{result: number, errMsg: string, isT: boolean}>; it('test TestClass2 func3', function () { let tc = new TestClass2() let ret = tc.func3("from", "to"); //assert.strictEqual(ret.read, 0); }); - // func4(from: string, to: string): Promise<{result: number; errMsg: string; isT: boolean}>; + // 测试:func4(from: string, to: string): Promise<{result: number; errMsg: string; isT: boolean}>; it('test TestClass2 func4', function () { let tc = new TestClass2() let ret = tc.func4("responeFrom", "responseTo"); //assert.strictEqual(ret.read, 0); }); - // func5(v1: string, v2: number, v3: boolean); + // 测试:func5(v1: string, v2: number, v3: boolean); it('test TestClass2 func5', function () { let tc = new TestClass2() tc.func5("func5", 5, false); @@ -244,15 +243,17 @@ describe('TestClass2', function () { }); describe('Class Nest', function () { - // class Demo { - // equals(other: Demo): boolean; - // handleCallback(): void; - // intPro: number; - // strPro: string; - // boolPro: boolean; - // inter: aa; - // type: Type; - // } + /* 测试 + class Demo { + equals(other: Demo): boolean; + handleCallback(): void; + intPro: number; + strPro: string; + boolPro: boolean; + inter: aa; + type: Type; + } + */ it('test Demo equals', function () { let tc1 = new test.Demo(); let ret = tc1.equals({ @@ -265,23 +266,25 @@ describe('Class Nest', function () { assert.strictEqual(ret, false); }); - // class Test { - // type: Type; - // func(param: Type): boolean; - // } + /* 测试 + class Test { + type: Type; + func(param: Type): boolean; + } + */ it('test Test func', function () { let tc1 = new test.Test(); let ret = tc1.func(test.Type.typeB); assert.strictEqual(ret, false); }); - // function funcTest(v: Type): boolean; + // 测试:function funcTest(v: Type): boolean; it('test funcTest', function () { let ret = test.funcTest(test.Type.typeA); assert.strictEqual(ret, false); }); - // function funcTest2(v: Test): boolean; + // 测试:function funcTest2(v: Test): boolean; it('test funcTest2', function () { let ret = test.funcTest2({type: test.Type.typeB}); assert.strictEqual(ret, false); diff --git a/test/storytest/test_direct/test.js b/test/storytest/test_direct/test.js index ec5b53d0d94552582b83cbac1939f9d1c7fc34bb..8af3a94a7979fe8a11c20ac1ac8630d7853832a0 100755 --- a/test/storytest/test_direct/test.js +++ b/test/storytest/test_direct/test.js @@ -20,14 +20,14 @@ describe('Number', function () { assert.strictEqual(ret, 0); } - // fun1(v: number): number; + // 测试:fun1(v: number): number; it('test TestClass1 fun1', function () { let tc1 = new TestClass1(); let ret = tc1.fun1(1); assert.strictEqual(ret, 0); }); - // fun2(v: string): Result; + // 测试:fun2(v: string): Result; it('test TestClass1 fun2', function () { let tc1 = new TestClass1(); let ret = tc1.fun2('aaa'); @@ -37,7 +37,7 @@ describe('Number', function () { }); describe('Direct', function () { - // function func1(v1: string, v2: number, v3: boolean); + // 测试:function func1(v1: string, v2: number, v3: boolean); it('test func1', function () { func1('aaa', 10, true); }); diff --git a/test/storytest/test_enum/test.js b/test/storytest/test_enum/test.js index d24447e46662f3ac48842e137cdb7f85d76da332..9eaca9dfb5a6cb4b0c5ab0c3c7a67c99d8c6eaac 100644 --- a/test/storytest/test_enum/test.js +++ b/test/storytest/test_enum/test.js @@ -18,25 +18,25 @@ const test = require("./out/build/Release/napitest") var assert = require("assert"); describe('enum', function () { - // function fun1(v0: string, v1: GrantStatus): GrantStatus; + // 测试:function fun1(v0: string, v1: GrantStatus): GrantStatus; it('test fun1', function () { let ret = fun1('aaaa', test.GrantStatus.PERMISSION_DENIED); assert.strictEqual(ret, test.GrantStatus.PERMISSION_DEFAULT); }); - // function fun2(v0: number, v1: LaunchReason): LaunchReason; + // 测试:function fun2(v0: number, v1: LaunchReason): LaunchReason; it('test fun2', function () { let ret = fun2(18, test.LaunchReason.START_ABILITY); assert.strictEqual(ret, test.LaunchReason.UNKNOWN); }); - // function fun3(v0: string, v1: Action): Action; + // 测试:function fun3(v0: string, v1: Action): Action; it('test fun3', function () { let ret = fun3('ggg', test.Action.ACTION_DIAL); assert.strictEqual(ret, ''); }); - // function fun4(v0: number, v1: PlayingState): PlayingState; + // 测试:function fun4(v0: number, v1: PlayingState): PlayingState; it('test fun4', function () { let ret = fun4(18, test.PlayingState.STATE_PLAYING); assert.strictEqual(ret, 0); @@ -46,7 +46,7 @@ describe('enum', function () { assert.deepStrictEqual(ret, test.LaunchReason.UNKNOWN); } - // function fun5(V0: string, callback: Callback): void; + // 测试:function fun5(V0: string, callback: Callback): void; it('test fun5', function () { fun5('aaa', abc); }); @@ -56,7 +56,7 @@ describe('enum', function () { assert.deepStrictEqual(ret, '') } - // function fun6(v0: string, callback: AsyncCallback): void; + // 测试:function fun6(v0: string, callback: AsyncCallback): void; it('test fun6_callback', function () { fun6('hhh', asynFun1); fun6('hhh').then(def1); @@ -66,7 +66,7 @@ describe('enum', function () { assert.deepStrictEqual(ret, ''); } - // function fun6(v0: string): Promise; + // 测试:function fun6(v0: string): Promise; it('test fun6_promise', function () { let promiseObj = fun6('hhh'); promiseObj.then(ret => { def1(ret) }); @@ -78,46 +78,48 @@ describe('enum second part', function () { assert.deepStrictEqual(ret, 0); } - // function fun8(v0: string): Promise; + // 测试:function fun8(v0: string): Promise; it('test fun8_promise', function () { let promiseObj = test.fun8('test'); promiseObj.then(ret => { def2(ret) }); }); - // function fun9(v0: PlayingTest): string; + // 测试:function fun9(v0: PlayingTest): string; it('test fun9', function () { let ret = test.fun9(test.PlayingTest.STATE_TEST_START); assert.strictEqual(ret, ''); }); - // function fun10(v: TestStatus): string; + // 测试:function fun10(v: TestStatus): string; it('test fun10', function () { let ret = test.fun10(test.PlayingTest.STATE_TEST_START); assert.strictEqual(ret, ''); }) - // function fun11(v: EnumString): string; - // export enum EnumString { - // ENUM_HOME = 'ohos.want.enum.home', - // ENUM_DIAL = 'ohos.want.enum.dial', - // ENUM_SEARCH = 'ohos.want.enum.search', - // ENUM_WIRELESS_SETTINGS = 'ohos.settings.enum.wireless', - // } + /* 测试 + function fun11(v: EnumString): string; + export enum EnumString { + ENUM_HOME = 'ohos.want.enum.home', + ENUM_DIAL = 'ohos.want.enum.dial', + ENUM_SEARCH = 'ohos.want.enum.search', + ENUM_WIRELESS_SETTINGS = 'ohos.settings.enum.wireless', + } + */ it('test fun11', function () { let ret = test.fun11(test.EnumString.ENUM_SEARCH); assert.strictEqual(ret, ''); }) - // function fun12(v: HttpStatus): number; + // 测试:function fun12(v: HttpStatus): number; it('test fun12', function () { let ret = test.fun12(test.HttpStatus.STATUS0); assert.strictEqual(ret, 0); }); }); -// Input exception testing +// 测试:Input exception testing describe('enum third part', function () { - // function fun1(v0: string, v1: GrantStatus): GrantStatus; + // 测试:function fun1(v0: string, v1: GrantStatus): GrantStatus; it('test fun1 exception ', function () { let ret2 = false; try { @@ -129,7 +131,7 @@ describe('enum third part', function () { assert.strictEqual(ret2, true) }); - // function fun2(v0: number, v1: LaunchReason): LaunchReason; + // 测试:function fun2(v0: number, v1: LaunchReason): LaunchReason; it('test fun2 exception', function () { let ret3 = false; try { @@ -141,7 +143,7 @@ describe('enum third part', function () { assert.strictEqual(ret3, true) }); - // function fun3(v0: string, v1: Action): Action; + // 测试:function fun3(v0: string, v1: Action): Action; it('test fun3 exception', function () { let ret2 = false; try { @@ -153,7 +155,7 @@ describe('enum third part', function () { assert.strictEqual(ret2, true) }); - // function fun4(v0: number, v1: PlayingState): PlayingState; + // 测试:function fun4(v0: number, v1: PlayingState): PlayingState; it('test fun4 exception', function () { let ret3 = false; try { @@ -165,7 +167,7 @@ describe('enum third part', function () { assert.strictEqual(ret3, true) }); - // function fun12(v: HttpStatus): number; + // 测试:function fun12(v: HttpStatus): number; it('test fun12 exception', function () { let ret3 = false; try { diff --git a/test/storytest/test_enum_interface/test.js b/test/storytest/test_enum_interface/test.js index 0e19bda7f7e495cf0c440a14bcb868c492b4155e..74496547e62c3c2a825354c278ffc4e763ec484d 100644 --- a/test/storytest/test_enum_interface/test.js +++ b/test/storytest/test_enum_interface/test.js @@ -22,7 +22,7 @@ describe('test_Interface', function () { assert.strictEqual(ret, ''); } - // function getProperties(callback: AsyncCallback): void; + // 测试:function getProperties(callback: AsyncCallback): void; it('test getProperties', function () { getProperties().then(abc); }); @@ -31,9 +31,11 @@ describe('test_Interface', function () { describe('test_Interface2', function () { let tc = new NodeSayHello() it('test interfaceFunc', function () { - // interface NodeSayHello { - // interfaceFunc(v0: string, v1: WindowType): boolean; - // } + /* 测试 + interface NodeSayHello { + interfaceFunc(v0: string, v1: WindowType): boolean; + } + */ let ret = tc.interfaceFunc('hello', 5); assert.strictEqual(ret, false); }); @@ -42,9 +44,11 @@ describe('test_Interface2', function () { describe('test_Class', function () { let tc1 = new NodeSayHi() - // export class NodeSayHi { - // classFunc(v0: WindowType, v1: number): string; // Class中的方法参数是枚举 - // } + /* 测试 + export class NodeSayHi { + classFunc(v0: WindowType, v1: number): string; // Class中的方法参数是枚举 + } + */ it('test classFunc', function () { let ret = tc1.classFunc(6, 8); assert.strictEqual(ret, ''); @@ -53,7 +57,7 @@ describe('test_Class', function () { describe('test_Function', function () { it('test enumParamFunc', function () { - // function enumParamFunc(v0: boolean, v1: WindowType): number; + // 测试:function enumParamFunc(v0: boolean, v1: WindowType): number; let ret = enumParamFunc(true, WindowType.TYPE_APP); assert.strictEqual(ret, 0); }); diff --git a/test/storytest/test_interface/test.js b/test/storytest/test_interface/test.js index d93a24c5f43160b32fa8446852035fae429b3476..1b823102cdfd1178f9d38494351cd84f5ff509a3 100755 --- a/test/storytest/test_interface/test.js +++ b/test/storytest/test_interface/test.js @@ -21,14 +21,14 @@ const { consumers } = require("stream"); describe('Interface', function () { - // fun1(v: number): number; + // 测试:fun1(v: number): number; it('test TestClass1 fun1', function () { let tc1 = new TestClass1(); let ret = tc1.fun1(1); assert.strictEqual(ret, 0); }); - // fun2(numcc: Array, mancc: Human): Human; + // 测试:fun2(numcc: Array, mancc: Human): Human; it('test TestClass1 fun2', function () { let tc = new TestClass1(); let ret = tc.fun2([1, 2, 3], { name: 'haha', age: 20 }); @@ -36,14 +36,14 @@ describe('Interface', function () { assert.strictEqual(retJson, '{"name":"","age":0}'); }); - // fun3: (v: number, v1: string, v2: boolean) => boolean; + // 测试:fun3: (v: number, v1: string, v2: boolean) => boolean; it('test TestClass1 fun3', function () { let tc = new TestClass1(); let ret = tc.fun3(2,'aaa',true); assert.strictEqual(ret, false); }); - // fun4: (mancc: Map,v?: string) => Array; + // 测试:fun4: (mancc: Map,v?: string) => Array; it('test TestClass1 fun4', function () { let tc = new test.TestClass1(); let ret = tc.fun4({ 'name': 'haha', 'age': '20' }); @@ -57,7 +57,7 @@ describe('Interface', function () { describe('Interface', function () { - // fun5: (data: Array) => Human; + // 测试:fun5: (data: Array) => Human; it('test TestClass1 fun5', function () { let tc = new test.TestClass1(); let ret = tc.fun5( @@ -66,7 +66,7 @@ describe('Interface', function () { assert.strictEqual(retJson, '{"name":"","age":0}'); }); - // fun6: (v: string[], v1: { [key: string]: boolean }) => string[]; + // 测试:fun6: (v: string[], v1: { [key: string]: boolean }) => string[]; it('test TestClass1 fun6', function () { let tc = new test.TestClass1(); let ret = tc.fun6(['11','22','33'],{'isExit':true,'isTrue':false}); @@ -74,45 +74,48 @@ describe('Interface', function () { assert.strictEqual(retJson, '[]'); }); - // fun8: () => void; + // 测试:fun8: () => void; it('test TestClass1 fun8', function () { let tc = new test.TestClass1(); let ret = tc.fun8(); assert.deepStrictEqual(typeof ret, 'undefined'); }); - // fun9(manA: Man): void; - // interface Man - // { - // name: string; - // age: number; - // } + /* 测试:fun9(manA: Man): void; + interface Man + { + name: string; + age: number; + } + */ it('test TestClass1 fun9', function () { let tc = new test.TestClass1(); let ret = tc.fun9({name: 'asa', age: 3}); assert.deepStrictEqual(typeof ret, 'undefined'); }); - // fun12(v: TestStatus): string; - // export enum TestStatus { - // UNKNOWN = 0, - // START_ABILITY = 1, - // CALL = 2, - // CONTINUATION = 3, - // } + /* 测试:fun12(v: TestStatus): string; + export enum TestStatus { + UNKNOWN = 0, + START_ABILITY = 1, + CALL = 2, + CONTINUATION = 3, + } + */ it('test TestClass1 fun12', function () { let tc = new test.TestClass1(); let ret = tc.fun12(test.TestStatus.CONTINUATION); assert.strictEqual(ret, 0); }); - // fun13(v: TestEnumString): string; - // export enum TestEnumString { - // ACTION_HOME = 'ohos.want.action.home', - // ACTION_DIAL = 'ohos.want.action.dial', - // ACTION_SEARCH = 'ohos.want.action.search', - // ACTION_WIRELESS_SETTINGS = 'ohos.settings.wireless', - // } + /* 测试:fun13(v: TestEnumString): string; + export enum TestEnumString { + ACTION_HOME = 'ohos.want.action.home', + ACTION_DIAL = 'ohos.want.action.dial', + ACTION_SEARCH = 'ohos.want.action.search', + ACTION_WIRELESS_SETTINGS = 'ohos.settings.wireless', + } + */ it('test TestClass1 fun13', function () { let tc = new test.TestClass1(); let ret = tc.fun13(test.TestEnumString.ACTION_SEARCH); @@ -121,7 +124,7 @@ describe('Interface', function () { }); describe('Interface', function () { - // fun16(v1: number, v2: string, v3: boolean); + // 测试:fun16(v1: number, v2: string, v3: boolean); it('test TestClass1 fun16', function () { let tc = new TestClass1() tc.fun16(5, "fun16",false); @@ -200,13 +203,15 @@ describe('Interface Optional Param func2', function () { assert.strictEqual(retJson, '""'); }); - // fun1(v: number): number; - // interface testInterfaceUse { - // v0: string; - // //v1: testInterfaceLater; - // // funceUse(n0: number): string; - // funceUse(n0: testInterfaceLater): string; - // } + /* 测试 + fun1(v: number): number; + interface testInterfaceUse { + v0: string; + //v1: testInterfaceLater; + // funceUse(n0: number): string; + funceUse(n0: testInterfaceLater): string; + } + */ it('test TestInterfaceUse funceUse', function () { let testLater = new TestInterfaceLater(); let tUse = new TestInterfaceUse(); diff --git a/test/storytest/test_interface_no_name/test.js b/test/storytest/test_interface_no_name/test.js index 5d1333c6e3f718981957106d55be477fa396a259..1ee445ad5aac7ded67363370ac1a87d9274d9ca3 100644 --- a/test/storytest/test_interface_no_name/test.js +++ b/test/storytest/test_interface_no_name/test.js @@ -32,55 +32,53 @@ describe('interface_no_name', function () { } } - // function fun1(mancc: {name: string, age: number}): string; + // 测试:function fun1(mancc: {name: string, age: number}): string; it('test interface_no_name fun1', function () { let ret = fun1({"name":"abc","age":20}); assert.strictEqual(ret, ''); }); - // function fun2(fp2: TestInterface): string; + // 测试:function fun2(fp2: TestInterface): string; it('test interface_no_name fun2', function () { let ret = fun2(fp2); //assert.strictEqual(ret, ''); }); - // function fun3(name : string, fp3: {nm: string, age: number}): string; + // 测试:function fun3(name : string, fp3: {nm: string, age: number}): string; it('test interface_no_name fun3', function () { let ret = fun3("fun3p1", {nm:"abc",age:20}); //assert.strictEqual(ret, ''); }); - // function fun4(input: string): { read: number; written: number }; + // 测试:function fun4(input: string): { read: number; written: number }; it('test interface_no_name fun4', function () { let ret = fun4("name"); //assert.strictEqual(ret.read, 0); }); - // function fun5(value: {xOffset: number, animation: { duration: number, curve: string}}); + // 测试:function fun5(value: {xOffset: number, animation: { duration: number, curve: string}}); it('test interface_no_name fun5', function () { fun5(value); - //let ret = fun5(value); - //assert.strictEqual(ret, void); }); - // function fun6(nm: string, value: {xOffset: number, animation: { duration: number, curve: string}}); + // 测试:function fun6(nm: string, value: {xOffset: number, animation: { duration: number, curve: string}}); it('test interface_no_name fun6', function () { fun6("name", value); }); - // function fun7(nm: string, value: {xOffset: number; animation: { duration: number; curve: string}}); + // 测试:function fun7(nm: string, value: {xOffset: number; animation: { duration: number; curve: string}}); it('test interface_no_name fun7', function () { fun7("name", value); }); - // function fun8(from: string): Promise<{result: number; errMsg: string; isT: boolean}>; + // 测试:function fun8(from: string): Promise<{result: number; errMsg: string; isT: boolean}>; it('test interface_no_name fun8', function () { let ret = fun8("name"); //assert.strictEqual(ret.read, 0); }); - // function fun9(from: string): Promise<{result: number, errMsg: string, isT: boolean}>; + // 测试:function fun9(from: string): Promise<{result: number, errMsg: string, isT: boolean}>; it('test interface_no_name fun9', function () { let ret = fun9("name"); //assert.strictEqual(ret.read, 0); @@ -88,28 +86,28 @@ describe('interface_no_name', function () { }); describe('TestInterfaceBB', function () { - // func1(name : string, fp3: {nm: string, age: number}): string; + // 测试:func1(name : string, fp3: {nm: string, age: number}): string; it('test interface_no_name func1', function () { let tc = new TestInterfaceBB() let ret = tc.func1("func1p1", {nm:"aaa",age:18,flag:false}); //assert.strictEqual(ret.read, 0); }); - // func2(input: string): { read: number; written: number; flag: boolean }; + // 测试:func2(input: string): { read: number; written: number; flag: boolean }; it('test interface_no_name func2', function () { let tc = new TestInterfaceBB() let ret = tc.func2("name"); //assert.strictEqual(ret.read, 0); }); - // func3(from: string, to: string): Promise<{result: number, errMsg: string, isT: boolean}>; + // 测试:func3(from: string, to: string): Promise<{result: number, errMsg: string, isT: boolean}>; it('test interface_no_name func3', function () { let tc = new TestInterfaceBB() let ret = tc.func3("from", "to"); //assert.strictEqual(ret.read, 0); }); - // func4(from: string, to: string): Promise<{result: number; errMsg: string; isT: boolean}>; + // 测试:func4(from: string, to: string): Promise<{result: number; errMsg: string; isT: boolean}>; it('test interface_no_name func4', function () { let tc = new TestInterfaceBB() let ret = tc.func4("responeFrom", "responseTo"); diff --git a/test/storytest/test_number/test.js b/test/storytest/test_number/test.js index ab392d4d2d239f5e89afd40e6aedd5df17d02b9b..842ae23bdde17e20c42303173ecf63c39bc08a5c 100755 --- a/test/storytest/test_number/test.js +++ b/test/storytest/test_number/test.js @@ -16,31 +16,31 @@ const test = require("./out/build/Release/napitest") var assert = require("assert"); describe('number first cases', function () { - // function fun1(v: number): number; + // 测试:function fun1(v: number): number; it('test fun1', function () { let ret = test.fun1(18); assert.deepStrictEqual(ret, 0); }); - // function fun2(v1: number, v2: number[]): number[]; + // 测试:function fun2(v1: number, v2: number[]): number[]; it('test fun2', function () { let ret = test.fun2(18, [18, 20]); assert.deepStrictEqual(ret, []); }); - // function fun3(v1: Array, v2: number): Array; + // 测试:function fun3(v1: Array, v2: number): Array; it('test fun3', function () { let ret = test.fun3([18, 20], 20); assert.deepStrictEqual(ret, []); }); - // function fun4(v: { [key: string]: number }): number; + // 测试:function fun4(v: { [key: string]: number }): number; it('test fun4', function () { let ret = test.fun4({ 'isTrue': 18, 'isExit': 20 }); assert.deepStrictEqual(ret, 0); }); - // function fun5(v1: Map, v2: number): number; + // 测试:function fun5(v1: Map, v2: number): number; it('test fun5', function () { let ret = test.fun5({ 'isTrue': 18, 'isExit': 20 }, 18); assert.deepStrictEqual(ret, 0); @@ -55,13 +55,13 @@ describe('number first cases', function () { assert.deepStrictEqual(ret, 0); } - // function fun6(v1: number, callback: AsyncCallback): void; + // 测试:function fun6(v1: number, callback: AsyncCallback): void; it('test fun6_callback', function () { test.fun6(15, asynFun1); test.fun6(15).then(def1); }); - // function fun6(v1: number): Promise; + // 测试:function fun6(v1: number): Promise; it('test fun6_promise', function () { let promiseObj = test.fun6(15); promiseObj.then(ret => { def1(ret) }); @@ -78,13 +78,13 @@ describe('number second cases', function () { assert.deepStrictEqual(ret, []); } - // function fun7(v: number, v1: AsyncCallback>): void; + // 测试:function fun7(v: number, v1: AsyncCallback>): void; it('test fun7_callback', function () { test.fun7(15, asynFun2); test.fun7(15).then(def2); }); - // function fun7(v: number): Promise>; + // 测试:function fun7(v: number): Promise>; it('test fun7_promise', function () { let promiseObj = test.fun7(15); promiseObj.then(ret => { def2(ret) }); @@ -94,12 +94,12 @@ describe('number second cases', function () { assert.deepStrictEqual(ret, 0) } - // function fun9(v1: number, callback: Callback): void; + // 测试:function fun9(v1: number, callback: Callback): void; it('test fun9', function () { test.fun9(15, cb1); }); - // function fun10(v1: Test): Test; + // 测试:function fun10(v1: Test): Test; it('test fun10', function () { let ret = test.fun10({ age: 18, height: [20, 20], width: [18, 18] }); assert.deepStrictEqual(typeof ret, 'object'); diff --git a/test/storytest/test_object/test.js b/test/storytest/test_object/test.js index 70237aa54fa57317ae587d3e45b36041f5420457..ee189783ecbea31f179471f243fed5882fde9d9d 100755 --- a/test/storytest/test_object/test.js +++ b/test/storytest/test_object/test.js @@ -25,7 +25,7 @@ describe('Object interface', function () { } let tc1 = new TestClass1(); - // fun1(v: Object): number; + // 测试:fun1(v: Object): number; it('test TestClass1 fun1', function () { let ret = tc1.fun1({"age":10,"name":"nameValue"}); assert.strictEqual(ret, 0); @@ -39,25 +39,25 @@ describe('Object interface', function () { assert.strictEqual(ret,0) }); - // fun2(num: number, v: Object): number; + // 测试:fun2(num: number, v: Object): number; it('test TestClass1 fun2', function () { let ret = tc1.fun2(2, {"age":10,"name":"nameValue"}); assert.strictEqual(ret, 0); }); - // fun3(num: number, v: Object, Sam: string): number; + // 测试:fun3(num: number, v: Object, Sam: string): number; it('test TestClass1 fun3', function () { let ret = tc1.fun3(2, {"age":10,"name":"nameValue"}, "test4"); assert.strictEqual(ret, 0); }); - // fun4(numcc: number): Object; + // 测试:fun4(numcc: number): Object; it('test TestClass1 fun4', function () { let ret = tc1.fun4(2); assert.deepStrictEqual(typeof ret, 'object'); }); - // fun9(): number; + // 测试:fun9(): number; it('test TestClass1 fun9', function () { let ret = tc1.fun9(); assert.strictEqual(ret, 0); @@ -72,7 +72,7 @@ describe('Object function', function () { RADIO_1XRTT : 2, } - // function fun5(v1: Object): number; + // 测试:function fun5(v1: Object): number; it('test fun5', function () { let ret = fun5({"name":"sam","age":10}); assert.strictEqual(ret, 0); @@ -86,19 +86,19 @@ describe('Object function', function () { assert.strictEqual(ret, 0); }); - // function fun6(num1: number, v2: Object): number; + // 测试:function fun6(num1: number, v2: Object): number; it('test fun6', function () { let ret = fun6(2, {"age":10,"name":"nameValue"}); assert.strictEqual(ret, 0); }); - // function fun7(num2: number, v3: Object, nike: string): number; + // 测试:function fun7(num2: number, v3: Object, nike: string): number; it('test fun7', function () { let ret = fun7(2, {"age":10,"name":"nameValue"}, "test4"); assert.strictEqual(ret, 0); }); - // function fun8(dd: number): Object; + // 测试:function fun8(dd: number): Object; it('test fun8', function () { let ret = fun8(2); assert.deepStrictEqual(typeof ret, 'object'); diff --git a/test/storytest/test_on/test.js b/test/storytest/test_on/test.js index 4d9cb9b758121fb991f020e67a11274ce1a875cb..c2922cabbeba5559cb7b50bc89bdf98e2f5c225f 100755 --- a/test/storytest/test_on/test.js +++ b/test/storytest/test_on/test.js @@ -40,9 +40,11 @@ describe('test 1 on', function () { console.info('onCallback message = ' + message) } - // interface TestClass1 { - // on(type: string, callback: Callback): void; - // } + /* 测试 + interface TestClass1 { + on(type: string, callback: Callback): void; + } + */ let tc1 = new TestClass1(); it('test TestClass1 on', function () { ret = false; @@ -50,13 +52,15 @@ describe('test 1 on', function () { tc1.off('OnEvent', onCallback); }); - // interface ModelEvent{ - // topic: string; - // message: string; - // } - // interface TestClass2 { - // on(type: string, callback: Callback): void; // Callback为interface - // } + /* 测试 + interface ModelEvent{ + topic: string; + message: string; + } + interface TestClass2 { + on(type: string, callback: Callback): void; // Callback为interface + } + */ let tc2 = new TestClass2(); it('test TestClass2 on', function () { ret = false; @@ -64,9 +68,11 @@ describe('test 1 on', function () { tc2.off('OnEvent', onCallback2); }); - // interface TestClass3 { - // on(type: string, callback: Callback<{topic:string,message:string}>): void; // Callback为匿名interface - // } + /* 测试 + interface TestClass3 { + on(type: string, callback: Callback<{topic:string,message:string}>): void; // Callback为匿名interface + } + */ let tc3 = new TestClass3(); it('test TestClass3 on', function () { ret = false; @@ -91,9 +97,11 @@ describe('test 2 on', function () { console.info('onCallback2 inter.message = ' + inter.message) } - // interface TestClass4 { - // on(type: "heartbeat", callback: (wid: boolean) => void): void; // 箭头函数支持 - // } + /* 测试 + interface TestClass4 { + on(type: "heartbeat", callback: (wid: boolean) => void): void; // 箭头函数支持 + } + */ let tc4 = new TestClass4(); it('test TestClass4 on', function () { ret = false; @@ -101,9 +109,11 @@ describe('test 2 on', function () { tc4.off('heartbeat', onCallback); }); - // interface TestClass5 { - // on(type: "inputStart", callback: (wid: boolean, modeEv: ModelEvent) => void): void // 回调函数参数个数大于1,支持 - // } + /* 测试 + interface TestClass5 { + on(type: "inputStart", callback: (wid: boolean, modeEv: ModelEvent) => void): void // 回调函数参数个数大于1,支持 + } + */ let tc5 = new TestClass5(); it('test TestClass5 on', function () { ret = false; @@ -112,7 +122,7 @@ describe('test 2 on', function () { }); // namespace域中有多个on function - // function on(type: "onEvents", callback: (wid: number) => void): void; // 箭头函数支持 + // 测试:function on(type: "onEvents", callback: (wid: number) => void): void; // 箭头函数支持 it('test function on', function () { ret = false; on('onEvents', onCallback); @@ -145,9 +155,11 @@ describe('test 3 on', function () { console.info('onCallback3 inter.message = ' + inter.message) } - // interface TestClass6 { - // on(type: string, asyncCallback: AsyncCallback): void; - // } + /* 测试 + interface TestClass6 { + on(type: string, asyncCallback: AsyncCallback): void; + } + */ let tc6 = new TestClass6(); it('test TestClass6 on', function () { ret = false; @@ -155,9 +167,11 @@ describe('test 3 on', function () { tc6.off('test1', onCallback); }); - // interface TestClass7 { - // on(type: string, asyncCallback: AsyncCallback): void; // Callback为interface - // } + /* 测试 + interface TestClass7 { + on(type: string, asyncCallback: AsyncCallback): void; // Callback为interface + } + */ let tc7 = new TestClass7(); it('test TestClass7 on', function () { ret = false; @@ -168,27 +182,27 @@ describe('test 3 on', function () { // interface中有多个on let tc10 = new TestClass10(); it('test TestClass10 on', function () { - // on(type: "heartbeat", callback: Callback): void; + // 测试:on(type: "heartbeat", callback: Callback): void; ret = false; tc10.on('heartbeat', onCallback); tc10.off('heartbeat'); - // on(type: "enableChange", callback: Callback): void; + // 测试:on(type: "enableChange", callback: Callback): void; ret = false; tc10.on('enableChange', onCallback2); tc10.off('enableChange'); - // on(type: string, asyncCallback: AsyncCallback): void; + // 测试:on(type: string, asyncCallback: AsyncCallback): void; ret = false; tc10.on('test01', onCallback); tc10.off('test01'); - // on(type: string, callback: (wid: number) => void): void; + // 测试:on(type: string, callback: (wid: number) => void): void; ret = false; tc10.on('test02', onCallback); tc10.off('test02'); - // on(type: "inputStart", callback: (wid: boolean, modeEv: ModelEvent) => void): void + // 测试:on(type: "inputStart", callback: (wid: boolean, modeEv: ModelEvent) => void): void ret = false; tc10.on('inputStart', onCallback3); tc10.off('inputStart'); @@ -196,14 +210,14 @@ describe('test 3 on', function () { }); describe('test register/unRegister', function () { - // function registerNamespacefunc20(cb: Function); - // function unRegisterNamespacefunc20(cb: Function); + // 测试:function registerNamespacefunc20(cb: Function); + // 测试:function unRegisterNamespacefunc20(cb: Function); - // function registerNamespacefunc21(cb : (wid: number) => string); - // function unRegisterNamespacefunc21(cb : (wid: number) => string); + // 测试:function registerNamespacefunc21(cb : (wid: number) => string); + // 测试:function unRegisterNamespacefunc21(cb : (wid: number) => string); - // function registerNamespacefunc22(cb : Callback); - // function unRegisterNamespacefunc22(cb : Callback); + // 测试:function registerNamespacefunc22(cb : Callback); + // 测试:function unRegisterNamespacefunc22(cb : Callback); // cb: (wid: number) => string function onCallbackfun10nm(wid) { @@ -225,17 +239,6 @@ describe('test register/unRegister', function () { }); -// interface TestClass11 { -// registerTestfunc11(cb: Function); -// unRegisterTestfunc11(cb: Function); - -// registerTestfunc12(cb : (wid: number) => string); -// unRegisterTestfunc12(cb : (wid: number) => string); - -// registerTestfunc13(cb : Callback); -// unRegisterTestfunc13(cb : Callback); -// } - function callbackTest14(ret1, ret2) { console.info("SayInfo.from = " + ret1.from) console.info("SayInfo.fromId = " + ret1.fromId) @@ -249,12 +252,14 @@ function callbackTest14(ret1, ret2) { console.info("TestOptional.v5 = " + ret2.v5) } -// interface TestClass12 { -// registerTestfunc14(cb: (wid: SayInfo, test: TestOptional) => void); -// unRegisterTestfunc14(cb: (wid: SayInfo, test: TestOptional) => void); -// } -// function registerNamespacefunc23(cb: (wid: SayInfo, test: TestOptional) => void); -// function unRegisterNamespacefunc23(cb: (wid: SayInfo, test: TestOptional) => void); +/* 测试 +interface TestClass12 { + registerTestfunc14(cb: (wid: SayInfo, test: TestOptional) => void); + unRegisterTestfunc14(cb: (wid: SayInfo, test: TestOptional) => void); + } + function registerNamespacefunc23(cb: (wid: SayInfo, test: TestOptional) => void); + function unRegisterNamespacefunc23(cb: (wid: SayInfo, test: TestOptional) => void); +*/ describe('test register/unRegister callback interface/type param is optional', function () { let tc12 = new TestClass12(); it('test TestClass12 registerTestfunc14', function () { diff --git a/test/storytest/test_string/test.js b/test/storytest/test_string/test.js index 30d5cbeb3cefba8098b194eaa469f5271899e5a6..332e9c9f1d88e1dfb234e93f44732bec6972f798 100755 --- a/test/storytest/test_string/test.js +++ b/test/storytest/test_string/test.js @@ -16,31 +16,31 @@ const test = require("./out/build/Release/napitest") var assert = require("assert"); describe('string case', function () { - // function fun1(v: string): string; + // 测试:function fun1(v: string): string; it('test fun1', function () { let ret = test.fun1('18'); assert.deepStrictEqual(ret, ''); }); - // function fun2(v1: string, v2: string[]): string[]; + // 测试:function fun2(v1: string, v2: string[]): string[]; it('test fun2', function () { let ret = test.fun2('18', ['18', '20']); assert.deepStrictEqual(ret, []); }); - // function fun3(v1: Array, v2: string): Array; + // 测试:function fun3(v1: Array, v2: string): Array; it('test fun3', function () { let ret = test.fun3(['18', '20'], '20'); assert.deepStrictEqual(ret, []); }); - // function fun4(v: { [key: string]: string }): string; + // 测试:function fun4(v: { [key: string]: string }): string; it('test fun4', function () { let ret = test.fun4({ 'isTrue': '18', 'isExit': '20' }); assert.deepStrictEqual(ret, ''); }); - // function fun5(v1: Map, v2: string): string; + // 测试:function fun5(v1: Map, v2: string): string; it('test fun5', function () { let ret = test.fun5({ 'isTrue': '18', 'isExit': '20' }, '18'); assert.deepStrictEqual(ret, ''); @@ -53,12 +53,12 @@ describe('string case', function () { function def1(ret) { assert.deepStrictEqual(ret, ''); } - // function fun6(v1: string, callback: AsyncCallback): void; + // 测试:function fun6(v1: string, callback: AsyncCallback): void; it('test fun6_callback', function () { test.fun6('15', asynFun1); test.fun6('15').then(def1); }); - // function fun6(v1: string): Promise; + // 测试:function fun6(v1: string): Promise; it('test fun6_promise', function () { let promiseObj = test.fun6('15'); promiseObj.then(ret => { def1(ret) }); @@ -73,17 +73,17 @@ describe('string case part2', function () { function def2(ret) { assert.deepStrictEqual(ret, []); } - // function fun7(v: string, v1: AsyncCallback>): void; + // 测试:function fun7(v: string, v1: AsyncCallback>): void; it('test fun7_callback', function () { test.fun7('15', asynFun2); test.fun7('15').then(def2); }); - // function fun7(v: string): Promise>; + // 测试:function fun7(v: string): Promise>; it('test fun7_promise', function () { let promiseObj = test.fun7('15'); promiseObj.then(ret => { def2(ret) }); }); - // define callback for fun8 + // 测试:define callback for fun8 function asynFun8(err, ret) { assert.deepStrictEqual(err.code, 0) assert.deepStrictEqual(ret, []) @@ -91,12 +91,12 @@ describe('string case part2', function () { function def8(ret) { assert.deepStrictEqual(ret, []); } - // function fun8(v1: string, callback: AsyncCallback): void; + // 测试:function fun8(v1: string, callback: AsyncCallback): void; it('test fun8_AsyncCallback', function () { test.fun8('funTest', asynFun8); test.fun8('funTest').then(def8); }); - // function fun8(v1: string): Promise; + // 测试:function fun8(v1: string): Promise; it('test fun8_promise', function () { let promiseObj = test.fun8('funTest'); promiseObj.then(ret => { def8(ret) }); @@ -109,12 +109,12 @@ describe('string case part3', function () { assert.deepStrictEqual(ret, '') } - // function fun9(v1: string, callback: Callback): void; + // 测试:function fun9(v1: string, callback: Callback): void; it('test fun9', function () { test.fun9('15', cb1); }); - // function fun10(v1: Test): Test; + // 测试:function fun10(v1: Test): Test; it('test fun10', function () { let ret = test.fun10( { age: '18', height: ['20', '20'], width: ['18', '18'] }); @@ -124,22 +124,22 @@ describe('string case part3', function () { assert.deepStrictEqual(ret.width, []) }); - // function fun11(v: string, v1: string, v2: string): void; + // 测试:function fun11(v: string, v1: string, v2: string): void; it('test fun11', function () { test.fun11('15', 'bb', 'cc'); }); - //function fun12(v1: Test1): void; + // 测试:function fun12(v1: Test1): void; it('test fun12', function () { let ff = test.fun12({lon: {'isTrue': '18', 'isExit': '20' }, address: {'kvkey': 'valuetest'}}); }); - // function fun13(v: number, v1: string, v2: string): void; + // 测试:function fun13(v: number, v1: string, v2: string): void; it('test fun13', function () { test.fun13(15, 'bb', 'cc'); }); - // function fun14(v: string, v1: string, v2: number): void; + // 测试:function fun14(v: string, v1: string, v2: number): void; it('test fun14', function () { test.fun14('aa', 'bb', 10); }); diff --git a/test/storytest/test_threadsafe_func/test.js b/test/storytest/test_threadsafe_func/test.js index 16f60c8055e3c88512ab6aa84766ef3fc980ee2a..85ee15502386ceab28ff73f96adb0cbcd3f95bf9 100755 --- a/test/storytest/test_threadsafe_func/test.js +++ b/test/storytest/test_threadsafe_func/test.js @@ -17,17 +17,18 @@ const { TestClass1} = require("./out/build/Release/napitest") var assert = require("assert"); describe('threadSafe func', function () { - // function fun1(v: string): string; + // 测试:function fun1(v: string): string; it('createThreadSafeFuncTest1', function () { test.createThreadSafeFuncTest1('Test1', (value, value1) => { return value + value1 }); - // assert.deepStrictEqual(ret, ''); }); - // interface TestClass1 { - // createThreadSafeFuncClass1(name: string, callback: (value?: number, value1?: number) => number):void - // } + /* 测试 + interface TestClass1 { + createThreadSafeFuncClass1(name: string, callback: (value?: number, value1?: number) => number):void + } + */ it('TestClass1 createThreadSafeFuncClass1', function () { let ret = '' let tc = new TestClass1(); diff --git a/test/storytest/test_type/test.js b/test/storytest/test_type/test.js index 4f8f49c8399075b92dae903fafeb2f2098bc68fb..6186ca0e897925cb55add60b12f09f9daf3181b1 100644 --- a/test/storytest/test_type/test.js +++ b/test/storytest/test_type/test.js @@ -18,44 +18,44 @@ var assert = require("assert"); const { consumers } = require("stream"); describe('type function', function () { - // function fun1(v: Plant): number; + // 测试:function fun1(v: Plant): number; it('test fun1', function () { let ret = test.fun1({ tomato: 'iutluhkd', tomatoId: 52, isTomato: true }); assert.deepStrictEqual(ret, 0); }); - // function fun2(v: boolean): Plant; + // 测试:function fun2(v: boolean): Plant; it('test fun2', function () { let ret = test.fun2(true); let retJson = JSON.stringify(ret); assert.strictEqual(retJson, '{"tomato":"","tomatoId":0,"isTomato":false}'); }); - // function fun3(v0: MyString, v1: MyNumberType, v2: MyBool): boolean; + // 测试:function fun3(v0: MyString, v1: MyNumberType, v2: MyBool): boolean; it('test fun3', function () { let ret = test.fun3('missssss', 24, false); assert.deepStrictEqual(ret, false); }); - // function fun4(v: string): MyString; + // 测试:function fun4(v: string): MyString; it('test fun4', function () { let ret = test.fun4('aaa'); assert.deepStrictEqual(ret, ''); }); - // function fun5(v: number): MyNumberType; + // 测试:function fun5(v: number): MyNumberType; it('test fun5', function () { let ret = test.fun5(22); assert.deepStrictEqual(ret, 0); }); - // function fun6(v: boolean): MyBool; + // 测试:function fun6(v: boolean): MyBool; it('test fun6', function () { let ret = test.fun6(true); assert.deepStrictEqual(ret, false); }); - // function fun7(v: MyUnion): number; + // 测试:function fun7(v: MyUnion): number; it('test fun7', function () { let ret = test.fun7(true); assert.deepStrictEqual(ret, 0); @@ -65,7 +65,7 @@ describe('type function', function () { assert.deepStrictEqual(ret3, 0); }); - // function fun8(v: MyEnumType): string; + // 测试:function fun8(v: MyEnumType): string; it('test fun8', function () { let ret = test.fun8('keyup'); assert.deepStrictEqual(ret, ''); @@ -73,13 +73,14 @@ describe('type function', function () { assert.deepStrictEqual(ret2, ''); }); - // function fun9(v: Flower): string; - // type Flower = - // { - // name: string; - // Id: number; - // isMoreFlower: boolean; - // } + /* 测试:function fun9(v: Flower): string; + type Flower = + { + name: string; + Id: number; + isMoreFlower: boolean; + } + */ it('test fun9', function () { let ret = test.fun9({ name: 'mudan', Id: 10, isMoreFlower: true }); assert.deepStrictEqual(ret, ''); @@ -89,21 +90,23 @@ describe('type function', function () { }); describe('Type Function', function () { - // type OptionalTest = - // { - // ttt: number; - // param1?: string; - // param2?: number; - // param3?: boolean; - // param4?: Array; - // param5?: string[]; - // param6: Array; - // param7?: Map; - // param8?: {[key: string]: number}; - // param9: Map; - // param10?: boolean | number | string; - // } - // function fun10(v: OptionalTest): string; + /* 测试 + type OptionalTest = + { + ttt: number; + param1?: string; + param2?: number; + param3?: boolean; + param4?: Array; + param5?: string[]; + param6: Array; + param7?: Map; + param8?: {[key: string]: number}; + param9: Map; + param10?: boolean | number | string; + } + function fun10(v: OptionalTest): string; + */ it('test fun10', function () { let ret = test.fun10( { ttt: 11, param1: "param", param2: 20, param3: false, @@ -135,35 +138,35 @@ describe('Type Function', function () { }); describe('Interface', function () { - // catFunc1(v: MyString): MyString; + // 测试:catFunc1(v: MyString): MyString; it('test Animal catFunc1', function () { let tc1 = new Animal(); let ret = tc1.catFunc1('cat'); assert.deepStrictEqual(ret, ''); }); - // catFunc2(v: MyNumberType): MyNumberType; + // 测试:catFunc2(v: MyNumberType): MyNumberType; it('test Animal catFunc2', function () { let tc = new Animal(); let ret = tc.catFunc2(23); assert.deepStrictEqual(ret, 0); }); - // catFunc3(v: MyBool): MyBool; + // 测试:catFunc3(v: MyBool): MyBool; it('test Animal catFunc3', function () { let tc = new Animal(); let ret = tc.catFunc3(true); assert.deepStrictEqual(ret, false); }); - // catFunc4(v: Plant): string; + // 测试:catFunc4(v: Plant): string; it('test Animal catFunc4', function () { let tc = new test.Animal(); let ret = tc.catFunc4({ tomato: 'ImageTomato', tomatoId: 12, isTomato: true }); assert.deepStrictEqual(ret, ''); }); - // catFunc5(v: number): Plant; + // 测试:catFunc5(v: number): Plant; it('test Animal catFunc5', function () { let tc = new test.Animal(); let ret = tc.catFunc5(66);