diff --git a/README.OpenSource b/README.OpenSource index e9bf4abe09ee517d3202e6493e79a34f4e60bc85..acad1ba9646984a2d7f95378b94cd00c4cb10f69 100644 --- a/README.OpenSource +++ b/README.OpenSource @@ -4,7 +4,7 @@ "License":"MIT License", "License File":"LICENSE", "Version Number":"2.0.0", - "Owner":"yuxuhao@huawei.com", + "Owner":"xiafeng@huawei.com", "Upstream URL":"https://github.com/apache/commons-codec", "Description": " Commons Codec package contains simple encoder and decoders for various formats such as Base64 and Hexadecimal. In addition to these widely used encoders and decoders, the codec package also maintains a collection of phonetic encoding utilities" } diff --git a/entry/src/main/ets/entryability/EntryAbility.ts b/entry/src/main/ets/entryability/EntryAbility.ts index d8147808c6c419f7c70e210eae41591cb77fb8dc..1340d5cc4703a1468e4b671cd87b4d69d0e6da09 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ts +++ b/entry/src/main/ets/entryability/EntryAbility.ts @@ -15,9 +15,11 @@ import UIAbility from '@ohos.app.ability.UIAbility'; import hilog from '@ohos.hilog'; import window from '@ohos.window'; +import Want from '@ohos.app.ability.Want'; +import AbilityConstant from '@ohos.app.ability.AbilityConstant'; export default class EntryAbility extends UIAbility { - onCreate(want, launchParam) { + onCreate(want: Want, param: AbilityConstant.LaunchParam) { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); } diff --git a/entry/src/main/ets/pages/digest.ets b/entry/src/main/ets/pages/digest.ets index 01a1e23b959699120253bd95e814e01f97e0dcdc..0518478cb0e2fa0bb062c139e30c1e144a5d2f0f 100644 --- a/entry/src/main/ets/pages/digest.ets +++ b/entry/src/main/ets/pages/digest.ets @@ -132,7 +132,7 @@ struct Digest { .onClick(() => { // https://github.com/emn178/js-sha256 this.mSha256Type = 1 - var sha256 = jsSha256.sha256 + let sha256 = jsSha256.sha256 this.mSha256Result = sha256(this.mSha256Input) console.log("SHA256编码= " + "【" + this.mSha256Result + "】") }) @@ -154,7 +154,7 @@ struct Digest { .onClick(() => { // https://github.com/emn178/js-sha256 this.mSha256Type = 2 - var sha256 = jsSha256.sha256 + let sha256 = jsSha256.sha256 this.mSha256HexResult = sha256.hex(this.mSha256HexInput) console.log("SHA256编码转Hex = " + "【" + this.mSha256HexResult + "】") }) @@ -181,7 +181,7 @@ struct Digest { // https://github.com/emn178/js-sha256 this.mSha224Type = 1 - var sha224 = jsSha256.sha224 + let sha224 = jsSha256.sha224 this.mSha224Result = sha224(this.mSha224Input) console.log("SHA224编码= " + "【" + this.mSha224Result + "】") }) @@ -203,7 +203,7 @@ struct Digest { .onClick(() => { // https://github.com/emn178/js-sha256 this.mSha224Type = 2 - var sha224 = jsSha256.sha224 + let sha224 = jsSha256.sha224 this.mSha224HexResult = sha224.hex(this.mSha224HexInput) console.log("SHA224编码转Hex = " + "【" + this.mSha224HexResult + "】") }) diff --git a/entry/src/main/ets/pages/language.ets b/entry/src/main/ets/pages/language.ets index 29ccc876b67960fd4c1301841dde0910e62b84dd..e6db38a5c4e20c997a9ec0f5aeb5727838d26b6f 100644 --- a/entry/src/main/ets/pages/language.ets +++ b/entry/src/main/ets/pages/language.ets @@ -92,7 +92,6 @@ struct Language { .buttonFancy() .onClick(() => { //Soundex 算法 https://github.com/LouisT/node-soundex - // @ts-ignore this.mSoundexResult = soundex(this.mSoundexInput) console.log("Soundex编码 = " + "【" + this.mSoundexResult + "】") }) diff --git a/entry/src/ohosTest/ets/test/Ability.test.ets b/entry/src/ohosTest/ets/test/Ability.test.ets index b3813198b0e4f7307169c9352eb05935d27e6ed7..6a00a1b51c4a7e990cffb6feb92d56370a923533 100644 --- a/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/entry/src/ohosTest/ets/test/Ability.test.ets @@ -16,27 +16,27 @@ import hilog from '@ohos.hilog'; import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' export default function abilityTest() { - describe('ActsAbilityTest', function () { + describe('ActsAbilityTest', ()=> { // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(function () { + beforeAll(()=> { // Presets an action, which is performed only once before all test cases of the test suite start. // This API supports only one parameter: preset action function. }) - beforeEach(function () { + beforeEach(()=> { // Presets an action, which is performed before each unit test case starts. // The number of execution times is the same as the number of test cases defined by **it**. // This API supports only one parameter: preset action function. }) - afterEach(function () { + afterEach(()=> { // Presets a clear action, which is performed after each unit test case ends. // The number of execution times is the same as the number of test cases defined by **it**. // This API supports only one parameter: clear action function. }) - afterAll(function () { + afterAll(()=> { // Presets a clear action, which is performed after all test cases of the test suite end. // This API supports only one parameter: clear action function. }) - it('assertContain',0, function () { + it('assertContain',0, ()=> { // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); let a = 'abc' diff --git a/entry/src/ohosTest/ets/test/CaverPhone.test.ets b/entry/src/ohosTest/ets/test/CaverPhone.test.ets index a6fd042b1ba71253251cff879722f84b5a96ecc3..461b30513a51af2663bb61267a006ecc93778168 100644 --- a/entry/src/ohosTest/ets/test/CaverPhone.test.ets +++ b/entry/src/ohosTest/ets/test/CaverPhone.test.ets @@ -17,8 +17,8 @@ import { describe, expect, it } from '@ohos/hypium' import caverphone from 'caverphone' export default function caverPhoneTest() { - describe('CaverPhoneTest', function () { - const testcases = [ + describe('CaverPhoneTest', ()=> { + const testcases:ESObject = [ { "input": "Cailean", "expected": "KLN1111111" @@ -38880,9 +38880,9 @@ export default function caverPhoneTest() { "expected": "SWMPFA1111" } ] - it('test_caverPhone', 0, function () { - testcases.forEach((testcase) => { - var result = caverphone(testcase.input); + it('test_caverPhone', 0, ()=> { + testcases.forEach((testcase:ESObject) => { + let result:string = caverphone(testcase.input); expect(result).assertEqual(testcase.expected); hilog.info(0x0000, 'commons-codec CaverPhone', `input=${testcase.input} expected=${testcase.expected} actual=${result}`); }); diff --git a/entry/src/ohosTest/ets/test/Compatibility.ts b/entry/src/ohosTest/ets/test/Compatibility.ts new file mode 100644 index 0000000000000000000000000000000000000000..82065b802de9ea75de0b2e082c9c4d1b1bcd84e0 --- /dev/null +++ b/entry/src/ohosTest/ets/test/Compatibility.ts @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { metaphone } from 'metaphone' + +export function compatibility(fun:Function){ + const own = {}.hasOwnProperty + const fixtures = { + ablaze: 'ABLS', + transition: 'TRNSXN', + astronomical: 'ASTRNMKL', + buzzard: 'BSRT', + wonderer: 'WNTRR', + district: 'TSTRKT', + hockey: 'HK', + capital: 'KPTL', + penguin: 'PNKN', + garbonzo: 'KRBNS', + lightning: 'LFTNNK', + light: 'LFT' + } + /** @type {string} */ + let key + + for (key in fixtures) { + if (own.call(fixtures, key)) { + fun(key,fixtures) + } + } +} + +export function metaphoneBoo(params) { + return metaphone(params) +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/JsSha1.test.ets b/entry/src/ohosTest/ets/test/JsSha1.test.ets index a6b4ae3c1aac2235efc6ea0bbe6ce8487219a728..544b4853ed541ede604127bb40bb58b6e3af1855 100644 --- a/entry/src/ohosTest/ets/test/JsSha1.test.ets +++ b/entry/src/ohosTest/ets/test/JsSha1.test.ets @@ -14,98 +14,97 @@ */ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' -// @ts-ignore import sha1 from 'js-sha1' export default function jsSha1Test() { - describe('JsSha1Test', function () { - beforeAll(function () { + describe('JsSha1Test', ()=> { + beforeAll(()=> { }) - beforeEach(function () { + beforeEach(()=> { }) - afterEach(function () { + afterEach(()=> { }) - afterAll(function () { + afterAll(()=> { }) - it('EmptyStringTest', 0, function () { - let result = sha1('') + it('EmptyStringTest', 0, ()=> { + let result:string = sha1('') expect(result).assertEqual('da39a3ee5e6b4b0d3255bfef95601890afd80709') }) - it('LetterTest', 0, function () { - let result = sha1('The quick brown fox jumps over the lazy dog') + it('LetterTest', 0, ()=> { + let result:string = sha1('The quick brown fox jumps over the lazy dog') expect(result).assertEqual('2fd4e1c67a2d28fced849ee1bb76e7391b93eb12') }) - it('LetterPunctuationTest', 0, function () { - let result = sha1('The quick brown fox jumps over the lazy dog.') + it('LetterPunctuationTest', 0, ()=> { + let result:string = sha1('The quick brown fox jumps over the lazy dog.') expect(result).assertEqual('408d94384216f890ff7a0c3528e8bed1e0b01621') }) - it('ChineseLettersTest', 0, function () { - let result = sha1('中文') + it('ChineseLettersTest', 0, ()=> { + let result:string = sha1('中文') expect(result).assertEqual('7be2d2d20c106eee0836c9bc2b939890a78e8fb3') }) - it('EmptyArrayTest', 0, function () { - let result = sha1([]) + it('EmptyArrayTest', 0, ()=> { + let result:string = sha1([]) expect(result).assertEqual('da39a3ee5e6b4b0d3255bfef95601890afd80709') }) - it('EmptyUin8ArrayTest', 0, function () { - let result = sha1(new Uint8Array([])) + it('EmptyUin8ArrayTest', 0, ()=> { + let result:string = sha1(new Uint8Array([])) expect(result).assertEqual('da39a3ee5e6b4b0d3255bfef95601890afd80709') }) - it('HexTest', 0, function () { - let result = sha1.hex('') + it('HexTest', 0, ()=> { + let result:string = sha1.hex('') expect(result).assertEqual('da39a3ee5e6b4b0d3255bfef95601890afd80709') }) - it('ArrayTest', 0, function () { - let arr = [218, 57, 163, 238, 94, 107, 75, 13, 50, 85, 191, 239, 149, 96, 24, 144, 175, 216, 7, 9]; - let result = sha1.array('') as Array - let matchResult = matchArry(arr, result) + it('ArrayTest', 0, ()=> { + let arr:Array = [218, 57, 163, 238, 94, 107, 75, 13, 50, 85, 191, 239, 149, 96, 24, 144, 175, 216, 7, 9]; + let result:Array = sha1.array('') as Array + let matchResult:boolean = matchArry(arr, result) expect(matchResult).assertTrue() }) - it('DigestTest', 0, function () { - let arr = [218, 57, 163, 238, 94, 107, 75, 13, 50, 85, 191, 239, 149, 96, 24, 144, 175, 216, 7, 9] - let result = sha1.digest('') - let matchResult = matchArry(arr, result) + it('DigestTest', 0, ()=> { + let arr:Array = [218, 57, 163, 238, 94, 107, 75, 13, 50, 85, 191, 239, 149, 96, 24, 144, 175, 216, 7, 9] + let result:Array = sha1.digest('') + let matchResult:boolean = matchArry(arr, result) expect(matchResult).assertTrue() }) - it('ArrayBufferTest', 0, function () { - let result = sha1.arrayBuffer('') - let type = '' + it('ArrayBufferTest', 0, ()=> { + let result:Array = sha1.arrayBuffer('') + let type:string = '' if (result instanceof ArrayBuffer) { type = 'ArrayBuffer' } expect(type).assertEqual('ArrayBuffer') }) - it('StringTest', 0, function () { - let result = sha1('13579ABCDEabcde,./;‘【') + it('StringTest', 0, ()=> { + let result:string = sha1('13579ABCDEabcde,./;‘【') expect(result).assertEqual('33c87d9da1d745679003dee486fad3a8169f3862') }) - it('UppercaseLowerCaseLetterTest', 0, function () { - let result = sha1('THE quick brown FOX jumps over 123 lazy dog'); + it('UppercaseLowerCaseLetterTest', 0, ()=> { + let result:string = sha1('THE quick brown FOX jumps over 123 lazy dog'); expect(result).assertEqual('c59942070e96a123532e4b381de17af0136949a1') }) - it('AlltypeTest', 0, function () { - let result = sha1('al25scAKF86.;*/【】!@#¥%你還得法國德國256'); + it('AlltypeTest', 0, ()=> { + let result:string = sha1('al25scAKF86.;*/【】!@#¥%你還得法國德國256'); expect(result).assertEqual('30c49442129b32047842a7501d73e738a89b17c5') }) - it('SimplifiedAndTraditionalChineseTest', 0, function () { - let result = sha1('中文简体繁體測試'); + it('SimplifiedAndTraditionalChineseTest', 0, ()=> { + let result:string = sha1('中文简体繁體測試'); expect(result).assertEqual('3352ea0b083302e43d0c0fc58ac993ae18e43d39') }) - it('NotEmptyArrayTest', 0, function () { - let result = sha1([1,2,3,4]); + it('NotEmptyArrayTest', 0, ()=> { + let result:string = sha1([1,2,3,4]); expect(result).assertEqual('12dada1fff4d4787ade3333147202c3b443e376f') }) - it('StringUint8ArrayTest', 0, function () { - let result = sha1(new Uint8Array([1,2,3,4])); + it('StringUint8ArrayTest', 0, ()=> { + let result:string = sha1(new Uint8Array([1,2,3,4])); expect(result).assertEqual('12dada1fff4d4787ade3333147202c3b443e376f') }) - it('CompareWithCryptoJS_HexTest', 0, function () { - var obj = sha1.create(); + it('CompareWithCryptoJS_HexTest', 0, ()=> { + let obj:ESObject = sha1.create(); obj.update('Message to hash'); - let result1 = obj.hex(); + let result1:ESObject = obj.hex(); - var result2 = sha1.hex('Message to hash') + let result2:ESObject = sha1.hex('Message to hash') expect(result1.toString()).assertEqual('ad8b1ef19620cf94a1c0c9d6c87e7d1b2bca2584') expect(result2.toString()).assertEqual('ad8b1ef19620cf94a1c0c9d6c87e7d1b2bca2584') @@ -113,9 +112,9 @@ export default function jsSha1Test() { }) - function matchArry(arr1: Array, arr2: Array): boolean { + let matchArry = (arr1: Array, arr2: Array): boolean=> { if (arr1.length == arr2.length) { - for (var i = 0; i < arr1.length; i++) { + for (let i = 0; i < arr1.length; i++) { if (arr1[i] != arr2[i]) { return false; } diff --git a/entry/src/ohosTest/ets/test/MetaPhone.test.ets b/entry/src/ohosTest/ets/test/MetaPhone.test.ets index bbc409faaf27e4438bc4b8ca41d9a206a2961f85..849208d1bcb9f19f166329cb847f5a9900ad6686 100644 --- a/entry/src/ohosTest/ets/test/MetaPhone.test.ets +++ b/entry/src/ohosTest/ets/test/MetaPhone.test.ets @@ -15,14 +15,13 @@ import { describe, expect, it } from '@ohos/hypium' import { metaphone } from 'metaphone' +import { compatibility, metaphoneBoo } from './Compatibility' export default function metaPhoneTest() { - describe('MetaPhoneTest', function () { - const own = {}.hasOwnProperty - it('metaphone', 0, function () { + describe('MetaPhoneTest', ()=> { + it('metaphone', 0, ()=> { expect(metaphone('')).assertEqual('') - // @ts-expect-error - expect(metaphone(false)).assertEqual('') + expect(metaphoneBoo(false)).assertEqual('') expect(metaphone(undefined)).assertEqual('') expect(metaphone(null)).assertEqual('') @@ -87,57 +86,37 @@ export default function metaPhoneTest() { expect(metaphone('HiCcUpS')).assertEqual(metaphone('hiccups')) }) - it('Compatibility_with_Natural', 0, function () { - /** @type {Record} */ - const fixtures = { - ablaze: 'ABLS', - transition: 'TRNSXN', - astronomical: 'ASTRNMKL', - buzzard: 'BSRT', - wonderer: 'WNTRR', - district: 'TSTRKT', - hockey: 'HK', - capital: 'KPTL', - penguin: 'PNKN', - garbonzo: 'KRBNS', - lightning: 'LFTNNK', - light: 'LFT' - } - /** @type {string} */ - let key - - for (key in fixtures) { - if (own.call(fixtures, key)) { - expect(metaphone(key)).assertEqual(fixtures[key]) - } - } + it('Compatibility_with_Natural', 0, ()=> { + compatibility((key:ESObject,fixtures:ESObject)=>{ + expect(metaphone(key)).assertEqual(fixtures[key]) + }) }) - it('test_caverPhone_michael', 0, function () { + it('test_caverPhone_michael', 0, ()=> { expect(metaphone('michael')).assertEqual('MXL'); }) - it('test_caverPhone_crevalle', 0, function () { + it('test_caverPhone_crevalle', 0, ()=> { expect(metaphone('crevalle')).assertEqual('KRFL'); }) - it('test_caverPhone_Filipowitz', 0, function () { + it('test_caverPhone_Filipowitz', 0, ()=> { expect(metaphone('Filipowitz')).assertEqual('FLPWTS'); }) - it('test_caverPhone_Xavier', 0, function () { + it('test_caverPhone_Xavier', 0, ()=> { expect(metaphone('Xavier')).assertEqual('SFR'); }) - it('test_caverPhone_delicious', 0, function () { + it('test_caverPhone_delicious', 0, ()=> { expect(metaphone('delicious')).assertEqual('TLSS'); }) - it('test_caverPhone_acceptingness', 0, function () { + it('test_caverPhone_acceptingness', 0, ()=> { expect(metaphone('acceptingness')).assertEqual('AKSPTNKNS'); }) - it('test_caverPhone_allegrettos', 0, function () { + it('test_caverPhone_allegrettos', 0, ()=> { expect(metaphone('allegrettos')).assertEqual('ALKRTS'); }) }) diff --git a/entry/src/ohosTest/ets/testability/TestAbility.ets b/entry/src/ohosTest/ets/testability/TestAbility.ets index cab0abce916aa3057ab2aeef48d6d10529f5c521..87c687036caede7aa1e774dc27409448160331e8 100644 --- a/entry/src/ohosTest/ets/testability/TestAbility.ets +++ b/entry/src/ohosTest/ets/testability/TestAbility.ets @@ -18,15 +18,17 @@ import hilog from '@ohos.hilog'; import { Hypium } from '@ohos/hypium'; import testsuite from '../test/List.test'; import window from '@ohos.window'; +import Want from '@ohos.app.ability.Want'; +import AbilityConstant from '@ohos.app.ability.AbilityConstant'; export default class TestAbility extends UIAbility { - onCreate(want, launchParam) { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? ''); - var abilityDelegator: any + let abilityDelegator: AbilityDelegatorRegistry.AbilityDelegator abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - var abilityDelegatorArguments: any + let abilityDelegatorArguments: AbilityDelegatorRegistry.AbilityDelegatorArgs abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) diff --git a/entry/src/ohosTest/ets/testability/pages/index.ets b/entry/src/ohosTest/ets/testability/pages/Index.ets similarity index 100% rename from entry/src/ohosTest/ets/testability/pages/index.ets rename to entry/src/ohosTest/ets/testability/pages/Index.ets