8329118: Run MessageFormat additional subformat pattern tests under en_US locale

Reviewed-by: naoto
This commit is contained in:
Justin Lu 2024-03-28 22:44:49 +00:00
parent 991e04e7d7
commit bf93e77e72
2 changed files with 18 additions and 12 deletions

View File

@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 8318761 * @bug 8318761 8329118
* @summary Test MessageFormatPattern ability to recognize and produce * @summary Test MessageFormatPattern ability to recognize and produce
* appropriate FormatType and FormatStyle for CompactNumberFormat. * appropriate FormatType and FormatStyle for CompactNumberFormat.
* @run junit CompactSubFormats * @run junit CompactSubFormats
@ -40,13 +40,15 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; 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 { public class CompactSubFormats {
// Ensure the built-in FormatType and FormatStyles for cnFmt are as expected // Ensure the built-in FormatType and FormatStyles for cnFmt are as expected
@Test @Test
public void applyPatternTest() { public void applyPatternTest() {
var mFmt = new MessageFormat( 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( var compactShort = NumberFormat.getCompactNumberInstance(
mFmt.getLocale(), NumberFormat.Style.SHORT); mFmt.getLocale(), NumberFormat.Style.SHORT);
var compactLong = NumberFormat.getCompactNumberInstance( 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 // An exception won't be thrown since 'compact_regular' will be interpreted as a
// subformatPattern. // subformatPattern.
assertEquals(new DecimalFormat("compact_regular"), 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 // SHORT and LONG CompactNumberFormats should produce correct patterns
@Test @Test
public void toPatternTest() { public void toPatternTest() {
var mFmt = new MessageFormat("{0}{1}"); var mFmt = new MessageFormat("{0}{1}", Locale.US);
mFmt.setFormatByArgumentIndex(0, NumberFormat.getCompactNumberInstance( mFmt.setFormatByArgumentIndex(0, NumberFormat.getCompactNumberInstance(
mFmt.getLocale(), NumberFormat.Style.SHORT)); mFmt.getLocale(), NumberFormat.Style.SHORT));
mFmt.setFormatByArgumentIndex(1, NumberFormat.getCompactNumberInstance( 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 // A custom cnFmt cannot be recognized, thus does not produce any built-in pattern
@Test @Test
public void badToPatternTest() { public void badToPatternTest() {
var mFmt = new MessageFormat("{0}"); var mFmt = new MessageFormat("{0}", Locale.US);
// Non-recognizable compactNumberFormat // Non-recognizable compactNumberFormat
mFmt.setFormatByArgumentIndex(0, new CompactNumberFormat("", mFmt.setFormatByArgumentIndex(0, new CompactNumberFormat("",
DecimalFormatSymbols.getInstance(Locale.US), new String[]{""})); DecimalFormatSymbols.getInstance(Locale.US), new String[]{""}));

View File

@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 8318761 * @bug 8318761 8329118
* @summary Test MessageFormatPattern ability to recognize and produce the * @summary Test MessageFormatPattern ability to recognize and produce the
* appropriate FormatType and FormatStyle for ListFormat. ListFormat's * appropriate FormatType and FormatStyle for ListFormat. ListFormat's
* STANDARD, OR, and UNIT types are supported as built-in patterns for * STANDARD, OR, and UNIT types are supported as built-in patterns for
@ -33,19 +33,22 @@
import java.text.ListFormat; import java.text.ListFormat;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.Locale;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; 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 { public class ListSubFormats {
// Recognize the 'list' FormatType as well as '', 'or', and // Recognize the 'list' FormatType as well as '', 'or', and
// 'unit' associated FormatStyles // 'unit' associated FormatStyles
@Test @Test
public void applyPatternTest() { 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(), var listStandard = ListFormat.getInstance(mFmt.getLocale(),
ListFormat.Type.STANDARD, ListFormat.Style.FULL); ListFormat.Type.STANDARD, ListFormat.Style.FULL);
var listOr = ListFormat.getInstance(mFmt.getLocale(), var listOr = ListFormat.getInstance(mFmt.getLocale(),
@ -63,12 +66,12 @@ public class ListSubFormats {
public void badApplyPatternTest() { public void badApplyPatternTest() {
// Wrong FormatStyle // Wrong FormatStyle
IllegalArgumentException exc = assertThrows(IllegalArgumentException.class, () -> 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()); assertEquals("Unexpected modifier for List: standard", exc.getMessage());
// Wrong FormatType // Wrong FormatType
exc = assertThrows(IllegalArgumentException.class, () -> exc = assertThrows(IllegalArgumentException.class, () ->
new MessageFormat("{0,listt,or}")); new MessageFormat("{0,listt,or}", Locale.US));
assertEquals("unknown format type: listt", exc.getMessage()); assertEquals("unknown format type: listt", exc.getMessage());
} }
@ -77,7 +80,7 @@ public class ListSubFormats {
// produce correct patterns. // produce correct patterns.
@Test @Test
public void toPatternTest() { public void toPatternTest() {
var mFmt = new MessageFormat("{0}{1}{2}"); var mFmt = new MessageFormat("{0}{1}{2}", Locale.US);
mFmt.setFormatByArgumentIndex(0, mFmt.setFormatByArgumentIndex(0,
ListFormat.getInstance(mFmt.getLocale(), ListFormat.Type.STANDARD, ListFormat.Style.FULL)); ListFormat.getInstance(mFmt.getLocale(), ListFormat.Type.STANDARD, ListFormat.Style.FULL));
mFmt.setFormatByArgumentIndex(1, mFmt.setFormatByArgumentIndex(1,
@ -90,9 +93,10 @@ public class ListSubFormats {
// A custom ListFormat cannot be recognized, thus does not produce any built-in pattern // A custom ListFormat cannot be recognized, thus does not produce any built-in pattern
@Test @Test
public void badToPatternTest() { public void badToPatternTest() {
var mFmt = new MessageFormat("{0}"); var mFmt = new MessageFormat("{0}", Locale.US);
mFmt.setFormatByArgumentIndex(0, 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()); assertEquals("{0}", mFmt.toPattern());
} }
} }