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('string case', function () { 19 // 测试:function fun1(v: string): string; 20 it('test fun1', function () { 21 let ret = test.fun1('18'); 22 assert.deepStrictEqual(ret, ''); 23 }); 24 25 // 测试:function fun2(v1: string, v2: string[]): string[]; 26 it('test fun2', function () { 27 let ret = test.fun2('18', ['18', '20']); 28 assert.deepStrictEqual(ret, []); 29 }); 30 31 // 测试:function fun3(v1: Array<string>, v2: string): Array<string>; 32 it('test fun3', function () { 33 let ret = test.fun3(['18', '20'], '20'); 34 assert.deepStrictEqual(ret, []); 35 }); 36 37 // 测试:function fun4(v: { [key: string]: string }): string; 38 it('test fun4', function () { 39 let ret = test.fun4({ 'isTrue': '18', 'isExit': '20' }); 40 assert.deepStrictEqual(ret, ''); 41 }); 42 43 // 测试:function fun5(v1: Map<string, string>, v2: string): string; 44 it('test fun5', function () { 45 let ret = test.fun5({ 'isTrue': '18', 'isExit': '20' }, '18'); 46 assert.deepStrictEqual(ret, ''); 47 }); 48 49 function asynFun1(err, ret) { 50 assert.strictEqual(err.code, 0) 51 assert.deepStrictEqual(ret, '') 52 } 53 function def1(ret) { 54 assert.deepStrictEqual(ret, ''); 55 } 56 // 测试:function fun6(v1: string, callback: AsyncCallback<string>): void; 57 it('test fun6_callback', function () { 58 test.fun6('15', asynFun1); 59 test.fun6('15').then(def1); 60 }); 61 // 测试:function fun6(v1: string): Promise<string>; 62 it('test fun6_promise', function () { 63 let promiseObj = test.fun6('15'); 64 promiseObj.then(ret => { def1(ret) }); 65 }); 66}); 67 68describe('string case part2', function () { 69 function asynFun2(err, ret) { 70 assert.deepStrictEqual(err.code, 0) 71 assert.deepStrictEqual(ret, []) 72 } 73 function def2(ret) { 74 assert.deepStrictEqual(ret, []); 75 } 76 // 测试:function fun7(v: string, v1: AsyncCallback<Array<string>>): void; 77 it('test fun7_callback', function () { 78 test.fun7('15', asynFun2); 79 test.fun7('15').then(def2); 80 }); 81 // 测试:function fun7(v: string): Promise<Array<string>>; 82 it('test fun7_promise', function () { 83 let promiseObj = test.fun7('15'); 84 promiseObj.then(ret => { def2(ret) }); 85 }); 86 // 测试:define callback for fun8 87 function asynFun8(err, ret) { 88 assert.deepStrictEqual(err.code, 0) 89 assert.deepStrictEqual(ret, []) 90 } 91 function def8(ret) { 92 assert.deepStrictEqual(ret, []); 93 } 94 // 测试:function fun8(v1: string, callback: AsyncCallback<string[]>): void; 95 it('test fun8_AsyncCallback', function () { 96 test.fun8('funTest', asynFun8); 97 test.fun8('funTest').then(def8); 98 }); 99 // 测试:function fun8(v1: string): Promise<string[]>; 100 it('test fun8_promise', function () { 101 let promiseObj = test.fun8('funTest'); 102 promiseObj.then(ret => { def8(ret) }); 103 }); 104}); 105 106describe('string case part3', function () { 107 108 function cb1(ret) { 109 assert.deepStrictEqual(ret, '') 110 } 111 112 // 测试:function fun9(v1: string, callback: Callback<string>): void; 113 it('test fun9', function () { 114 test.fun9('15', cb1); 115 }); 116 117 // 测试:function fun10(v1: Test): Test; 118 it('test fun10', function () { 119 let ret = test.fun10( 120 { age: '18', height: ['20', '20'], width: ['18', '18'] }); 121 assert.deepStrictEqual(typeof ret, 'object'); 122 assert.strictEqual(ret.age, '') 123 assert.deepStrictEqual(ret.height, []) 124 assert.deepStrictEqual(ret.width, []) 125 }); 126 127 // 测试:function fun11(v: string, v1: string, v2: string): void; 128 it('test fun11', function () { 129 test.fun11('15', 'bb', 'cc'); 130 }); 131 132 // 测试:function fun12(v1: Test1): void; 133 it('test fun12', function () { 134 let ff = test.fun12({lon: {'isTrue': '18', 'isExit': '20' }, address: {'kvkey': 'valuetest'}}); 135 }); 136 137 // 测试:function fun13(v: number, v1: string, v2: string): void; 138 it('test fun13', function () { 139 test.fun13(15, 'bb', 'cc'); 140 }); 141 142 // 测试:function fun14(v: string, v1: string, v2: number): void; 143 it('test fun14', function () { 144 test.fun14('aa', 'bb', 10); 145 }); 146});