13af6ab5fSopenharmony_ci/* 23af6ab5fSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 33af6ab5fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 43af6ab5fSopenharmony_ci * you may not use this file except in compliance with the License. 53af6ab5fSopenharmony_ci * You may obtain a copy of the License at 63af6ab5fSopenharmony_ci * 73af6ab5fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 83af6ab5fSopenharmony_ci * 93af6ab5fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 103af6ab5fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 113af6ab5fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 123af6ab5fSopenharmony_ci * See the License for the specific language governing permissions and 133af6ab5fSopenharmony_ci * limitations under the License. 143af6ab5fSopenharmony_ci */ 153af6ab5fSopenharmony_ci 163af6ab5fSopenharmony_ciimport mocha from 'mocha'; 173af6ab5fSopenharmony_ciimport { isDebug, isFileExist, sortAndDeduplicateStringArr } from '../../../src/initialization/utils'; 183af6ab5fSopenharmony_ciimport { assert, expect } from 'chai'; 193af6ab5fSopenharmony_ciimport { DEBUG } from "../../../src/initialization/CommonObject"; 203af6ab5fSopenharmony_ciimport * as fs from 'fs'; 213af6ab5fSopenharmony_ci 223af6ab5fSopenharmony_cidescribe('Tester Cases for <utils>.', function () { 233af6ab5fSopenharmony_ci describe('Tester Cases for <isDebug>.', function () { 243af6ab5fSopenharmony_ci /** test for isDebug */ 253af6ab5fSopenharmony_ci it('Tester: <Debug Mode> case for isDebug', function () { 263af6ab5fSopenharmony_ci const projectConfig: any = { 273af6ab5fSopenharmony_ci buildMode: DEBUG 283af6ab5fSopenharmony_ci }; 293af6ab5fSopenharmony_ci assert.strictEqual(isDebug(projectConfig), true); 303af6ab5fSopenharmony_ci }); 313af6ab5fSopenharmony_ci }); 323af6ab5fSopenharmony_ci 333af6ab5fSopenharmony_ci describe('Tester Cases for <isFileExist>.', function () { 343af6ab5fSopenharmony_ci /** test for isFileExist */ 353af6ab5fSopenharmony_ci it('Tester: <file not exist> case for isFileExist', function () { 363af6ab5fSopenharmony_ci const path: string = 'test/ut/initialization/testFileNotExiet.txt'; 373af6ab5fSopenharmony_ci assert.strictEqual(isFileExist(path), false); 383af6ab5fSopenharmony_ci }); 393af6ab5fSopenharmony_ci 403af6ab5fSopenharmony_ci it('Tester: <file exist> case for isFileExist', function () { 413af6ab5fSopenharmony_ci const path: string = 'test/ut/initialization/demo.txt'; 423af6ab5fSopenharmony_ci fs.writeFileSync(path, 'test'); 433af6ab5fSopenharmony_ci assert.strictEqual(isFileExist(path), true); 443af6ab5fSopenharmony_ci fs.unlinkSync(path); 453af6ab5fSopenharmony_ci }); 463af6ab5fSopenharmony_ci }); 473af6ab5fSopenharmony_ci 483af6ab5fSopenharmony_ci describe('Tester Cases for <sortAndDeduplicateStringArr>.', function () { 493af6ab5fSopenharmony_ci /** test for sortAndDeduplicateStringArr */ 503af6ab5fSopenharmony_ci it('Tester: <the length of arr is 0> case for sortAndDeduplicateStringArr', function () { 513af6ab5fSopenharmony_ci const arr: string[] = []; 523af6ab5fSopenharmony_ci assert.strictEqual(sortAndDeduplicateStringArr(arr).length, 0); 533af6ab5fSopenharmony_ci }); 543af6ab5fSopenharmony_ci 553af6ab5fSopenharmony_ci it('Tester: <sort and deduplicate> case for sortAndDeduplicateStringArr', function () { 563af6ab5fSopenharmony_ci const arr0: string[] = ['test2', 'test2', 'test1', 'test0']; 573af6ab5fSopenharmony_ci const arr2: string[] = ['test0', 'test1', 'test2']; 583af6ab5fSopenharmony_ci let arr1 = sortAndDeduplicateStringArr(arr0); 593af6ab5fSopenharmony_ci expect(arr1).to.deep.equal(arr2); 603af6ab5fSopenharmony_ci }); 613af6ab5fSopenharmony_ci }); 623af6ab5fSopenharmony_ci}); 63