Search in sources :

Example 1 with SimpleFormatter

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

the class SimpleFormatterTest method TestFormatReplaceOptimization.

@Test
public void TestFormatReplaceOptimization() {
    SimpleFormatter fmt = SimpleFormatter.compile("{2}, {0}, {1} and {3}");
    int[] offsets = new int[4];
    StringBuilder result = new StringBuilder("original");
    assertEquals("format", "original, freddy, frog and by", fmt.formatAndReplace(result, offsets, "freddy", "frog", result, "by").toString());
    int[] expectedOffsets = { 10, 18, 0, 27 };
    verifyOffsets(expectedOffsets, offsets);
}
Also used : SimpleFormatter(android.icu.text.SimpleFormatter) Test(org.junit.Test)

Example 2 with SimpleFormatter

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

the class SimpleFormatterTest method TestFormatReplaceNoOptimizationLeadingText.

@Test
public void TestFormatReplaceNoOptimizationLeadingText() {
    SimpleFormatter fmt = SimpleFormatter.compile("boo {2}, {0}, {1} and {3}");
    int[] offsets = new int[4];
    StringBuilder result = new StringBuilder("original");
    assertEquals("format", "boo original, freddy, frog and by", fmt.formatAndReplace(result, offsets, "freddy", "frog", result, "by").toString());
    int[] expectedOffsets = { 14, 22, 4, 31 };
    verifyOffsets(expectedOffsets, offsets);
}
Also used : SimpleFormatter(android.icu.text.SimpleFormatter) Test(org.junit.Test)

Example 3 with SimpleFormatter

use of android.icu.text.SimpleFormatter 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 4 with SimpleFormatter

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

the class SimpleFormatterTest method TestFormatReplaceNoOptimization.

@Test
public void TestFormatReplaceNoOptimization() {
    SimpleFormatter fmt = SimpleFormatter.compile("{2}, {0}, {1} and {3}");
    int[] offsets = new int[4];
    StringBuilder result = new StringBuilder("original");
    assertEquals("format", "frog, original, freddy and by", fmt.formatAndReplace(result, offsets, result, "freddy", "frog", "by").toString());
    int[] expectedOffsets = { 6, 16, 0, 27 };
    verifyOffsets(expectedOffsets, offsets);
}
Also used : SimpleFormatter(android.icu.text.SimpleFormatter) Test(org.junit.Test)

Example 5 with SimpleFormatter

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

the class SimpleFormatterTest method TestWithNoArguments.

// public methods -----------------------------------------------
@Test
public void TestWithNoArguments() {
    SimpleFormatter fmt = SimpleFormatter.compile("This doesn''t have templates '{0}");
    assertEquals("getArgumentLimit", 0, fmt.getArgumentLimit());
    assertEquals("format", "This doesn't have templates {0}", fmt.format("unused"));
    assertEquals("format with values=null", "This doesn't have templates {0}", fmt.format((CharSequence[]) null));
    assertEquals("toString", "This doesn't have templates {0}", fmt.toString());
    int[] offsets = new int[1];
    assertEquals("formatAndAppend", "This doesn't have templates {0}", fmt.formatAndAppend(new StringBuilder(), offsets).toString());
    assertEquals("offsets[0]", -1, offsets[0]);
    assertEquals("formatAndAppend with values=null", "This doesn't have templates {0}", fmt.formatAndAppend(new StringBuilder(), null, (CharSequence[]) null).toString());
    assertEquals("formatAndReplace with values=null", "This doesn't have templates {0}", fmt.formatAndReplace(new StringBuilder(), null, (CharSequence[]) null).toString());
}
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