18c339a94Sopenharmony_ci/* 28c339a94Sopenharmony_ci* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. 38c339a94Sopenharmony_ci* Licensed under the Apache License, Version 2.0 (the "License"); 48c339a94Sopenharmony_ci* you may not use this file except in compliance with the License. 58c339a94Sopenharmony_ci* You may obtain a copy of the License at 68c339a94Sopenharmony_ci* 78c339a94Sopenharmony_ci* http://www.apache.org/licenses/LICENSE-2.0 88c339a94Sopenharmony_ci* 98c339a94Sopenharmony_ci* Unless required by applicable law or agreed to in writing, software 108c339a94Sopenharmony_ci* distributed under the License is distributed on an "AS IS" BASIS, 118c339a94Sopenharmony_ci* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128c339a94Sopenharmony_ci* See the License for the specific language governing permissions and 138c339a94Sopenharmony_ci* limitations under the License. 148c339a94Sopenharmony_ci*/ 158c339a94Sopenharmony_ciconst test = require("./out/build/Release/napitest") 168c339a94Sopenharmony_civar assert = require("assert"); 178c339a94Sopenharmony_ci 188c339a94Sopenharmony_cidescribe('string case', function () { 198c339a94Sopenharmony_ci // 测试:function fun1(v: string): string; 208c339a94Sopenharmony_ci it('test fun1', function () { 218c339a94Sopenharmony_ci let ret = test.fun1('18'); 228c339a94Sopenharmony_ci assert.deepStrictEqual(ret, ''); 238c339a94Sopenharmony_ci }); 248c339a94Sopenharmony_ci 258c339a94Sopenharmony_ci // 测试:function fun2(v1: string, v2: string[]): string[]; 268c339a94Sopenharmony_ci it('test fun2', function () { 278c339a94Sopenharmony_ci let ret = test.fun2('18', ['18', '20']); 288c339a94Sopenharmony_ci assert.deepStrictEqual(ret, []); 298c339a94Sopenharmony_ci }); 308c339a94Sopenharmony_ci 318c339a94Sopenharmony_ci // 测试:function fun3(v1: Array<string>, v2: string): Array<string>; 328c339a94Sopenharmony_ci it('test fun3', function () { 338c339a94Sopenharmony_ci let ret = test.fun3(['18', '20'], '20'); 348c339a94Sopenharmony_ci assert.deepStrictEqual(ret, []); 358c339a94Sopenharmony_ci }); 368c339a94Sopenharmony_ci 378c339a94Sopenharmony_ci // 测试:function fun4(v: { [key: string]: string }): string; 388c339a94Sopenharmony_ci it('test fun4', function () { 398c339a94Sopenharmony_ci let ret = test.fun4({ 'isTrue': '18', 'isExit': '20' }); 408c339a94Sopenharmony_ci assert.deepStrictEqual(ret, ''); 418c339a94Sopenharmony_ci }); 428c339a94Sopenharmony_ci 438c339a94Sopenharmony_ci // 测试:function fun5(v1: Map<string, string>, v2: string): string; 448c339a94Sopenharmony_ci it('test fun5', function () { 458c339a94Sopenharmony_ci let ret = test.fun5({ 'isTrue': '18', 'isExit': '20' }, '18'); 468c339a94Sopenharmony_ci assert.deepStrictEqual(ret, ''); 478c339a94Sopenharmony_ci }); 488c339a94Sopenharmony_ci 498c339a94Sopenharmony_ci function asynFun1(err, ret) { 508c339a94Sopenharmony_ci assert.strictEqual(err.code, 0) 518c339a94Sopenharmony_ci assert.deepStrictEqual(ret, '') 528c339a94Sopenharmony_ci } 538c339a94Sopenharmony_ci function def1(ret) { 548c339a94Sopenharmony_ci assert.deepStrictEqual(ret, ''); 558c339a94Sopenharmony_ci } 568c339a94Sopenharmony_ci // 测试:function fun6(v1: string, callback: AsyncCallback<string>): void; 578c339a94Sopenharmony_ci it('test fun6_callback', function () { 588c339a94Sopenharmony_ci test.fun6('15', asynFun1); 598c339a94Sopenharmony_ci test.fun6('15').then(def1); 608c339a94Sopenharmony_ci }); 618c339a94Sopenharmony_ci // 测试:function fun6(v1: string): Promise<string>; 628c339a94Sopenharmony_ci it('test fun6_promise', function () { 638c339a94Sopenharmony_ci let promiseObj = test.fun6('15'); 648c339a94Sopenharmony_ci promiseObj.then(ret => { def1(ret) }); 658c339a94Sopenharmony_ci }); 668c339a94Sopenharmony_ci}); 678c339a94Sopenharmony_ci 688c339a94Sopenharmony_cidescribe('string case part2', function () { 698c339a94Sopenharmony_ci function asynFun2(err, ret) { 708c339a94Sopenharmony_ci assert.deepStrictEqual(err.code, 0) 718c339a94Sopenharmony_ci assert.deepStrictEqual(ret, []) 728c339a94Sopenharmony_ci } 738c339a94Sopenharmony_ci function def2(ret) { 748c339a94Sopenharmony_ci assert.deepStrictEqual(ret, []); 758c339a94Sopenharmony_ci } 768c339a94Sopenharmony_ci // 测试:function fun7(v: string, v1: AsyncCallback<Array<string>>): void; 778c339a94Sopenharmony_ci it('test fun7_callback', function () { 788c339a94Sopenharmony_ci test.fun7('15', asynFun2); 798c339a94Sopenharmony_ci test.fun7('15').then(def2); 808c339a94Sopenharmony_ci }); 818c339a94Sopenharmony_ci // 测试:function fun7(v: string): Promise<Array<string>>; 828c339a94Sopenharmony_ci it('test fun7_promise', function () { 838c339a94Sopenharmony_ci let promiseObj = test.fun7('15'); 848c339a94Sopenharmony_ci promiseObj.then(ret => { def2(ret) }); 858c339a94Sopenharmony_ci }); 868c339a94Sopenharmony_ci // 测试:define callback for fun8 878c339a94Sopenharmony_ci function asynFun8(err, ret) { 888c339a94Sopenharmony_ci assert.deepStrictEqual(err.code, 0) 898c339a94Sopenharmony_ci assert.deepStrictEqual(ret, []) 908c339a94Sopenharmony_ci } 918c339a94Sopenharmony_ci function def8(ret) { 928c339a94Sopenharmony_ci assert.deepStrictEqual(ret, []); 938c339a94Sopenharmony_ci } 948c339a94Sopenharmony_ci // 测试:function fun8(v1: string, callback: AsyncCallback<string[]>): void; 958c339a94Sopenharmony_ci it('test fun8_AsyncCallback', function () { 968c339a94Sopenharmony_ci test.fun8('funTest', asynFun8); 978c339a94Sopenharmony_ci test.fun8('funTest').then(def8); 988c339a94Sopenharmony_ci }); 998c339a94Sopenharmony_ci // 测试:function fun8(v1: string): Promise<string[]>; 1008c339a94Sopenharmony_ci it('test fun8_promise', function () { 1018c339a94Sopenharmony_ci let promiseObj = test.fun8('funTest'); 1028c339a94Sopenharmony_ci promiseObj.then(ret => { def8(ret) }); 1038c339a94Sopenharmony_ci }); 1048c339a94Sopenharmony_ci}); 1058c339a94Sopenharmony_ci 1068c339a94Sopenharmony_cidescribe('string case part3', function () { 1078c339a94Sopenharmony_ci 1088c339a94Sopenharmony_ci function cb1(ret) { 1098c339a94Sopenharmony_ci assert.deepStrictEqual(ret, '') 1108c339a94Sopenharmony_ci } 1118c339a94Sopenharmony_ci 1128c339a94Sopenharmony_ci // 测试:function fun9(v1: string, callback: Callback<string>): void; 1138c339a94Sopenharmony_ci it('test fun9', function () { 1148c339a94Sopenharmony_ci test.fun9('15', cb1); 1158c339a94Sopenharmony_ci }); 1168c339a94Sopenharmony_ci 1178c339a94Sopenharmony_ci // 测试:function fun10(v1: Test): Test; 1188c339a94Sopenharmony_ci it('test fun10', function () { 1198c339a94Sopenharmony_ci let ret = test.fun10( 1208c339a94Sopenharmony_ci { age: '18', height: ['20', '20'], width: ['18', '18'] }); 1218c339a94Sopenharmony_ci assert.deepStrictEqual(typeof ret, 'object'); 1228c339a94Sopenharmony_ci assert.strictEqual(ret.age, '') 1238c339a94Sopenharmony_ci assert.deepStrictEqual(ret.height, []) 1248c339a94Sopenharmony_ci assert.deepStrictEqual(ret.width, []) 1258c339a94Sopenharmony_ci }); 1268c339a94Sopenharmony_ci 1278c339a94Sopenharmony_ci // 测试:function fun11(v: string, v1: string, v2: string): void; 1288c339a94Sopenharmony_ci it('test fun11', function () { 1298c339a94Sopenharmony_ci test.fun11('15', 'bb', 'cc'); 1308c339a94Sopenharmony_ci }); 1318c339a94Sopenharmony_ci 1328c339a94Sopenharmony_ci // 测试:function fun12(v1: Test1): void; 1338c339a94Sopenharmony_ci it('test fun12', function () { 1348c339a94Sopenharmony_ci let ff = test.fun12({lon: {'isTrue': '18', 'isExit': '20' }, address: {'kvkey': 'valuetest'}}); 1358c339a94Sopenharmony_ci }); 1368c339a94Sopenharmony_ci 1378c339a94Sopenharmony_ci // 测试:function fun13(v: number, v1: string, v2: string): void; 1388c339a94Sopenharmony_ci it('test fun13', function () { 1398c339a94Sopenharmony_ci test.fun13(15, 'bb', 'cc'); 1408c339a94Sopenharmony_ci }); 1418c339a94Sopenharmony_ci 1428c339a94Sopenharmony_ci // 测试:function fun14(v: string, v1: string, v2: number): void; 1438c339a94Sopenharmony_ci it('test fun14', function () { 1448c339a94Sopenharmony_ci test.fun14('aa', 'bb', 10); 1458c339a94Sopenharmony_ci }); 1468c339a94Sopenharmony_ci});