From bf93e77e72ccce56685fd10dde83587c703a37b3 Mon Sep 17 00:00:00 2001 From: Justin Lu Date: Thu, 28 Mar 2024 22:44:49 +0000 Subject: [PATCH] 8329118: Run MessageFormat additional subformat pattern tests under en_US locale Reviewed-by: naoto --- .../MessageFormat/CompactSubFormats.java | 12 +++++++----- .../Format/MessageFormat/ListSubFormats.java | 18 +++++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/test/jdk/java/text/Format/MessageFormat/CompactSubFormats.java b/test/jdk/java/text/Format/MessageFormat/CompactSubFormats.java index f4b12a14fcc..5c7818ae1ba 100644 --- a/test/jdk/java/text/Format/MessageFormat/CompactSubFormats.java +++ b/test/jdk/java/text/Format/MessageFormat/CompactSubFormats.java @@ -23,7 +23,7 @@ /* * @test - * @bug 8318761 + * @bug 8318761 8329118 * @summary Test MessageFormatPattern ability to recognize and produce * appropriate FormatType and FormatStyle for CompactNumberFormat. * @run junit CompactSubFormats @@ -40,13 +40,15 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +// This test expects an US locale, as this locale provides distinct instances +// for different styles. public class CompactSubFormats { // Ensure the built-in FormatType and FormatStyles for cnFmt are as expected @Test public void applyPatternTest() { var mFmt = new MessageFormat( - "{0,number,compact_short}{1,number,compact_long}"); + "{0,number,compact_short}{1,number,compact_long}", Locale.US); var compactShort = NumberFormat.getCompactNumberInstance( mFmt.getLocale(), NumberFormat.Style.SHORT); var compactLong = NumberFormat.getCompactNumberInstance( @@ -63,13 +65,13 @@ public class CompactSubFormats { // An exception won't be thrown since 'compact_regular' will be interpreted as a // subformatPattern. assertEquals(new DecimalFormat("compact_regular"), - new MessageFormat("{0,number,compact_regular}").getFormatsByArgumentIndex()[0]); + new MessageFormat("{0,number,compact_regular}", Locale.US).getFormatsByArgumentIndex()[0]); } // SHORT and LONG CompactNumberFormats should produce correct patterns @Test public void toPatternTest() { - var mFmt = new MessageFormat("{0}{1}"); + var mFmt = new MessageFormat("{0}{1}", Locale.US); mFmt.setFormatByArgumentIndex(0, NumberFormat.getCompactNumberInstance( mFmt.getLocale(), NumberFormat.Style.SHORT)); mFmt.setFormatByArgumentIndex(1, NumberFormat.getCompactNumberInstance( @@ -80,7 +82,7 @@ public class CompactSubFormats { // A custom cnFmt cannot be recognized, thus does not produce any built-in pattern @Test public void badToPatternTest() { - var mFmt = new MessageFormat("{0}"); + var mFmt = new MessageFormat("{0}", Locale.US); // Non-recognizable compactNumberFormat mFmt.setFormatByArgumentIndex(0, new CompactNumberFormat("", DecimalFormatSymbols.getInstance(Locale.US), new String[]{""})); diff --git a/test/jdk/java/text/Format/MessageFormat/ListSubFormats.java b/test/jdk/java/text/Format/MessageFormat/ListSubFormats.java index 598239ef5ef..de50d95a98a 100644 --- a/test/jdk/java/text/Format/MessageFormat/ListSubFormats.java +++ b/test/jdk/java/text/Format/MessageFormat/ListSubFormats.java @@ -23,7 +23,7 @@ /* * @test - * @bug 8318761 + * @bug 8318761 8329118 * @summary Test MessageFormatPattern ability to recognize and produce the * appropriate FormatType and FormatStyle for ListFormat. ListFormat's * STANDARD, OR, and UNIT types are supported as built-in patterns for @@ -33,19 +33,22 @@ import java.text.ListFormat; import java.text.MessageFormat; +import java.util.Locale; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +// This test expects an US locale, as this locale provides distinct instances +// for different styles. public class ListSubFormats { // Recognize the 'list' FormatType as well as '', 'or', and // 'unit' associated FormatStyles @Test public void applyPatternTest() { - var mFmt = new MessageFormat("{0,list}{1,list,or}{2,list,unit}"); + var mFmt = new MessageFormat("{0,list}{1,list,or}{2,list,unit}", Locale.US); var listStandard = ListFormat.getInstance(mFmt.getLocale(), ListFormat.Type.STANDARD, ListFormat.Style.FULL); var listOr = ListFormat.getInstance(mFmt.getLocale(), @@ -63,12 +66,12 @@ public class ListSubFormats { public void badApplyPatternTest() { // Wrong FormatStyle IllegalArgumentException exc = assertThrows(IllegalArgumentException.class, () -> - new MessageFormat("{0,list,standard}")); + new MessageFormat("{0,list,standard}", Locale.US)); assertEquals("Unexpected modifier for List: standard", exc.getMessage()); // Wrong FormatType exc = assertThrows(IllegalArgumentException.class, () -> - new MessageFormat("{0,listt,or}")); + new MessageFormat("{0,listt,or}", Locale.US)); assertEquals("unknown format type: listt", exc.getMessage()); } @@ -77,7 +80,7 @@ public class ListSubFormats { // produce correct patterns. @Test public void toPatternTest() { - var mFmt = new MessageFormat("{0}{1}{2}"); + var mFmt = new MessageFormat("{0}{1}{2}", Locale.US); mFmt.setFormatByArgumentIndex(0, ListFormat.getInstance(mFmt.getLocale(), ListFormat.Type.STANDARD, ListFormat.Style.FULL)); mFmt.setFormatByArgumentIndex(1, @@ -90,9 +93,10 @@ public class ListSubFormats { // A custom ListFormat cannot be recognized, thus does not produce any built-in pattern @Test public void badToPatternTest() { - var mFmt = new MessageFormat("{0}"); + var mFmt = new MessageFormat("{0}", Locale.US); mFmt.setFormatByArgumentIndex(0, - ListFormat.getInstance(mFmt.getLocale(), ListFormat.Type.UNIT, ListFormat.Style.NARROW)); + ListFormat.getInstance(mFmt.getLocale(), + ListFormat.Type.UNIT, ListFormat.Style.NARROW)); assertEquals("{0}", mFmt.toPattern()); } }