diff --git a/compileruntime/BUILD.gn b/compileruntime/BUILD.gn index 92e9d7a4546e3a1c67763e328527a1563a9fdb7c..2ab1c67b4cfa91575e7eeb791a34e0cf99ba51bf 100644 --- a/compileruntime/BUILD.gn +++ b/compileruntime/BUILD.gn @@ -16,6 +16,7 @@ group("compileruntime") { testonly = true if (is_standard_system) { deps = [ + "ark_intl_standard/intljs:intljs_test", "convertxml_lib_standard:convertxml_js_test", "process_lib_standard:process_js_test", "uri_lib_standard:uri_js_test", diff --git a/compileruntime/ark_intl_standard/intljs/BUILD.gn b/compileruntime/ark_intl_standard/intljs/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ce9fa83f381b87ca4c122b8753e184d68ff33f38 --- /dev/null +++ b/compileruntime/ark_intl_standard/intljs/BUILD.gn @@ -0,0 +1,31 @@ +# 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("intljs_test") { + hap_profile = "./src/main/config.json" + deps = [ + ":intljs_assets", + ":intljs_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsIntlJsApiTest" +} +ohos_js_assets("intljs_assets") { + source_dir = "./src/main/js/default" +} +ohos_resources("intljs_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/compileruntime/ark_intl_standard/intljs/Test.json b/compileruntime/ark_intl_standard/intljs/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..5ba0ad721ad3a8949bbe923812542be0a3fcfe6e --- /dev/null +++ b/compileruntime/ark_intl_standard/intljs/Test.json @@ -0,0 +1,30 @@ +{ + "description": "Configuration for intljs Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "300000", + "package": "ohos.intl.test", + "shell-timeout": "60000" + }, + "kits": [ + { + "test-file-name": [ + "ActsIntlJsApiTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + }, + { + "type": "PushKit", + "push": [ + "resource/global/white_languages.xml->/system/usr/ohos_locale_config/white_languages.xml" + ] + }, + { + "type": "ShellKit", + "run-command": [ + "chmod 644 /system/usr/ohos_locale_config/white_languages.xml" + ] + } + ] +} diff --git a/compileruntime/ark_intl_standard/intljs/signature/openharmony_sx.p7b b/compileruntime/ark_intl_standard/intljs/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..9be1e98fa4c0c28ca997ed660112fa16b194f0f5 Binary files /dev/null and b/compileruntime/ark_intl_standard/intljs/signature/openharmony_sx.p7b differ diff --git a/compileruntime/ark_intl_standard/intljs/src/main/config.json b/compileruntime/ark_intl_standard/intljs/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..bc4f2d4a00e86408411d7c0db008022a970175b0 --- /dev/null +++ b/compileruntime/ark_intl_standard/intljs/src/main/config.json @@ -0,0 +1,60 @@ +{ + "app": { + "bundleName": "ohos.intl.test", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.intl.test", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "ohos.intl.test.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "MyApplication", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} diff --git a/compileruntime/ark_intl_standard/intljs/src/main/js/default/app.js b/compileruntime/ark_intl_standard/intljs/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..044bffa75e29d7a5fe32644e19cc1bbbc5e9a7b1 --- /dev/null +++ b/compileruntime/ark_intl_standard/intljs/src/main/js/default/app.js @@ -0,0 +1,22 @@ +/* + * 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. + */ +export default { + onCreate() { + console.info('TestApplication onCreate'); + }, + onDestroy() { + console.info('TestApplication onDestroy'); + } +}; diff --git a/compileruntime/ark_intl_standard/intljs/src/main/js/default/i18n/en-US.json b/compileruntime/ark_intl_standard/intljs/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..55561b83737c3c31d082fbfa11e5fc987a351104 --- /dev/null +++ b/compileruntime/ark_intl_standard/intljs/src/main/js/default/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/compileruntime/ark_intl_standard/intljs/src/main/js/default/i18n/zh-CN.json b/compileruntime/ark_intl_standard/intljs/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..cce1af06761a42add0cac1a0567aa3237eda8cb4 --- /dev/null +++ b/compileruntime/ark_intl_standard/intljs/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/compileruntime/ark_intl_standard/intljs/src/main/js/default/pages/index/index.css b/compileruntime/ark_intl_standard/intljs/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/compileruntime/ark_intl_standard/intljs/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/compileruntime/ark_intl_standard/intljs/src/main/js/default/pages/index/index.hml b/compileruntime/ark_intl_standard/intljs/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/compileruntime/ark_intl_standard/intljs/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/compileruntime/ark_intl_standard/intljs/src/main/js/default/pages/index/index.js b/compileruntime/ark_intl_standard/intljs/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..30456d5b72e14ba4918255ad8707175623a77175 --- /dev/null +++ b/compileruntime/ark_intl_standard/intljs/src/main/js/default/pages/index/index.js @@ -0,0 +1,43 @@ +/* + * 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 {Core, ExpectExtend} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + core.init() + + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../test/List.test') + core.execute() + + }, + onReady() { + }, +} \ No newline at end of file diff --git a/compileruntime/ark_intl_standard/intljs/src/main/js/default/test/List.test.js b/compileruntime/ark_intl_standard/intljs/src/main/js/default/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..70efc8295afe6f5b6fdaf02d01970b1a1ffb5e5f --- /dev/null +++ b/compileruntime/ark_intl_standard/intljs/src/main/js/default/test/List.test.js @@ -0,0 +1,18 @@ +/* + * 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. + */ +require('./intlLocale_test.js') +require('./intlCollator_test.js') +require('./intlDateTimeFormat_test.js') +require('./numberFormat_test.js') diff --git a/compileruntime/ark_intl_standard/intljs/src/main/js/default/test/intlCollator_test.js b/compileruntime/ark_intl_standard/intljs/src/main/js/default/test/intlCollator_test.js new file mode 100644 index 0000000000000000000000000000000000000000..7e7ff77e91c042e2ecdf64aa9c60557d4cc8bf93 --- /dev/null +++ b/compileruntime/ark_intl_standard/intljs/src/main/js/default/test/intlCollator_test.js @@ -0,0 +1,74 @@ +/* + * 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 Intl from '@ohos.intl'; +import {describe,beforeAll,beforeEach,afterEach,afterAll,it,expect}from 'deccjsunit/index' +describe('intlDateTimeFormatTest', function () { + console.log("*******test start*******") + + /* * + * @tc.number ARK_INTL_JS_DATETIME_004 + * @tc.name the locale in de + * @tc.desc check the sort in de + */ + it('collator_info_test_004', 0, function () { + var collator1= new Intl.Collator('de').compare('ä', 'z'); + console.log(collator1); + expect(collator1).assertEqual(-1); + + var collator2= new Intl.Collator('sv').compare('ä', 'z'); + console.log(collator2); + expect(collator2).assertEqual(1); + }) + + /* * + * @tc.number ARK_INTL_JS_DATETIME_005 + * @tc.name the locale in de and sv + * @tc.desc check the sort in de and sv + */ + it('collator_info_test_005', 0, function () { + var collator1= new Intl.Collator('de',{sensitivity:'base'}).compare('ä', 'a'); + console.log(collator1); + + var collator2= new Intl.Collator('sv',{sensitivity:'base'}).compare('ä', 'a'); + console.log(collator2); + expect(collator1).assertEqual(0); + expect(collator2).assertEqual(1); + }) + + /* * + * @tc.number ARK_INTL_JS_DATETIME_006 + * @tc.name the locale in zh-Hans + * @tc.desc check the resolvedOptions of collator + */ + it('collator_info_test_006', 0, function () { + var collator = new Intl.Collator("zh-Hans",{sensitivity:'base',caseFirst:'upper',ignorePunctuation:'true'}); + var options = collator.resolvedOptions(); + console.log("collator_info_test_006:",options.caseFirst); + expect(options.caseFirst).assertEqual('upper'); + }) + + /* * + * @tc.number ARK_INTL_JS_DATETIME_007 + * @tc.name the locale in zh-Hans + * @tc.desc check the resolvedOptions of collator + */ + it('collator_info_test_007', 0, function () { + var collator = new Intl.Collator("zh-Hans",{sensitivity:'base',caseFirst:'upper',ignorePunctuation:'true'}); + var options = collator.resolvedOptions(); + console.log("collator_info_test_007:",options.sensitivity); + expect(options.sensitivity).assertEqual('base'); + }) + +}) diff --git a/compileruntime/ark_intl_standard/intljs/src/main/js/default/test/intlDateTimeFormat_test.js b/compileruntime/ark_intl_standard/intljs/src/main/js/default/test/intlDateTimeFormat_test.js new file mode 100644 index 0000000000000000000000000000000000000000..73271ce9dca91d47e6698e4ed09c248960b8b4d6 --- /dev/null +++ b/compileruntime/ark_intl_standard/intljs/src/main/js/default/test/intlDateTimeFormat_test.js @@ -0,0 +1,354 @@ +/* + * 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 Intl from '@ohos.intl'; +import {describe,beforeAll,beforeEach,afterEach,afterAll,it,expect}from 'deccjsunit/index' +describe('intlDateTimeFormatTest_1', function () { + console.log('******test start******') + + /* * + * @tc.number ARK_INTL_JS_DATETIME_001 + * @tc.name format the datetime with en-GB locale + * @tc.desc check the datetime is not null + */ + it('dateTimeFormat_test_001', 0, function () { + let datefmt = new Intl.DateTimeFormat('en-GB'); + expect(datefmt !== null).assertTrue(); + }) + + /* * + * @tc.number ARK_INTL_JS_DATETIME_002 + * @tc.name format the datetime with en-GB locale + * @tc.desc check the datetime is not null + */ + it('dateTimeFormat_test_002', 0, function () { + let datefmt = new Intl.DateTimeFormat(); + expect(datefmt !== null).assertTrue(); + }) + + /* * + * @tc.number ARK_INTL_JS_DATETIME_003 + * @tc.name format the date with zh locale + * @tc.desc check the date + */ + it('dateTimeFormat_test_003', 0, function () { + let date = new Date(2021, 11, 17, 3, 24, 0); + let datefmt = new Intl.DateTimeFormat('zh'); + console.log('dateTimeFormat_test_003 ' + datefmt.format(date)); + expect(datefmt.format(date)).assertEqual('2021/12/17'); + }) + +}) + +describe('intlDateTimeFormatTest_2', function () { + console.log('******test start******') + + /* * + * @tc.number ARK_INTL_JS_DATETIME_005 + * @tc.name format the date with da locale + * @tc.desc check the date + */ + it('dateTimeFormat_test_005', 0, function () { + let date = new Date(2021, 11, 17, 3, 24, 0); + let datefmt = new Intl.DateTimeFormat('da'); + console.log('dateTimeFormat_test_005 ' + datefmt.format(date)); + expect(datefmt.format(date)).assertEqual('17.12.2021'); +}) + +/* * + * @tc.number ARK_INTL_JS_DATETIME_006 + * @tc.name format the date with en-GB locale + * @tc.desc check the date + */ +it('dateTimeFormat_test_006', 0, function () { + let date = new Date(2021, 11, 17, 3, 24, 0); + let datefmt = new Intl.DateTimeFormat('en-GB'); + console.log('dateTimeFormat_test_006 ' + datefmt.format(date)); + expect(datefmt.format(date)).assertEqual('17/12/2021'); +}) +}) + +describe('intlDateTimeFormatTest_3', function () { + console.log('******test start******') + + /* * + * @tc.number ARK_INTL_JS_DATETIME_007 + * @tc.name format the date with aa locale + * @tc.desc check the date + */ + it('dateTimeFormat_test_007', 0, function () { + let date = new Date(2021, 11, 17, 3, 24, 0); + let datefmt = new Intl.DateTimeFormat('aa'); + let value = datefmt.format(date); + console.log('dateTimeFormat_test_007 ' + value); + expect(value).assertInstanceOf('String'); +}) + +/* * + * @tc.number ARK_INTL_JS_DATETIME_008 + * @tc.name format the hour with ban and zh locale + * @tc.desc check the hour with ban and zh locale + */ +it('dateTimeFormat_test_008', 0, function () { + let date = new Date(2020, 11, 20, 14, 23, 16); + let option = { dateStyle: 'full' }; + let datefmt = new Intl.DateTimeFormat(['ban', 'zh'],option); + console.log('dateTimeFormat_test_008 ' + datefmt.format(date)); + expect(datefmt.format(date)).assertEqual('2020年12月20日星期日'); +}) + +/* * + * @tc.number ARK_INTL_JS_DATETIME_009 + * @tc.name format the hour with en and zh locale + * @tc.desc check the hour with en and zh locale + */ +it('dateTimeFormat_test_009', 0, function () { + let date = new Date(2020, 11, 20, 14, 23, 16); + let option = { dateStyle: 'full' }; + let datefmt = new Intl.DateTimeFormat(['en', 'zh'], option); + console.log('dateTimeFormat_test_009 ' + datefmt.format(date)); + expect(datefmt.format(date)).assertEqual('Sunday, December 20, 2020'); +}) +}) + +describe('intlDateTimeFormatTest_4', function () { + console.log('******test start******') + +/* * + * @tc.number ARK_INTL_JS_DATETIME_010 + * @tc.name format the hour with en and ban locale + * @tc.desc check the hour with en and ban locale + */ +it('dateTimeFormat_test_010', 0, function () { + let date = new Date(2020, 11, 20, 14, 23, 16); + let option = { dateStyle: 'full' }; + let datefmt = new Intl.DateTimeFormat(['en', 'ban'], option); + console.log('dateTimeFormat_test_010 ' + datefmt.format(date)); + expect(datefmt.format(date)).assertEqual('Sunday, December 20, 2020'); +}) + +/* * + * @tc.number ARK_INTL_JS_DATETIME_013 + * @tc.name format the date dateStyle with long style + * @tc.desc check the dateStyle with long style + */ +it('dateTimeFormat_test_013', 0, function () { + let date = new Date(2020, 11, 20, 14, 23, 16); + let option = { dateStyle: 'long', timeStyle: 'long' }; + let datefmt = new Intl.DateTimeFormat('zh-CN', option); + console.log('dateTimeFormat_test_013 ' + datefmt.resolvedOptions().dateStyle); + expect(datefmt.resolvedOptions().dateStyle).assertEqual('long'); +}) + + /* * + * @tc.number ARK_INTL_JS_DATETIME_014 + * @tc.name format the date dateStyle with medium style + * @tc.desc check the dateStyle with medium style + */ + it('dateTimeFormat_test_014', 0, function () { + let date = new Date(2020, 11, 20, 14, 23, 16); + let option = { dateStyle: 'medium', timeStyle: 'medium' }; + let datefmt = new Intl.DateTimeFormat('zh-CN', option); + console.log('dateTimeFormat_test_014 ' + datefmt.resolvedOptions().dateStyle); + expect(datefmt.resolvedOptions().dateStyle).assertEqual('medium'); + expect(datefmt.format(date)).assertEqual('2020年12月20日 下午2:23:16'); + }) +}) + +describe('intlDateTimeFormatTest_5', function () { + console.log('******test start******') + + /* * + * @tc.number ARK_INTL_JS_DATETIME_017 + * @tc.name format the date with daterange when the start and end date is equal + * @tc.desc check the daterange when the start and end date is equal + */ + it('dateTimeFormat_test_017', 0, function () { + let startdate = new Date(2020, 11, 20, 14, 23, 16); + let enddate = new Date(2020, 11, 20, 14, 23, 16); + let datefmt = new Intl.DateTimeFormat('en-GB'); + console.log('dateTimeFormat_test_017 ' + datefmt.formatRange(startdate, enddate)); + expect(datefmt.formatRange(startdate, enddate)).assertEqual('20/12/2020'); +}) + + /* * + * @tc.number ARK_INTL_JS_DATETIME_016 + * @tc.name format the date with daterange + * @tc.desc check the daterange + */ + it('dateTimeFormat_test_016', 0, function () { + let startdate = new Date(2020, 11, 20, 14, 23, 16); + let enddate = new Date(2020, 11, 21, 14, 23, 16); + let datefmt = new Intl.DateTimeFormat('en-GB'); + console.log('dateTimeFormat_test_016 ' + datefmt.formatRange(startdate, enddate)); + expect(datefmt.formatRange(startdate, enddate)).assertEqual('20/12/2020 – 21/12/2020'); +}) + + /* * + * @tc.number ARK_INTL_JS_DATETIME_015 + * @tc.name format the date dateStyle with short style + * @tc.desc check the dateStyle with short style + */ + it('dateTimeFormat_test_015', 0, function () { + let date = new Date(2020, 11, 20, 14, 23, 16); + let option = { dateStyle: 'short', timeStyle: 'short' }; + let datefmt = new Intl.DateTimeFormat('zh-CN', option); + console.log('dateTimeFormat_test_015 ' + datefmt.resolvedOptions().dateStyle); + expect(datefmt.resolvedOptions().dateStyle).assertEqual('short'); +}) + +}) + +describe('intlDateTimeFormatTest_6', function () { + console.log('******test start******') + +/* * + * @tc.number ARK_INTL_JS_DATETIME_018 + * @tc.name format the year、month、day、weekday + * @tc.desc check the year、month、day、weekday + */ +it('dateTimeFormat_test_018', 0, function () { + let date = new Date(2020, 11, 20, 14, 23, 16); + let option = { year: 'numeric', month: 'long', day: 'numeric', weekday: 'long' }; + let datefmt = new Intl.DateTimeFormat('ja', option); + console.log('dateTimeFormat_test_018 ' + datefmt.format(date)); + expect(datefmt.format(date)).assertEqual('2020年12月20日日曜日'); + }) + + /* * + * @tc.number ARK_INTL_JS_DATETIME_019 + * @tc.name format the timerange with year、month、day、weekday + * @tc.desc check the timerange with year、month、day、weekday + */ + it('dateTimeFormat_test_019', 0, function () { + let startdate = new Date(2020, 11, 20, 14, 23, 16); + let enddate = new Date(2021, 4, 5, 10, 5, 3); + let option = { year: 'numeric', month: 'long', day: 'numeric', weekday: 'long' }; + let datefmt = new Intl.DateTimeFormat('en', option); + console.log('dateTimeFormat_test_019 ' + datefmt.formatRange(startdate, enddate)); + expect(datefmt.formatRange(startdate, enddate)).assertEqual( + 'Sunday, December 20, 2020 – Wednesday, May 5, 2021'); + }) + + /* * + * @tc.number ARK_INTL_JS_DATETIME_020 + * @tc.name format the hour&minute&second + * @tc.desc check the hour&minute&second + */ + it('dateTimeFormat_test_020', 0, function () { + let date = new Date(2020, 11, 20, 14, 23, 16); + let option = { year: 'numeric', month: 'long', day: 'numeric', + hour: 'numeric', minute: '2-digit', second: 'numeric', weekday: 'long', era: 'short' }; + let datefmt = new Intl.DateTimeFormat('zh-CN-u-hc-h12', option); + console.log('dateTimeFormat_test_020 ' + datefmt.format(date)); + expect(datefmt.format(date)).assertEqual('公元2020年12月20日星期日 下午2:23:16'); + }) +}) + +describe('intlDateTimeFormatTest_7', function () { + console.log('******test start******') + +/* * + * @tc.number ARK_INTL_JS_DATETIME_021 + * @tc.name format the timeZone + * @tc.desc check the timeZone + */ +it('dateTimeFormat_test_021', 0, function () { + let date = new Date(2020, 3, 14, 15, 5, 3); + let option = { timeZone: 'America/Los_Angeles', timeZoneName: 'long' }; + let datefmt = new Intl.DateTimeFormat('zh-CN-u-hc-h12', option); + console.log('dateTimeFormat_test_021 ' + datefmt.format(date)); + expect(datefmt.format(date).indexOf('北美太平洋夏令时间') !== -1).assertTrue(); + }) + + /* * + * @tc.number ARK_INTL_JS_DATETIME_022 + * @tc.name format the America/Los_Angeles timeZone + * @tc.desc check the America/Los_Angeles timeZone + */ + it('dateTimeFormat_test_022', 0, function () { + let option = { timeZone: 'America/Los_Angeles', timeZoneName: 'long' }; + let datefmt = new Intl.DateTimeFormat('zh-CN-u-hc-h12', option); + console.log('dateTimeFormat_test_022 ' + datefmt.resolvedOptions().timeZone); + expect(datefmt.resolvedOptions().timeZone).assertEqual('America/Los_Angeles'); + }) + + /* * + * @tc.number ARK_INTL_JS_DATETIME_023 + * @tc.name format the America/Los_Angeles timeZoneName + * @tc.desc check the America/Los_Angeles timeZoneName + */ + it('dateTimeFormat_test_023', 0, function () { + let option = { timeZone: 'America/Los_Angeles', timeZoneName: 'long' }; + let datefmt = new Intl.DateTimeFormat('zh-CN-u-hc-h12', option); + console.log('dateTimeFormat_test_023 ' + datefmt.resolvedOptions().timeZoneName); + expect(datefmt.resolvedOptions().timeZoneName).assertEqual('long'); + }) + + /* * + * @tc.number ARK_INTL_JS_DATETIME_024 + * @tc.name format the year + * @tc.desc check the year + */ + it('dateTimeFormat_test_024', 0, function () { + let option = { year: 'numeric', month: 'long', day: 'numeric', + hour: 'numeric', minute: '2-digit', second: 'numeric', weekday: 'long', era: 'short' }; + let datefmt = new Intl.DateTimeFormat('zh-CN-u-hc-h12', option); + console.log('dateTimeFormat_test_024 ' + datefmt.resolvedOptions().year); + expect(datefmt.resolvedOptions().year).assertEqual('numeric'); + }) +}) + +describe('intlDateTimeFormatTest_7', function () { + console.log('******test start******') + +/* * + * @tc.number ARK_INTL_JS_DATETIME_025 + * @tc.name format the weekday + * @tc.desc check the weekday + */ +it('dateTimeFormat_test_025', 0, function () { + let option = { year: 'numeric', month: 'long', day: 'numeric', + hour: 'numeric', minute: '2-digit', second: 'numeric', weekday: 'long', era: 'short' }; + let datefmt = new Intl.DateTimeFormat('zh-CN-u-hc-h12', option); + console.log('dateTimeFormat_test_025 ' + datefmt.resolvedOptions().weekday); + expect(datefmt.resolvedOptions().weekday).assertEqual('long'); + }) + + /* * + * @tc.number ARK_INTL_JS_DATETIME_026 + * @tc.name format the hour in zh-CN-u-hc-h12 + * @tc.desc check the hour in zh-CN-u-hc-h12 + */ + it('dateTimeFormat_test_026', 0, function () { + let option = { year: 'numeric', month: 'long', day: 'numeric', + hour: 'numeric', minute: '2-digit', second: 'numeric', weekday: 'long', era: 'short' }; + let datefmt = new Intl.DateTimeFormat('zh-CN-u-hc-h12', option); + console.log('dateTimeFormat_test_026 ' + datefmt.resolvedOptions().hour); + expect(datefmt.resolvedOptions().hour).assertEqual('numeric'); + }) + + /* * + * @tc.number ARK_INTL_JS_DATETIME_027 + * @tc.name format the hour in fr-Latn-FR-u-nu-mong + * @tc.desc check the hour in fr-Latn-FR-u-nu-mong + */ + it('dateTimeFormat_test_027', 0, function () { + let date = new Date(2020, 11, 20, 14, 23, 16); + let option = { dateStyle: 'full' }; + let datefmt = new Intl.DateTimeFormat('fr-Latn-FR-u-nu-mong', option); + console.log('dateTimeFormat_test_027 ' + datefmt.format(date)); + expect(datefmt.format(date)).assertEqual('dimanche ᠒᠐ décembre ᠒᠐᠒᠐'); + }) +}) \ No newline at end of file diff --git a/compileruntime/ark_intl_standard/intljs/src/main/js/default/test/intlLocale_test.js b/compileruntime/ark_intl_standard/intljs/src/main/js/default/test/intlLocale_test.js new file mode 100644 index 0000000000000000000000000000000000000000..42e3b7655ecc22cad48a80008c41c18d0057da6d --- /dev/null +++ b/compileruntime/ark_intl_standard/intljs/src/main/js/default/test/intlLocale_test.js @@ -0,0 +1,31 @@ +/* + * 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 Intl from '@ohos.intl'; +import {describe,beforeAll,beforeEach,afterEach,afterAll,it,expect}from 'deccjsunit/index' +describe('intlDateTimeFormatTest', function () { + console.log('******* start IntlLocale_Test ******') + + /* * + * @tc.number ARK_INTL_JS_DATETIME_001 + * @tc.name the locale in en-Latn-GB + * @tc.desc check the locale in en-Latn-GB + */ + it('locale_test_001', 0, function () { + let locale = new Intl.Locale('en-Latn-GB'); + console.log('locale_test_001 ' + locale.language); + expect(locale.language).assertEqual('en'); + }) + +}) \ No newline at end of file diff --git a/compileruntime/ark_intl_standard/intljs/src/main/js/default/test/numberFormat_test.js b/compileruntime/ark_intl_standard/intljs/src/main/js/default/test/numberFormat_test.js new file mode 100644 index 0000000000000000000000000000000000000000..9ffe78bba37902082ff4d0aa15f06a066a49be69 --- /dev/null +++ b/compileruntime/ark_intl_standard/intljs/src/main/js/default/test/numberFormat_test.js @@ -0,0 +1,106 @@ +/* + * 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 Intl from '@ohos.intl'; +import {describe,beforeAll,beforeEach,afterEach,afterAll,it,expect}from 'deccjsunit/index' +describe('intlDateTimeFormatTest', function () { + console.log('******test start********'); + + /* * + * @tc.number ARK_INTL_JS_DATETIME_001 + * @tc.name format the number in en-GB and zh + * @tc.desc check the number in en-GB and zh + */ + it('numberFormat_info_test_001', 0, function () { + var numfmt = new Intl.NumberFormat(["en-GB", "zh"], { style: 'decimal', notation: "scientific" }); + console.log(numfmt.format(1223)); + expect(numfmt.format(1223)).assertEqual('1.223E3'); + // console.log(numfmt.resolvedOptions().locale); + // console.log(numfmt.resolvedOptions().currency); + }) + + /* * + * @tc.number ARK_INTL_JS_DATETIME_003 + * @tc.name format the number in ar-EG + * @tc.desc check the style of number in ar-EG + */ + it('numberFormat_info_test_003', 0, function () { + var number = 123456.789; + var numfmt =new Intl.NumberFormat('ar-EG'); + console.log(numfmt.format(number)); + expect(numfmt.format(number)).assertEqual('١٢٣٬٤٥٦٫٧٨٩'); + }) + + /* * + * @tc.number ARK_INTL_JS_DATETIME_004 + * @tc.name format the number in en-IN + * @tc.desc check the format of number in en-IN + */ + it('numberFormat_info_test_004', 0, function () { + var number = 123456.789; + var numfmt =new Intl.NumberFormat('en-IN'); + console.log(numfmt.format(number)); + expect(numfmt.format(number)).assertEqual('1,23,456.789'); + }) + + /* * + * @tc.number ARK_INTL_JS_DATETIME_005 + * @tc.name format the number in zh-Hans-CN-u-nu-hanidec + * @tc.desc check the format of number in zh-Hans-CN-u-nu-hanidec + */ + it('numberFormat_info_test_005', 0, function () { + var number = 123456.789; + // 通过编号系统中的nu扩展键请求, 例如中文十进制数字 + var numfmt =new Intl.NumberFormat('zh-Hans-CN-u-nu-hanidec') + console.log(numfmt.format(number)); + expect(numfmt.format(number)).assertEqual('一二三,四五六.七八九') + }) + + /* * + * @tc.number ARK_INTL_JS_DATETIME_006 + * @tc.name format the number in ban and id + * @tc.desc check the format of number in ban and id + */ + it('numberFormat_info_test_006', 0, function () { + var number = 123456.789; + var numfmt=new Intl.NumberFormat('ban'); + console.log('numberFormat_info_test_006 '+numfmt.format(number)); + expect(numfmt.format(number)).assertEqual('123,456.789') + }) + + /* * + * @tc.number ARK_INTL_JS_DATETIME_008 + * @tc.name format the number in ja-JP + * @tc.desc check the format of number in ja-JP + */ + it('numberFormat_info_test_008', 0, function () { + var number = 123456.789; + var numfmt=new Intl.NumberFormat('ja', { style: 'currency', currency: 'JPY' }); + console.log('numberFormat_info_test_008 '+numfmt.format(number)); + expect(numfmt.format(number)).assertEqual('¥123,457'); + }) + + /* * + * @tc.number ARK_INTL_JS_DATETIME_009 + * @tc.name format the number in en-IN + * @tc.desc check the format of number in en-IN + */ + it('numberFormat_info_test_009', 0, function () { + var number = 123456.789; + var numfmt=new Intl.NumberFormat('en-IN', { maximumSignificantDigits: 3 }) + console.log('numberFormat_info_test_009 '+numfmt.format(number)); + expect(numfmt.format(number)).assertEqual('1,23,000') + }) + +}) \ No newline at end of file diff --git a/compileruntime/ark_intl_standard/intljs/src/main/resources/base/element/string.json b/compileruntime/ark_intl_standard/intljs/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..fac1f3a7cbdd54561048bb8e4211abd3340efe97 --- /dev/null +++ b/compileruntime/ark_intl_standard/intljs/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "L2Test" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/compileruntime/ark_intl_standard/intljs/src/main/resources/base/media/icon.png b/compileruntime/ark_intl_standard/intljs/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/compileruntime/ark_intl_standard/intljs/src/main/resources/base/media/icon.png differ