use of java.text.FieldPosition in project j2objc by google.
the class SimpleDateFormatTest method assertFormat.
private void assertFormat(SimpleDateFormat format, String pattern, Calendar cal, String expected, int field) {
StringBuffer buffer = new StringBuffer();
FieldPosition position = new FieldPosition(field);
format.applyPattern(pattern);
format.format(cal.getTime(), buffer, position);
String result = buffer.toString();
assertTrue("Wrong format: \"" + pattern + "\" expected: " + expected + " result: " + result, result.equals(expected));
assertEquals("Wrong begin position: " + pattern + "\n" + "expected: " + expected + "\n" + "field: " + field, 1, position.getBeginIndex());
assertTrue("Wrong end position: " + pattern + " expected: " + expected + " field: " + field, position.getEndIndex() == result.length());
}
use of java.text.FieldPosition in project j2objc by google.
the class ChoiceFormatTest method test_formatDLjava_lang_StringBufferLjava_text_FieldPosition.
/**
* @tests java.text.ChoiceFormat#format(double, java.lang.StringBuffer,
* java.text.FieldPosition)
*/
public void test_formatDLjava_lang_StringBufferLjava_text_FieldPosition() {
// Test for method java.lang.StringBuffer
// java.text.ChoiceFormat.format(double, java.lang.StringBuffer,
// java.text.FieldPosition)
FieldPosition field = new FieldPosition(0);
StringBuffer buf = new StringBuffer();
String r = f1.format(-1, buf, field).toString();
assertEquals("Wrong choice for -1", "Less than one", r);
buf.setLength(0);
r = f1.format(0, buf, field).toString();
assertEquals("Wrong choice for 0", "Less than one", r);
buf.setLength(0);
r = f1.format(1, buf, field).toString();
assertEquals("Wrong choice for 1", "one", r);
buf.setLength(0);
r = f1.format(2, buf, field).toString();
assertEquals("Wrong choice for 2", "Between one and two", r);
buf.setLength(0);
r = f1.format(3, buf, field).toString();
assertEquals("Wrong choice for 3", "Greater than two", r);
// Regression test for HARMONY-1081
assertEquals(0, new ChoiceFormat("|").format(Double.NaN, new StringBuffer(), new FieldPosition(6)).length());
assertEquals(0, new ChoiceFormat("|").format(1, new StringBuffer(), new FieldPosition(6)).length());
assertEquals("Less than one", f1.format(Double.NaN, new StringBuffer(), field).toString());
}
use of java.text.FieldPosition in project j2objc by google.
the class ChoiceFormatTest method test_formatJLjava_lang_StringBufferLjava_text_FieldPosition.
/**
* @tests java.text.ChoiceFormat#format(long, java.lang.StringBuffer,
* java.text.FieldPosition)
*/
public void test_formatJLjava_lang_StringBufferLjava_text_FieldPosition() {
// Test for method java.lang.StringBuffer
// java.text.ChoiceFormat.format(long, java.lang.StringBuffer,
// java.text.FieldPosition)
FieldPosition field = new FieldPosition(0);
StringBuffer buf = new StringBuffer();
String r = f1.format(0.5, buf, field).toString();
assertEquals("Wrong choice for 0.5", "Less than one", r);
buf.setLength(0);
r = f1.format(1.5, buf, field).toString();
assertEquals("Wrong choice for 1.5", "Between one and two", r);
buf.setLength(0);
r = f1.format(2.5, buf, field).toString();
assertEquals("Wrong choice for 2.5", "Greater than two", r);
}
use of java.text.FieldPosition in project j2objc by google.
the class DecimalFormatTest method test_formatObject.
public void test_formatObject() {
DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(Locale.US);
// format maxLong
FieldPosition pos = new FieldPosition(0);
StringBuffer out = format.format(new Long(Long.MAX_VALUE), new StringBuffer(), pos);
assertTrue("Wrong result L1: " + out, out.toString().equals("9,223,372,036,854,775,807"));
// format minLong
pos = new FieldPosition(0);
out = format.format(new Long(Long.MIN_VALUE), new StringBuffer(), pos);
assertTrue("Wrong result L2: " + out, out.toString().equals("-9,223,372,036,854,775,808"));
// format maxLong of type BigInteger
pos = new FieldPosition(0);
out = format.format(new java.math.BigInteger(String.valueOf(Long.MAX_VALUE)), new StringBuffer(), pos);
assertTrue("Wrong result BI1: " + out, out.toString().equals("9,223,372,036,854,775,807"));
// format minLong of type BigInteger
pos = new FieldPosition(0);
out = format.format(new java.math.BigInteger(String.valueOf(Long.MIN_VALUE)), new StringBuffer(), pos);
assertTrue("Wrong result BI2: " + out, out.toString().equals("-9,223,372,036,854,775,808"));
// format maxLong + 1
java.math.BigInteger big;
pos = new FieldPosition(0);
big = new java.math.BigInteger(String.valueOf(Long.MAX_VALUE)).add(new java.math.BigInteger("1"));
out = format.format(big, new StringBuffer(), pos);
assertTrue("Wrong result BI3: " + out, out.toString().equals("9,223,372,036,854,775,808"));
// format minLong - 1
pos = new FieldPosition(0);
big = new java.math.BigInteger(String.valueOf(Long.MIN_VALUE)).add(new java.math.BigInteger("-1"));
out = format.format(big, new StringBuffer(), pos);
assertTrue("Wrong result BI4: " + out, out.toString().equals("-9,223,372,036,854,775,809"));
// format big decimal
pos = new FieldPosition(0);
out = format.format(new java.math.BigDecimal("51.348"), new StringBuffer(), pos);
assertTrue("Wrong result BD1: " + out, out.toString().equals("51.348"));
// format big decimal
pos = new FieldPosition(0);
out = format.format(new java.math.BigDecimal("51"), new StringBuffer(), pos);
assertTrue("Wrong result BD2: " + out, out.toString().equals("51"));
// format big decimal Double.MAX_VALUE * 2
java.math.BigDecimal bigDecimal;
pos = new FieldPosition(0);
final String doubleMax2 = "359,538,626,972,463,141,629,054,847,463,408," + "713,596,141,135,051,689,993,197,834,953,606,314,521,560,057,077," + "521,179,117,265,533,756,343,080,917,907,028,764,928,468,642,653," + "778,928,365,536,935,093,407,075,033,972,099,821,153,102,564,152," + "490,980,180,778,657,888,151,737,016,910,267,884,609,166,473,806," + "445,896,331,617,118,664,246,696,549,595,652,408,289,446,337,476," + "354,361,838,599,762,500,808,052,368,249,716,736";
bigDecimal = new BigDecimal(Double.MAX_VALUE).add(new BigDecimal(Double.MAX_VALUE));
out = format.format(bigDecimal, new StringBuffer(), pos);
assertTrue("Wrong result BDmax2: " + out, out.toString().equals(doubleMax2));
// format big decimal Double.MIN_VALUE + Double.MIN_VALUE
// and Double.MIN_VALUE - Double.MIN_VALUE
pos = new FieldPosition(0);
bigDecimal = new BigDecimal(Double.MIN_VALUE).add(new BigDecimal(Double.MIN_VALUE));
out = format.format(bigDecimal, new StringBuffer(), pos);
bigDecimal = new BigDecimal(Float.MAX_VALUE).add(new BigDecimal(Float.MAX_VALUE));
out = format.format(bigDecimal, new StringBuffer(), pos);
final String BDFloatMax2 = "680,564,693,277,057,719,623,408,366,969,033,850,880";
assertTrue("Wrong result BDFloatMax2: " + out, out.toString().equals(BDFloatMax2));
// format big decimal Float.MIN_VALUE + Float.MIN_VALUE
// and Float.MIN_VALUE - Float.MIN_VALUE
bigDecimal = new BigDecimal(Float.MIN_VALUE).add(new BigDecimal(Float.MIN_VALUE));
out = format.format(bigDecimal, new StringBuffer(), pos);
final String BDFloatMin2 = "0";
bigDecimal = new BigDecimal(Float.MIN_VALUE).subtract(new BigDecimal(Float.MIN_VALUE));
out = format.format(bigDecimal, new StringBuffer(), pos);
assertTrue("Wrong result BDFloatMax2: " + out, out.toString().equals(BDFloatMin2));
}
use of java.text.FieldPosition in project j2objc by google.
the class FieldPositionTest method test_setEndIndexI.
public void test_setEndIndexI() {
FieldPosition fpos = new FieldPosition(1);
fpos.setEndIndex(3);
fpos.setBeginIndex(2);
assertEquals("EndIndex should have been set to 3", 3, fpos.getEndIndex());
fpos.setEndIndex(Integer.MAX_VALUE);
assertEquals("endIndex should have been set to Integer.MAX_VALUE", Integer.MAX_VALUE, fpos.getEndIndex());
fpos.setEndIndex(-1);
assertEquals("endIndex should have been set to -1", -1, fpos.getEndIndex());
}
Aggregations