Path: blob/master/test/jdk/java/text/Format/CompactNumberFormat/TestUExtensionOverride.java
41153 views
/*1* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/*23* @test24* @bug 8177552 822143225* @summary Checks the behaviour of Unicode BCP 47 U Extension with26* compact number format27* @modules jdk.localedata28* @run testng/othervm TestUExtensionOverride29*/30import java.text.NumberFormat;31import java.text.ParseException;32import java.util.Locale;33import org.testng.annotations.DataProvider;34import org.testng.annotations.Test;3536public class TestUExtensionOverride {3738@DataProvider(name = "compactFormatData")39Object[][] compactFormatData() {40return new Object[][]{41// locale, number, formatted string4243// -nu44{Locale.forLanguageTag("en-US-u-nu-deva"), 12345, "\u0967\u0968K"},45{Locale.forLanguageTag("en-US-u-nu-sinh"), 12345, "\u0de7\u0de8K"},46{Locale.forLanguageTag("en-US-u-nu-zzzz"), 12345, "12K"},47// -rg48{Locale.forLanguageTag("fr-FR-u-rg-cazzzz"), 1234567,49"1\u00a0M"},50{Locale.forLanguageTag("fr-FR-u-rg-cazzzz"), 1234567890,51"1\u00a0G"},52// -nu and -rg53{Locale.forLanguageTag("en-US-u-nu-deva-rg-dezzzz"), 12345,54"\u0967\u0968K"},55{Locale.forLanguageTag("fr-FR-u-nu-zzzz-rg-cazzzz"), 1234567890,56"1\u00a0Md"},57{Locale.forLanguageTag("fr-FR-u-nu-zzzz-rg-zzzz"), 12345,58"12\u00a0k"},59{Locale.forLanguageTag("fr-FR-u-rg-cazzzz-nu-deva"), 12345,60"\u0967\u0968\u00a0k"},};61}6263@DataProvider(name = "compactParseData")64Object[][] compactParseData() {65return new Object[][]{66// locale, parse string, parsed number6768// -nu69{Locale.forLanguageTag("en-US-u-nu-deva"),70"\u0967\u0968K", 12000L},71{Locale.forLanguageTag("en-US-u-nu-sinh"),72"\u0de7\u0de8K", 12000L},73{Locale.forLanguageTag("en-US-u-nu-zzzz"),74"12K", 12000L},75// -rg76{Locale.forLanguageTag("fr-FR-u-rg-cazzzz"),77"1\u00a0G", 1000000000L},78// -nu and -rg79{Locale.forLanguageTag("en-US-u-nu-deva-rg-dezzzz"),80"\u0967\u0968K", 12000L},81{Locale.forLanguageTag("fr-FR-u-nu-zzzz-rg-cazzzz"),82"1\u00a0Md", 1000000000L},83{Locale.forLanguageTag("fr-FR-u-nu-zzzz-rg-zzzz"),84"12\u00a0k", 12000L},85{Locale.forLanguageTag("fr-FR-u-rg-cazzzz-nu-deva"),86"\u0967\u0968\u00a0k", 12000L},};87}8889@Test(dataProvider = "compactFormatData")90public void testFormat(Locale locale, double num,91String expected) {92NumberFormat cnf = NumberFormat.getCompactNumberInstance(locale,93NumberFormat.Style.SHORT);94CompactFormatAndParseHelper.testFormat(cnf, num, expected);95}9697@Test(dataProvider = "compactParseData")98public void testParse(Locale locale, String parseString,99Number expected) throws ParseException {100NumberFormat cnf = NumberFormat.getCompactNumberInstance(locale,101NumberFormat.Style.SHORT);102CompactFormatAndParseHelper.testParse(cnf, parseString, expected, null, null);103}104105}106107108