use of android.icu.text.MessageFormat in project j2objc by google.
the class TestMessageFormat method TestUnlimitedArgsAndSubformats.
/**
* Verify that MessageFormat accomodates more than 10 arguments and
* more than 10 subformats.
*/
@Test
public void TestUnlimitedArgsAndSubformats() {
final String pattern = "On {0,date} (aka {0,date,short}, aka {0,date,long}) " + "at {0,time} (aka {0,time,short}, aka {0,time,long}) " + "there were {1,number} werjes " + "(a {3,number,percent} increase over {2,number}) " + "despite the {4}''s efforts " + "and to delight of {5}, {6}, {7}, {8}, {9}, and {10} {11}.";
try {
MessageFormat msg = new MessageFormat(pattern);
final Object[] ARGS = { new Date(10000000000000L), new Integer(1303), new Integer(1202), new Double(1303.0 / 1202 - 1), "Glimmung", "the printers", "Nick", "his father", "his mother", "the spiddles", "of course", "Horace" };
String expected = "On Nov 20, 2286 (aka 11/20/86, aka November 20, 2286) " + "at 9:46:40 AM (aka 9:46 AM, aka 9:46:40 AM PST) " + "there were 1,303 werjes " + "(a 8% increase over 1,202) " + "despite the Glimmung's efforts " + "and to delight of the printers, Nick, his father, " + "his mother, the spiddles, and of course Horace.";
assertEquals("format", expected, msg.format(ARGS));
} catch (IllegalArgumentException e1) {
errln("FAIL: constructor failed");
}
}
use of android.icu.text.MessageFormat in project j2objc by google.
the class TestMessageFormat method TestBug2.
@Test
public void TestBug2() {
// {sfb} use double format in pattern, so result will match (not strictly necessary)
final String pattern = "There {0,choice,0.0#are no files|1.0#is one file|1.0<are {0, number} files} on disk {1}. ";
logln("The input pattern : " + pattern);
try {
MessageFormat fmt = new MessageFormat(pattern);
assertEquals("toPattern", pattern, fmt.toPattern());
} catch (IllegalArgumentException e) {
errln("MessageFormat pattern creation failed.");
}
}
use of android.icu.text.MessageFormat in project j2objc by google.
the class TestMessageFormat method TestFormat.
@SuppressWarnings("static-access")
@Test
public void TestFormat() {
final Object[] ft_arr = { new Date(871068000000L) };
StringBuffer result = new StringBuffer();
// String formatStr = "At {1,time} on {1,date}, you made a {2} of {0,number,currency}.";
String formatStr = "On {0,date}, it began.";
String compareStr = "On Aug 8, 1997, it began.";
MessageFormat msg = new MessageFormat(formatStr);
FieldPosition fp = new FieldPosition(0);
try {
msg.format(new Date(871068000000L), result, fp);
errln("*** MSG format without expected error code.");
} catch (Exception e1) {
}
result.setLength(0);
result = msg.format(ft_arr, result, fp);
assertEquals("format", compareStr, result.toString());
Map<String, Object> map = new HashMap<String, Object>();
try {
msg.format("", map);
} catch (Exception e) {
errln("MessageFormat.format(String,Map) was not suppose to return " + "an exception.");
}
}
use of android.icu.text.MessageFormat in project j2objc by google.
the class TestMessageFormat method TestNotEquals.
@Test
public void TestNotEquals() {
MessageFormat x = new MessageFormat("There are {0} files on {1}");
MessageFormat y = new MessageFormat("There are {0} files on {1}");
y.setLocale(Locale.FRENCH);
if (x.equals(y)) {
errln("First test (operator !=): Failed!");
}
y = new MessageFormat("There are {0} files on {1}");
y.applyPattern("There are {0} files on {1} the disk");
if (x.equals(y)) {
errln("Second test (operator !=): Failed!");
}
}
use of android.icu.text.MessageFormat in project android_packages_apps_Settings by omnirom.
the class ZenModePriorityConversationsPreferenceController method getSummary.
private String getSummary(String key) {
int numConversations;
if (KEY_ALL.equals(key)) {
numConversations = mNumConversations;
} else if (KEY_IMPORTANT.equals(key)) {
numConversations = mNumImportantConversations;
} else {
return null;
}
if (numConversations == UNSET) {
return null;
} else {
MessageFormat msgFormat = new MessageFormat(mContext.getString(R.string.zen_mode_conversations_count), Locale.getDefault());
Map<String, Object> args = new HashMap<>();
args.put("count", numConversations);
return msgFormat.format(args);
}
}
Aggregations