Search in sources :

Example 11 with MessageFormat

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() + "\"");
    }
}
Also used : MessageFormat(android.icu.text.MessageFormat) Test(org.junit.Test)

Example 12 with MessageFormat

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]);
    }
}
Also used : MessageFormat(android.icu.text.MessageFormat) ParsePosition(java.text.ParsePosition) Test(org.junit.Test)

Example 13 with MessageFormat

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() + "\"");
    }
}
Also used : MessageFormat(android.icu.text.MessageFormat) Test(org.junit.Test)

Example 14 with MessageFormat

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"));
}
Also used : MessageFormat(android.icu.text.MessageFormat) SimpleFormatter(android.icu.text.SimpleFormatter) Test(org.junit.Test)

Example 15 with MessageFormat

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());
}
Also used : MessageFormat(android.icu.text.MessageFormat) FieldPosition(java.text.FieldPosition) Test(org.junit.Test)

Aggregations

MessageFormat (android.icu.text.MessageFormat)61 Test (org.junit.Test)53 AttributedString (java.text.AttributedString)24 HashMap (java.util.HashMap)15 FieldPosition (java.text.FieldPosition)12 ParsePosition (java.text.ParsePosition)10 Date (java.util.Date)10 ChoiceFormat (java.text.ChoiceFormat)9 ParseException (java.text.ParseException)9 IOException (java.io.IOException)7 Map (java.util.Map)7 TreeMap (java.util.TreeMap)6 SimpleDateFormat (android.icu.text.SimpleDateFormat)5 DateFormat (android.icu.text.DateFormat)4 DecimalFormat (android.icu.text.DecimalFormat)4 NumberFormat (android.icu.text.NumberFormat)4 UFormat (android.icu.text.UFormat)3 ULocale (android.icu.util.ULocale)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3