Search in sources :

Example 6 with SimpleFormatter

use of android.icu.text.SimpleFormatter in project j2objc by google.

the class SimpleFormatterTest method TestBigArgument.

@Test
public void TestBigArgument() {
    SimpleFormatter fmt = SimpleFormatter.compile("a{20}c");
    assertEquals("{20} count", 21, fmt.getArgumentLimit());
    CharSequence[] values = new CharSequence[21];
    values[20] = "b";
    assertEquals("{20}=b", "abc", fmt.format(values));
}
Also used : SimpleFormatter(android.icu.text.SimpleFormatter) Test(org.junit.Test)

Example 7 with SimpleFormatter

use of android.icu.text.SimpleFormatter in project j2objc by google.

the class SimpleFormatterTest method TestFormatUseAppendToAsArgument.

@Test
public void TestFormatUseAppendToAsArgument() {
    SimpleFormatter fmt = SimpleFormatter.compile("Arguments {0} and {1}");
    StringBuilder appendTo = new StringBuilder("previous:");
    try {
        fmt.formatAndAppend(appendTo, null, appendTo, "frog");
        fail("IllegalArgumentException expected.");
    } catch (IllegalArgumentException e) {
    // expected.
    }
}
Also used : SimpleFormatter(android.icu.text.SimpleFormatter) Test(org.junit.Test)

Example 8 with SimpleFormatter

use of android.icu.text.SimpleFormatter in project j2objc by google.

the class SimpleFormatterTest method TestFormatReplaceOptimizationNoOffsets.

@Test
public void TestFormatReplaceOptimizationNoOffsets() {
    SimpleFormatter fmt = SimpleFormatter.compile("{2}, {0}, {1} and {3}");
    StringBuilder result = new StringBuilder("original");
    assertEquals("format", "original, freddy, frog and by", fmt.formatAndReplace(result, null, "freddy", "frog", result, "by").toString());
}
Also used : SimpleFormatter(android.icu.text.SimpleFormatter) Test(org.junit.Test)

Example 9 with SimpleFormatter

use of android.icu.text.SimpleFormatter in project j2objc by google.

the class SimpleFormatterTest method TestTooFewArgumentValues.

@Test
public void TestTooFewArgumentValues() {
    SimpleFormatter fmt = SimpleFormatter.compile("Templates {2}{1} and {4} are out of order.");
    try {
        fmt.format("freddy", "tommy", "frog", "leg");
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    // Expected
    }
    try {
        fmt.formatAndAppend(new StringBuilder(), null, "freddy", "tommy", "frog", "leg");
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    // Expected
    }
    try {
        fmt.formatAndReplace(new StringBuilder(), null, "freddy", "tommy", "frog", "leg");
        fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    // Expected
    }
}
Also used : SimpleFormatter(android.icu.text.SimpleFormatter) Test(org.junit.Test)

Example 10 with SimpleFormatter

use of android.icu.text.SimpleFormatter in project j2objc by google.

the class SimpleFormatterTest method TestWithArguments.

@Test
public void TestWithArguments() {
    SimpleFormatter fmt = SimpleFormatter.compile("Templates {2}{1} and {4} are out of order.");
    assertEquals("getArgumentLimit", 5, fmt.getArgumentLimit());
    assertEquals("toString", "Templates {2}{1} and {4} are out of order.", fmt.toString());
    int[] offsets = new int[6];
    assertEquals("format", "123456: Templates frogtommy and {0} are out of order.", fmt.formatAndAppend(new StringBuilder("123456: "), offsets, "freddy", "tommy", "frog", "leg", "{0}").toString());
    int[] expectedOffsets = { -1, 22, 18, -1, 32, -1 };
    verifyOffsets(expectedOffsets, offsets);
}
Also used : SimpleFormatter(android.icu.text.SimpleFormatter) Test(org.junit.Test)

Aggregations

SimpleFormatter (android.icu.text.SimpleFormatter)12 Test (org.junit.Test)12 MessageFormat (android.icu.text.MessageFormat)1