Path: blob/master/test/jdk/java/text/Format/CompactNumberFormat/TestParseBigDecimal.java
41153 views
/*1* Copyright (c) 2018, 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 817755225* @summary Checks CNF.parse() when parseBigDecimal is set to true26* @modules jdk.localedata27* @run testng/othervm TestParseBigDecimal28*/2930import org.testng.annotations.BeforeTest;31import org.testng.annotations.DataProvider;32import org.testng.annotations.Test;3334import java.math.BigDecimal;35import java.text.CompactNumberFormat;36import java.text.NumberFormat;37import java.text.ParseException;38import java.util.Locale;3940public class TestParseBigDecimal {4142private static final CompactNumberFormat FORMAT_DZ_LONG = (CompactNumberFormat) NumberFormat43.getCompactNumberInstance(new Locale("dz"), NumberFormat.Style.LONG);4445private static final CompactNumberFormat FORMAT_EN_US_SHORT = (CompactNumberFormat) NumberFormat46.getCompactNumberInstance(Locale.US, NumberFormat.Style.SHORT);4748private static final CompactNumberFormat FORMAT_EN_LONG = (CompactNumberFormat) NumberFormat49.getCompactNumberInstance(new Locale("en"), NumberFormat.Style.LONG);5051private static final CompactNumberFormat FORMAT_HI_IN_LONG = (CompactNumberFormat) NumberFormat52.getCompactNumberInstance(new Locale("hi", "IN"), NumberFormat.Style.LONG);5354private static final CompactNumberFormat FORMAT_JA_JP_SHORT = (CompactNumberFormat) NumberFormat55.getCompactNumberInstance(Locale.JAPAN, NumberFormat.Style.SHORT);5657private static final CompactNumberFormat FORMAT_IT_SHORT = (CompactNumberFormat) NumberFormat58.getCompactNumberInstance(new Locale("it"), NumberFormat.Style.SHORT);5960private static final CompactNumberFormat FORMAT_SW_LONG = (CompactNumberFormat) NumberFormat61.getCompactNumberInstance(new Locale("sw"), NumberFormat.Style.LONG);6263private static final CompactNumberFormat FORMAT_SE_SHORT = (CompactNumberFormat) NumberFormat64.getCompactNumberInstance(new Locale("se"), NumberFormat.Style.SHORT);6566@BeforeTest67public void mutateInstances() {68FORMAT_DZ_LONG.setParseBigDecimal(true);69FORMAT_EN_US_SHORT.setParseBigDecimal(true);70FORMAT_EN_LONG.setParseBigDecimal(true);71FORMAT_HI_IN_LONG.setParseBigDecimal(true);72FORMAT_JA_JP_SHORT.setParseBigDecimal(true);73FORMAT_IT_SHORT.setParseBigDecimal(true);74FORMAT_SW_LONG.setParseBigDecimal(true);75FORMAT_SE_SHORT.setParseBigDecimal(true);76}7778@DataProvider(name = "parse")79Object[][] compactParseData() {80return new Object[][]{81// compact number format instance, string to parse, parsed number82{FORMAT_DZ_LONG, "\u0F66\u0F9F\u0F7C\u0F44\u0F0B\u0F55\u0FB2"83+ "\u0F42 \u0F21", new BigDecimal("1000")},84{FORMAT_DZ_LONG, "-\u0F66\u0F9F\u0F7C\u0F44\u0F0B\u0F55\u0FB2"85+ "\u0F42 \u0F23", new BigDecimal("-3000")},86{FORMAT_DZ_LONG, "\u0F51\u0F74\u0F44\u0F0B\u0F55\u0FB1\u0F74\u0F62"87+ "\u0F0B\u0F66\u0F0B\u0F61\u0F0B \u0F21"88+ "\u0F22\u0F23\u0F24\u0F25\u0F27", new BigDecimal("12345700000000000000")},89{FORMAT_DZ_LONG, "-\u0F51\u0F74\u0F44\u0F0B\u0F55\u0FB1\u0F74\u0F62"90+ "\u0F0B\u0F66\u0F0B\u0F61\u0F0B \u0F21"91+ "\u0F22\u0F23\u0F24\u0F25\u0F27", new BigDecimal("-12345700000000000000")},92{FORMAT_EN_US_SHORT, "-0.0", new BigDecimal("-0.0")},93{FORMAT_EN_US_SHORT, "0", new BigDecimal("0")},94{FORMAT_EN_US_SHORT, "499", new BigDecimal("499")},95{FORMAT_EN_US_SHORT, "-499", new BigDecimal("-499")},96{FORMAT_EN_US_SHORT, "499.89", new BigDecimal("499.89")},97{FORMAT_EN_US_SHORT, "-499.89", new BigDecimal("-499.89")},98{FORMAT_EN_US_SHORT, "1K", new BigDecimal("1000")},99{FORMAT_EN_US_SHORT, "-1K", new BigDecimal("-1000")},100{FORMAT_EN_US_SHORT, "3K", new BigDecimal("3000")},101{FORMAT_EN_US_SHORT, "-3K", new BigDecimal("-3000")},102{FORMAT_EN_US_SHORT, "17K", new BigDecimal("17000")},103{FORMAT_EN_US_SHORT, "-17K", new BigDecimal("-17000")},104{FORMAT_EN_US_SHORT, "12345678901234567890",105new BigDecimal("12345678901234567890")},106{FORMAT_EN_US_SHORT, "12345679T", new BigDecimal("12345679000000000000")},107{FORMAT_EN_US_SHORT, "-12345679T", new BigDecimal("-12345679000000000000")},108{FORMAT_EN_US_SHORT, "599.01K", new BigDecimal("599010.00")},109{FORMAT_EN_US_SHORT, "-599.01K", new BigDecimal("-599010.00")},110{FORMAT_EN_US_SHORT, "599444444.90T", new BigDecimal("599444444900000000000.00")},111{FORMAT_EN_US_SHORT, "-599444444.90T", new BigDecimal("-599444444900000000000.00")},112{FORMAT_EN_US_SHORT, "123456789012345.5678K",113new BigDecimal("123456789012345567.8000")},114{FORMAT_EN_US_SHORT, "17.000K", new BigDecimal("17000.000")},115{FORMAT_EN_US_SHORT, "123.56678K", new BigDecimal("123566.78000")},116{FORMAT_EN_US_SHORT, "-123.56678K", new BigDecimal("-123566.78000")},117{FORMAT_EN_LONG, "999", new BigDecimal("999")},118{FORMAT_EN_LONG, "1 thousand", new BigDecimal("1000")},119{FORMAT_EN_LONG, "3 thousand", new BigDecimal("3000")},120{FORMAT_EN_LONG, "12345679 trillion", new BigDecimal("12345679000000000000")},121{FORMAT_HI_IN_LONG, "999", new BigDecimal("999")},122{FORMAT_HI_IN_LONG, "-999", new BigDecimal("-999")},123{FORMAT_HI_IN_LONG, "1 \u0939\u091C\u093C\u093E\u0930", new BigDecimal("1000")},124{FORMAT_HI_IN_LONG, "-1 \u0939\u091C\u093C\u093E\u0930", new BigDecimal("-1000")},125{FORMAT_HI_IN_LONG, "3 \u0939\u091C\u093C\u093E\u0930", new BigDecimal("3000")},126{FORMAT_HI_IN_LONG, "12345679 \u0916\u0930\u092C", new BigDecimal("1234567900000000000")},127{FORMAT_HI_IN_LONG, "-12345679 \u0916\u0930\u092C", new BigDecimal("-1234567900000000000")},128{FORMAT_JA_JP_SHORT, "-99", new BigDecimal("-99")},129{FORMAT_JA_JP_SHORT, "1\u4E07", new BigDecimal("10000")},130{FORMAT_JA_JP_SHORT, "30\u4E07", new BigDecimal("300000")},131{FORMAT_JA_JP_SHORT, "-30\u4E07", new BigDecimal("-300000")},132{FORMAT_JA_JP_SHORT, "12345679\u5146", new BigDecimal("12345679000000000000")},133{FORMAT_JA_JP_SHORT, "-12345679\u5146", new BigDecimal("-12345679000000000000")},134{FORMAT_IT_SHORT, "-99", new BigDecimal("-99")},135{FORMAT_IT_SHORT, "1\u00a0Mln", new BigDecimal("1000000")},136{FORMAT_IT_SHORT, "30\u00a0Mln", new BigDecimal("30000000")},137{FORMAT_IT_SHORT, "-30\u00a0Mln", new BigDecimal("-30000000")},138{FORMAT_IT_SHORT, "12345679\u00a0Bln", new BigDecimal("12345679000000000000")},139{FORMAT_IT_SHORT, "-12345679\u00a0Bln", new BigDecimal("-12345679000000000000")},140{FORMAT_SW_LONG, "-0.0", new BigDecimal("-0.0")},141{FORMAT_SW_LONG, "499", new BigDecimal("499")},142{FORMAT_SW_LONG, "elfu 1", new BigDecimal("1000")},143{FORMAT_SW_LONG, "elfu 3", new BigDecimal("3000")},144{FORMAT_SW_LONG, "elfu 17", new BigDecimal("17000")},145{FORMAT_SW_LONG, "elfu -3", new BigDecimal("-3000")},146{FORMAT_SW_LONG, "-499", new BigDecimal("-499")},147{FORMAT_SW_LONG, "elfu 1", new BigDecimal("1000")},148{FORMAT_SW_LONG, "elfu 3", new BigDecimal("3000")},149{FORMAT_SW_LONG, "elfu -3", new BigDecimal("-3000")},150{FORMAT_SW_LONG, "elfu 17", new BigDecimal("17000")},151{FORMAT_SW_LONG, "trilioni 12345679", new BigDecimal("12345679000000000000")},152{FORMAT_SW_LONG, "trilioni -12345679", new BigDecimal("-12345679000000000000")},153{FORMAT_SW_LONG, "elfu 599.01", new BigDecimal("599010.00")},154{FORMAT_SW_LONG, "elfu -599.01", new BigDecimal("-599010.00")},155{FORMAT_SE_SHORT, "999", new BigDecimal("999")},156{FORMAT_SE_SHORT, "8\u00a0mn", new BigDecimal("8000000")},157{FORMAT_SE_SHORT, "8\u00a0dt", new BigDecimal("8000")},158{FORMAT_SE_SHORT, "12345679\u00a0bn", new BigDecimal("12345679000000000000")},159{FORMAT_SE_SHORT, "12345679,89\u00a0bn", new BigDecimal("12345679890000000000.00")},160{FORMAT_SE_SHORT, "\u2212999", new BigDecimal("-999")},161{FORMAT_SE_SHORT, "\u22128\u00a0mn", new BigDecimal("-8000000")},162{FORMAT_SE_SHORT, "\u22128\u00a0dt", new BigDecimal("-8000")},163{FORMAT_SE_SHORT, "\u221212345679\u00a0bn", new BigDecimal("-12345679000000000000")},164{FORMAT_SE_SHORT, "\u221212345679,89\u00a0bn", new BigDecimal("-12345679890000000000.00")},};165}166167@Test(dataProvider = "parse")168public void testParse(NumberFormat cnf, String parseString,169Number expected) throws ParseException {170CompactFormatAndParseHelper.testParse(cnf, parseString, expected, null, BigDecimal.class);171}172}173174175