1/* 2* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3* Licensed under the Apache License, Version 2.0 (the "License"); 4* you may not use this file except in compliance with the License. 5* You may obtain a copy of the License at 6* 7* http://www.apache.org/licenses/LICENSE-2.0 8* 9* Unless required by applicable law or agreed to in writing, software 10* distributed under the License is distributed on an "AS IS" BASIS, 11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12* See the License for the specific language governing permissions and 13* limitations under the License. 14*/ 15const test = require("./out/build/Release/napitest") 16var assert = require("assert"); 17 18describe('AsyncCallback<string/number>', function () { 19 function asynFun1(err, ret) { 20 assert.strictEqual(err.code, 0) 21 assert.deepStrictEqual(ret, []) 22 } 23 function def1(ret) { 24 assert.deepStrictEqual(ret, []) 25 } 26 27 // 测试:function fun1(v1: string, v2: AsyncCallback<Array<string>>): void; 28 it('test fun1_callback', function () { 29 test.fun1('a', asynFun1) 30 test.fun1('a').then(def1) 31 }); 32 33 // 测试:function fun1(v1: string): Promise<Array<string>>; 34 it('test fun1_promise', function () { 35 let promiseObj = test.fun1('a'); 36 promiseObj.then(ret => { def1(ret) }) 37 }); 38 39 function asynFun2(err, ret) { 40 assert.strictEqual(err.code, 0) 41 assert.deepStrictEqual(ret, []) 42 } 43 44 function def2(ret) { 45 assert.deepStrictEqual(ret, []); 46 } 47 48 // 测试:function fun2(v1: Array<number>, v2: AsyncCallback<Array<number>>): void; 49 it('test fun2_callback', function () { 50 test.fun2([2, 3], asynFun2); 51 test.fun2([2, 3]).then(def2); 52 }); 53 54 // 测试:function fun2(v1: Array<number>): Promise<Array<number>>; 55 it('test fun2_promise', function () { 56 let promiseObj = test.fun2([2, 3]); 57 promiseObj.then(ret => { def2(ret) }); 58 }); 59}); 60 61describe('AsyncCallback<boolean>', function () { 62 function asynFun3(err, ret) { 63 assert.strictEqual(err.code, 0) 64 assert.deepStrictEqual(ret, []) 65 } 66 67 function def3(ret) { 68 assert.deepStrictEqual(ret, []); 69 } 70 71 // 测试:function fun3(v1: Array<boolean>, v2: AsyncCallback<Array<boolean>>): void; 72 it('test fun3_callback', function () { 73 test.fun3([true, false], asynFun3); 74 test.fun3([true, false]).then(def3); 75 }); 76 77 // 测试:function fun3(v1: Array<boolean>): Promise<Array<boolean>>; 78 it('test fun3_promise', function () { 79 let promiseObj = test.fun3([true, false]); 80 promiseObj.then(ret => { def3(ret) }); 81 }); 82}); 83 84describe('array<basic>', function () { 85 86 // 测试:function testArray(v: Array<string>): Array<string>; 87 it('test testArray string', function () { 88 let ret = test.testArray(['kkk', 'hhh']); 89 assert.deepStrictEqual(ret, []); 90 }); 91 92 // 测试:function testArray1(v: Array<number>): Array<number>; 93 it('test testArray1 number', function () { 94 let ret = test.testArray1([15, 18]); 95 assert.deepStrictEqual(ret, []); 96 }); 97 98 // 测试:function testArray2(v: Array<boolean>): Array<boolean>; 99 it('test testArray2 boolean', function () { 100 let ret = test.testArray2([true, false]); 101 assert.deepStrictEqual(ret, []); 102 }); 103}); 104 105describe('Array<interface>/map<array>', function () { 106 // 测试:function fun4(v1: Array<string>, v2: Array<Test>): Array<number>; 107 it('test fun4', function () { 108 let ret = test.fun4(['kkk', 'hhh'], 109 [{ 'name': 'kkk', 'age': 18 }, { 'name': 'kkk', 'age': 18 }]); 110 assert.deepStrictEqual(ret, []); 111 }); 112 113 // 测试:function fun5(v1: Array<number>, v2: Array<Test>): Array<string>; 114 it('test fun5', function () { 115 let ret = test.fun5([12, 18], 116 [{ 'name': 'kkk', 'age': 18 }, { 'name': 'kkk', 'age': 18 }]); 117 assert.deepStrictEqual(ret, []); 118 }); 119 120 // 测试:function fun6(v1: Array<boolean>, v2: Array<Test>): Array<boolean>; 121 it('test fun6', function () { 122 let ret = test.fun6([true, false], 123 [{ 'name': 'kkk', 'age': 18 }, { 'name': 'kkk', 'age': 18 }]); 124 assert.deepStrictEqual(ret, []); 125 }); 126 127 // 测试:function fun7(v0: Array<string>, v1: { [key: string]: Array<string> }): number; 128 it('test fun7', function () { 129 let ret = test.fun7(['hhh', 'ooo'], 130 { 'name': ['aaa', 'bbb'], 'age': ['ccc', 'ddd'] }); 131 assert.strictEqual(ret, 0); 132 }); 133 134 // 测试:function fun8(v0: Array<number>, v1: { [key: string]: Array<number> }): number; 135 it('test fun8', function () { 136 let ret = test.fun8([13, 15], 137 { 'name': [125, 126], 'age': [145, 146] }); 138 assert.strictEqual(ret, 0); 139 }); 140 141 // 测试:function fun9(v0: Array<boolean>, v1: { [key: string]: Array<boolean> }): number; 142 it('test fun9', function () { 143 let ret = test.fun9([false, true], 144 { 'name': [true, false], 'age': [false, true] }); 145 assert.strictEqual(ret, 0); 146 }); 147 148 // 测试:function fun11(v1: Map<string, Array<string>>): number; 149 it('test fun11', function () { 150 let ret = test.fun11({ 'name': ['aaa', 'bbb'], 'age': ['ccc', 'ddd'] }); 151 assert.strictEqual(ret, 0); 152 }); 153 154 // 测试:function fun12(v1: Map<string, Array<number>>): string; 155 it('test fun12', function () { 156 let ret = test.fun12({ 'name': [111, 222], 'age': [333, 444] }); 157 assert.strictEqual(ret, ''); 158 }); 159 160 // 测试:function fun13(v1: Map<string, Array<boolean>>): boolean; 161 it('test fun13', function () { 162 let ret = test.fun13({ 'name': [true, true], 'age': [false, false] }); 163 assert.deepStrictEqual(ret, false); 164 }); 165}); 166 167describe('map<array>', function () { 168 function cb1(ret) { 169 assert.deepStrictEqual(ret, []) 170 } 171 172 // 测试:function fun14(v1: Array<string>, callback: Callback<Array<string>>): void; 173 it('test fun14', function () { 174 test.fun14(['aaa', 'bbb', 'ccc'], cb1); 175 }); 176 177 function cb2(ret) { 178 assert.deepStrictEqual(ret, []) 179 } 180 181 // 测试:function fun15(v1: Array<number>, callback: Callback<Array<number>>): void; 182 it('test fun15', function () { 183 test.fun15([12, 15, 18], cb2); 184 }); 185 186 function cb3(ret) { 187 assert.deepStrictEqual(ret, []) 188 } 189 190 // 测试:function fun16(v1: Array<boolean>, callback: Callback<Array<boolean>>): void; 191 it('test fun16', function () { 192 test.fun16([true, true, false], cb3); 193 }); 194 195 function cb4(ret) { 196 assert.deepStrictEqual(ret, []) 197 } 198 199 // 测试:function fun17(callback: Callback<Array<Test>>): void; 200 it('test fun17', function () { 201 test.fun17(cb4); 202 }); 203 204 // 测试:function fun21(v: string, v1: Array<Entry>): Array<Entry>; 205 it('test fun21', function () { 206 let ret = test.fun21('sdfghjk', 207 [{ 'key': [15, 18], 'value': ['aa', 'bb'], 'isExit': [true, true] }, 208 { 'key': [15, 18], 'value': ['aa', 'bb'], 'isExit': [true, true] }]); 209 assert.strictEqual(typeof ret, 'object'); 210 }); 211}); 212