use of java.util.IllegalFormatWidthException in project j2objc by google.
the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_LineSeparator.
/**
* java.util.Formatter#format(String, Object...) for line sperator
*/
public void test_formatLjava_lang_String$Ljava_lang_Object_LineSeparator() {
Formatter f = null;
/* J2ObjC: Setting line.separator has no effect, see System.lineSeparator().
String oldSeparator = System.getProperty("line.separator");
try {
System.setProperty("line.separator", "!\n");
f = new Formatter(Locale.US);
f.format("%1$n", 1);
assertEquals("!\n", f.toString());
f = new Formatter(Locale.KOREAN);
f.format("head%1$n%2$n", 1, new Date());
assertEquals("head!\n!\n", f.toString());
f = new Formatter(Locale.US);
f.format("%n%s", "hello");
assertEquals("!\nhello", f.toString());
} finally {
System.setProperty("line.separator", oldSeparator);
}*/
f = new Formatter(Locale.US);
try {
f.format("%-n");
fail("should throw IllegalFormatFlagsException: %-n");
} catch (IllegalFormatFlagsException e) {
// expected
}
try {
f.format("%+n");
fail("should throw IllegalFormatFlagsException: %+n");
} catch (IllegalFormatFlagsException e) {
// expected
}
try {
f.format("%#n");
fail("should throw IllegalFormatFlagsException: %#n");
} catch (IllegalFormatFlagsException e) {
// expected
}
try {
f.format("% n");
fail("should throw IllegalFormatFlagsException: % n");
} catch (IllegalFormatFlagsException e) {
// expected
}
try {
f.format("%0n");
fail("should throw IllegalFormatFlagsException: %0n");
} catch (IllegalFormatFlagsException e) {
// expected
}
try {
f.format("%,n");
fail("should throw IllegalFormatFlagsException: %,n");
} catch (IllegalFormatFlagsException e) {
// expected
}
try {
f.format("%(n");
fail("should throw IllegalFormatFlagsException: %(n");
} catch (IllegalFormatFlagsException e) {
// expected
}
f = new Formatter(Locale.US);
try {
f.format("%4n");
fail("should throw IllegalFormatWidthException");
} catch (IllegalFormatWidthException e) {
// expected
}
f = new Formatter(Locale.US);
try {
f.format("%-4n");
fail("should throw IllegalFormatWidthException");
} catch (IllegalFormatWidthException e) {
// expected
}
f = new Formatter(Locale.US);
try {
f.format("%.9n");
fail("should throw IllegalFormatPrecisionException");
} catch (IllegalFormatPrecisionException e) {
// expected
}
f = new Formatter(Locale.US);
try {
f.format("%5.9n");
fail("should throw IllegalFormatPrecisionException");
} catch (IllegalFormatPrecisionException e) {
// expected
}
//System.setProperty("line.separator", oldSeparator);
}
Aggregations