use of android.icu.text.MessageFormat in project j2objc by google.
the class MessageRegressionTest method Test4113018.
/* @bug 4113018
* MessageFormat.applyPattern works wrong with illegal patterns.
*/
@Test
public void Test4113018() {
String originalPattern = "initial pattern";
MessageFormat mf = new MessageFormat(originalPattern);
String illegalPattern = "format: {0, xxxYYY}";
logln("pattern before: \"" + mf.toPattern() + "\"");
logln("illegal pattern: \"" + illegalPattern + "\"");
try {
mf.applyPattern(illegalPattern);
errln("Should have thrown IllegalArgumentException for pattern : " + illegalPattern);
} catch (IllegalArgumentException e) {
if (illegalPattern.equals(mf.toPattern()))
errln("pattern after: \"" + mf.toPattern() + "\"");
}
}
use of android.icu.text.MessageFormat in project j2objc by google.
the class MessageRegressionTest method Test4118592.
/* @bug 4118592
* MessageFormat.parse fails with ChoiceFormat.
*/
@Test
public void Test4118592() {
MessageFormat mf = new MessageFormat("");
String pattern = "{0,choice,1#YES|2#NO}";
String prefix = "";
for (int i = 0; i < 5; i++) {
String formatted = prefix + "YES";
mf.applyPattern(prefix + pattern);
prefix += "x";
Object[] objs = mf.parse(formatted, new ParsePosition(0));
logln(i + ". pattern :\"" + mf.toPattern() + "\"");
log(" \"" + formatted + "\" parsed as ");
if (objs == null)
logln(" null");
else
logln(" " + objs[0]);
}
}
use of android.icu.text.MessageFormat in project j2objc by google.
the class MessageRegressionTest method Test4114743.
/* @bug 4114743
* MessageFormat.applyPattern allows illegal patterns.
*/
@Test
public void Test4114743() {
String originalPattern = "initial pattern";
MessageFormat mf = new MessageFormat(originalPattern);
String illegalPattern = "ab { '}' de";
try {
mf.applyPattern(illegalPattern);
errln("illegal pattern: \"" + illegalPattern + "\"");
} catch (IllegalArgumentException foo) {
if (illegalPattern.equals(mf.toPattern()))
errln("pattern after: \"" + mf.toPattern() + "\"");
}
}
use of android.icu.text.MessageFormat in project j2objc by google.
the class SimpleFormatterTest method TestQuotingLikeMessageFormat.
@Test
public void TestQuotingLikeMessageFormat() {
String pattern = "{0} don't can''t '{5}''}{a' again '}'{1} to the '{end";
SimpleFormatter spf = SimpleFormatter.compile(pattern);
MessageFormat mf = new MessageFormat(pattern, ULocale.ROOT);
String expected = "X don't can't {5}'}{a again }Y to the {end";
assertEquals("MessageFormat", expected, mf.format(new Object[] { "X", "Y" }));
assertEquals("SimpleFormatter", expected, spf.format("X", "Y"));
}
use of android.icu.text.MessageFormat in project j2objc by google.
the class TestMessageFormat method TestSample.
@Test
public // aka sample()
void TestSample() {
MessageFormat form = null;
StringBuffer buffer2 = new StringBuffer();
try {
form = new MessageFormat("There are {0} files on {1}");
} catch (IllegalArgumentException e1) {
errln("Sample message format creation failed.");
return;
}
Object[] testArgs1 = { "abc", "def" };
FieldPosition fieldpos = new FieldPosition(0);
assertEquals("format", "There are abc files on def", form.format(testArgs1, buffer2, fieldpos).toString());
}
Aggregations