Path: blob/master/test/jdk/java/text/Format/NumberFormat/MultipleNumberScriptTest.java
41152 views
/*1* Copyright (c) 2012, 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*/2223/*24* @test25* @bug 7073852 800857726* @summary Support multiple scripts for digits and decimal symbols per locale27* @run main/othervm -Djava.locale.providers=JRE,SPI MultipleNumberScriptTest28*/2930import java.text.*;31import java.util.*;3233public class MultipleNumberScriptTest {3435static Locale[] locales = {36new Locale("ar"),37new Locale("ar", "EG"),38new Locale("ar", "DZ"),39Locale.forLanguageTag("ar-EG-u-nu-arab"),40Locale.forLanguageTag("ar-EG-u-nu-latn"),41Locale.forLanguageTag("ar-DZ-u-nu-arab"),42Locale.forLanguageTag("ar-DZ-u-nu-latn"),43Locale.forLanguageTag("ee"),44Locale.forLanguageTag("ee-GH"),45Locale.forLanguageTag("ee-GH-u-nu-latn"),46new Locale("th", "TH", "TH"),47Locale.forLanguageTag("th-TH"),48Locale.forLanguageTag("th-TH-u-nu-thai"),49Locale.forLanguageTag("th-TH-u-nu-hoge"),50};5152// expected numbering system for each locale53static String[] expectedNumSystem = {54"latn", // ar55"latn", // ar-EG56"latn", // ar-DZ57"arab", // ar-EG-u-nu-arab58"latn", // ar-EG-u-nu-latn59"arab", // ar-DZ-u-nu-arab60"latn", // ar-DZ-u-nu-latn61"latn", // ee62"latn", // ee-GH63"latn", // ee-GH-u-nu-latn64"thai", // th_TH_TH65"latn", // th-TH66"thai", // th-TH-u-nu-thai67"latn", // th-TH-u-nu-hoge (invalid)68};6970public static void main(String[] args) {71int num = 123456;7273for (int i = 0; i < locales.length; i++) {74NumberFormat nf = NumberFormat.getIntegerInstance(locales[i]);75String formatted = nf.format(num);76System.out.printf("%s is %s in %s locale (expected in %s script).\n",77num, formatted, locales[i], expectedNumSystem[i]);78if (!checkResult(formatted, expectedNumSystem[i])) {79throw new RuntimeException("test failed. expected number system was not returned.");80}81}82}8384static boolean checkResult(String formatted, String numSystem) {85switch (numSystem) {86case "arab":87return formatted.charAt(0) == '\u0661';88case "latn":89return formatted.charAt(0) == '1';90case "thai":91return formatted.charAt(0) == '\u0e51';92default:93return false;94}95}96}979899