0N/A/*
2362N/A * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/* Type-specific source code for unit test
0N/A *
0N/A * Regenerate the BasicX classes via genBasic.sh whenever this file changes.
0N/A * We check in the generated source files so that the test tree can be used
0N/A * independently of the rest of the source tree.
0N/A */
0N/A
0N/A#warn This file is preprocessed before being compiled
0N/A
0N/Aimport java.io.*;
0N/Aimport java.math.BigDecimal;
0N/Aimport java.math.BigInteger;
0N/Aimport java.text.DateFormatSymbols;
0N/Aimport java.util.*;
0N/A#if[double]
0N/Aimport sun.misc.FpUtils;
0N/Aimport sun.misc.DoubleConsts;
0N/A#end[double]
0N/A
0N/Aimport static java.util.Calendar.*;
0N/A#if[datetime]
0N/Aimport static java.util.SimpleTimeZone.*;
0N/Aimport java.util.regex.Pattern;
0N/A#end[datetime]
0N/A
0N/Apublic class Basic$Type$ extends Basic {
0N/A
0N/A private static void test(String fs, String exp, Object ... args) {
0N/A Formatter f = new Formatter(new StringBuilder(), Locale.US);
0N/A f.format(fs, args);
0N/A ck(fs, exp, f.toString());
0N/A }
0N/A
0N/A private static void test(Locale l, String fs, String exp, Object ... args)
0N/A {
0N/A Formatter f = new Formatter(new StringBuilder(), l);
0N/A f.format(fs, args);
0N/A ck(fs, exp, f.toString());
0N/A }
0N/A
0N/A private static void test(String fs, Object ... args) {
0N/A Formatter f = new Formatter(new StringBuilder(), Locale.US);
0N/A f.format(fs, args);
0N/A ck(fs, "fail", f.toString());
0N/A }
0N/A
0N/A private static void test(String fs) {
0N/A Formatter f = new Formatter(new StringBuilder(), Locale.US);
0N/A f.format(fs, "fail");
0N/A ck(fs, "fail", f.toString());
0N/A }
0N/A
0N/A private static void testSysOut(String fs, String exp, Object ... args) {
0N/A FileOutputStream fos = null;
0N/A FileInputStream fis = null;
0N/A try {
0N/A PrintStream saveOut = System.out;
0N/A fos = new FileOutputStream("testSysOut");
0N/A System.setOut(new PrintStream(fos));
0N/A System.out.format(Locale.US, fs, args);
0N/A fos.close();
0N/A
0N/A fis = new FileInputStream("testSysOut");
0N/A byte [] ba = new byte[exp.length()];
0N/A int len = fis.read(ba);
0N/A String got = new String(ba);
0N/A if (len != ba.length)
0N/A fail(fs, exp, got);
0N/A ck(fs, exp, got);
0N/A
0N/A System.setOut(saveOut);
0N/A } catch (FileNotFoundException ex) {
0N/A fail(fs, ex.getClass());
0N/A } catch (IOException ex) {
0N/A fail(fs, ex.getClass());
0N/A } finally {
0N/A try {
0N/A if (fos != null)
0N/A fos.close();
0N/A if (fis != null)
0N/A fis.close();
0N/A } catch (IOException ex) {
0N/A fail(fs, ex.getClass());
0N/A }
0N/A }
0N/A }
0N/A
0N/A private static void tryCatch(String fs, Class<?> ex) {
0N/A boolean caught = false;
0N/A try {
0N/A test(fs);
0N/A } catch (Throwable x) {
0N/A if (ex.isAssignableFrom(x.getClass()))
0N/A caught = true;
0N/A }
0N/A if (!caught)
0N/A fail(fs, ex);
0N/A else
0N/A pass();
0N/A }
0N/A
0N/A private static void tryCatch(String fs, Class<?> ex, Object ... args) {
0N/A boolean caught = false;
0N/A try {
0N/A test(fs, args);
0N/A } catch (Throwable x) {
0N/A if (ex.isAssignableFrom(x.getClass()))
0N/A caught = true;
0N/A }
0N/A if (!caught)
0N/A fail(fs, ex);
0N/A else
0N/A pass();
0N/A }
0N/A
0N/A#if[datetime]
0N/A private static void testDateTime(String fs, String exp, Calendar c) {
0N/A testDateTime(fs, exp, c, true);
0N/A }
0N/A
0N/A private static void testDateTime(String fs, String exp, Calendar c, boolean upper) {
0N/A //---------------------------------------------------------------------
0N/A // Date/Time conversions applicable to Calendar, Date, and long.
0N/A //---------------------------------------------------------------------
0N/A
0N/A // Calendar
0N/A test(fs, exp, c);
0N/A test((Locale)null, fs, exp, c);
0N/A test(Locale.US, fs, exp, c);
0N/A
0N/A // Date/long do not have timezone information so they will always use
0N/A // the default timezone.
0N/A String nexp = (fs.equals("%tZ") || fs.equals("%TZ")
0N/A || fs.equals("%tc") || fs.equals("%Tc")
0N/A ? exp.replace("PST", "GMT-08:00")
0N/A : exp);
0N/A
0N/A // Date (implemented via conversion to Calendar)
0N/A Date d = c.getTime();
0N/A test(fs, nexp, d);
0N/A test((Locale)null, fs, nexp, d);
0N/A test(Locale.US, fs, nexp, d);
0N/A
0N/A // long (implemented via conversion to Calendar)
0N/A long l = c.getTimeInMillis();
0N/A test(fs, nexp, l);
0N/A test((Locale)null, fs, nexp, l);
0N/A test(Locale.US, fs, nexp, l);
0N/A
0N/A if (upper)
0N/A // repeat all tests for upper case variant (%T)
0N/A testDateTime(Pattern.compile("t").matcher(fs).replaceFirst("T"),
0N/A exp.toUpperCase(), c, false);
0N/A }
0N/A
0N/A private static void testHours() {
0N/A for (int i = 0; i < 24; i++) {
0N/A // GregorianCalendar(int year, int month, int dayOfMonth,
0N/A // int hourOfDay, int minute, int second);
0N/A Calendar c = new GregorianCalendar(1995, MAY, 23, i, 48, 34);
0N/A
0N/A //-----------------------------------------------------------------
0N/A // DateTime.HOUR_OF_DAY - 'k' (0 - 23) -- like H
0N/A //-----------------------------------------------------------------
0N/A String exp = Integer.toString(i);
0N/A testDateTime("%tk", exp, c);
0N/A
0N/A //-----------------------------------------------------------------
0N/A // DateTime.HOUR - 'l' (1 - 12) -- like I
0N/A //-----------------------------------------------------------------
0N/A int v = i % 12;
0N/A v = (v == 0 ? 12 : v);
0N/A String exp2 = Integer.toString(v);
0N/A testDateTime("%tl", exp2, c);
0N/A
0N/A //-----------------------------------------------------------------
0N/A // DateTime.HOUR_OF_DAY_0 - 'H' (00 - 23) [zero padded]
0N/A //-----------------------------------------------------------------
0N/A if (exp.length() < 2) exp = "0" + exp;
0N/A testDateTime("%tH", exp, c);
0N/A
0N/A //-----------------------------------------------------------------
0N/A // DateTime.HOUR_0 - 'I' (01 - 12)
0N/A //-----------------------------------------------------------------
0N/A if (exp2.length() < 2) exp2 = "0" + exp2;
0N/A testDateTime("%tI", exp2, c);
0N/A
0N/A //-----------------------------------------------------------------
0N/A // DateTime.AM_PM - (am or pm)
0N/A //-----------------------------------------------------------------
0N/A testDateTime("%tp", (i <12 ? "am" : "pm"), c);
0N/A }
0N/A }
0N/A#end[datetime]
0N/A
0N/A#if[dec]
0N/A#if[prim]
0N/A private static $type$ negate($type$ v) {
0N/A return ($type$) -v;
0N/A }
0N/A#end[prim]
0N/A#end[dec]
0N/A#if[Byte]
0N/A private static $type$ negate($type$ v) {
0N/A return new $type$((byte) -v.byteValue());
0N/A }
0N/A#end[Byte]
0N/A#if[Short]
0N/A private static $type$ negate($type$ v) {
0N/A return new $type$((short) -v.shortValue());
0N/A }
0N/A#end[Short]
0N/A#if[Integer]
0N/A private static $type$ negate($type$ v) {
0N/A return new $type$(-v.intValue());
0N/A }
0N/A#end[Integer]
0N/A#if[Long]
0N/A private static $type$ negate($type$ v) {
0N/A return new $type$(-v.longValue());
0N/A }
0N/A#end[Long]
0N/A
0N/A#if[BigDecimal]
0N/A private static $type$ create(double v) {
0N/A return new $type$(v);
0N/A }
0N/A
0N/A private static $type$ negate($type$ v) {
0N/A return v.negate();
0N/A }
0N/A
0N/A private static $type$ mult($type$ v, double mul) {
0N/A return v.multiply(new $type$(mul));
0N/A }
0N/A
0N/A private static $type$ recip($type$ v) {
0N/A return BigDecimal.ONE.divide(v);
0N/A }
0N/A#end[BigDecimal]
0N/A#if[float]
0N/A private static $type$ create(double v) {
0N/A return ($type$) v;
0N/A }
0N/A
0N/A private static $type$ negate(double v) {
0N/A return ($type$) -v;
0N/A }
0N/A
0N/A private static $type$ mult($type$ v, double mul) {
0N/A return v * ($type$) mul;
0N/A }
0N/A
0N/A private static $type$ recip($type$ v) {
0N/A return 1.0f / v;
0N/A }
0N/A#end[float]
0N/A#if[Float]
0N/A private static $type$ create(double v) {
0N/A return new $type$(v);
0N/A }
0N/A
0N/A private static $type$ negate($type$ v) {
0N/A return new $type$(-v.floatValue());
0N/A }
0N/A
0N/A private static $type$ mult($type$ v, double mul) {
0N/A return new $type$(v.floatValue() * (float) mul);
0N/A }
0N/A
0N/A private static $type$ recip($type$ v) {
0N/A return new $type$(1.0f / v.floatValue());
0N/A }
0N/A#end[Float]
0N/A#if[double]
0N/A private static $type$ create(double v) {
0N/A return ($type$) v;
0N/A }
0N/A
0N/A
0N/A private static $type$ negate(double v) {
0N/A return -v;
0N/A }
0N/A
0N/A private static $type$ mult($type$ v, double mul) {
0N/A return v * mul;
0N/A }
0N/A
0N/A private static $type$ recip($type$ v) {
0N/A return 1.0 / v;
0N/A }
0N/A#end[double]
0N/A#if[Double]
0N/A private static $type$ create(double v) {
0N/A return new $type$(v);
0N/A }
0N/A
0N/A private static $type$ negate($type$ v) {
0N/A return new $type$(-v.doubleValue());
0N/A }
0N/A
0N/A private static $type$ mult($type$ v, double mul) {
0N/A return new $type$(v.doubleValue() * mul);
0N/A }
0N/A
0N/A private static $type$ recip($type$ v) {
0N/A return new $type$(1.0 / v.doubleValue());
0N/A }
0N/A#end[Double]
0N/A
0N/A public static void test() {
0N/A TimeZone.setDefault(TimeZone.getTimeZone("GMT-0800"));
0N/A
0N/A // Any characters not explicitly defined as conversions, date/time
0N/A // conversion suffixes, or flags are illegal and are reserved for
0N/A // future extensions. Use of such a character in a format string will
0N/A // cause an UnknownFormatConversionException or
0N/A // UnknownFormatFlagsException to be thrown.
0N/A tryCatch("%q", UnknownFormatConversionException.class);
0N/A tryCatch("%t&", UnknownFormatConversionException.class);
0N/A tryCatch("%&d", UnknownFormatConversionException.class);
0N/A tryCatch("%^b", UnknownFormatConversionException.class);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // Formatter.java class javadoc examples
0N/A //---------------------------------------------------------------------
0N/A test(Locale.FRANCE, "e = %+10.4f", "e = +2,7183", Math.E);
0N/A test("%4$2s %3$2s %2$2s %1$2s", " d c b a", "a", "b", "c", "d");
0N/A test("Amount gained or lost since last statement: $ %,(.2f",
0N/A "Amount gained or lost since last statement: $ (6,217.58)",
0N/A (new BigDecimal("-6217.58")));
0N/A Calendar c = new GregorianCalendar(1969, JULY, 20, 16, 17, 0);
0N/A testSysOut("Local time: %tT", "Local time: 16:17:00", c);
0N/A
0N/A test("Unable to open file '%1$s': %2$s",
0N/A "Unable to open file 'food': No such file or directory",
0N/A "food", "No such file or directory");
0N/A Calendar duke = new GregorianCalendar(1995, MAY, 23, 19, 48, 34);
0N/A duke.set(Calendar.MILLISECOND, 584);
0N/A test("Duke's Birthday: %1$tB %1$te, %1$tY",
0N/A "Duke's Birthday: May 23, 1995",
0N/A duke);
0N/A test("Duke's Birthday: %1$tB %1$te, %1$tY",
0N/A "Duke's Birthday: May 23, 1995",
0N/A duke.getTime());
0N/A test("Duke's Birthday: %1$tB %1$te, %1$tY",
0N/A "Duke's Birthday: May 23, 1995",
0N/A duke.getTimeInMillis());
0N/A
0N/A test("%4$s %3$s %2$s %1$s %4$s %3$s %2$s %1$s",
0N/A "d c b a d c b a", "a", "b", "c", "d");
0N/A test("%s %s %<s %<s", "a b b b", "a", "b", "c", "d");
0N/A test("%s %s %s %s", "a b c d", "a", "b", "c", "d");
0N/A test("%2$s %s %<s %s", "b a a b", "a", "b", "c", "d");
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %b
0N/A //
0N/A // General conversion applicable to any argument.
0N/A //---------------------------------------------------------------------
0N/A test("%b", "true", true);
0N/A test("%b", "false", false);
0N/A test("%B", "TRUE", true);
0N/A test("%B", "FALSE", false);
0N/A test("%b", "true", Boolean.TRUE);
0N/A test("%b", "false", Boolean.FALSE);
0N/A test("%B", "TRUE", Boolean.TRUE);
0N/A test("%B", "FALSE", Boolean.FALSE);
0N/A test("%14b", " true", true);
0N/A test("%-14b", "true ", true);
0N/A test("%5.1b", " f", false);
0N/A test("%-5.1b", "f ", false);
0N/A
0N/A test("%b", "true", "foo");
0N/A test("%b", "false", (Object)null);
0N/A
0N/A // Boolean.java hardcodes the Strings for "true" and "false", so no
0N/A // localization is possible.
0N/A test(Locale.FRANCE, "%b", "true", true);
0N/A test(Locale.FRANCE, "%b", "false", false);
0N/A
0N/A // If you pass in a single array to a varargs method, the compiler
0N/A // uses it as the array of arguments rather than treating it as a
0N/A // single array-type argument.
0N/A test("%b", "false", (Object[])new String[2]);
0N/A test("%b", "true", new String[2], new String[2]);
0N/A
0N/A int [] ia = { 1, 2, 3 };
0N/A test("%b", "true", ia);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %b - errors
0N/A //---------------------------------------------------------------------
0N/A tryCatch("%#b", FormatFlagsConversionMismatchException.class);
0N/A tryCatch("%-b", MissingFormatWidthException.class);
0N/A // correct or side-effect of implementation?
0N/A tryCatch("%.b", UnknownFormatConversionException.class);
0N/A tryCatch("%,b", FormatFlagsConversionMismatchException.class);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %c
0N/A //
0N/A // General conversion applicable to any argument.
0N/A //---------------------------------------------------------------------
0N/A test("%c", "i", 'i');
0N/A test("%C", "I", 'i');
0N/A test("%4c", " i", 'i');
0N/A test("%-4c", "i ", 'i');
0N/A test("%4C", " I", 'i');
0N/A test("%-4C", "I ", 'i');
0N/A test("%c", "i", new Character('i'));
0N/A test("%c", "H", (byte) 72);
0N/A test("%c", "i", (short) 105);
0N/A test("%c", "!", (int) 33);
0N/A test("%c", "\u007F", Byte.MAX_VALUE);
0N/A test("%c", new String(Character.toChars(Short.MAX_VALUE)),
0N/A Short.MAX_VALUE);
0N/A test("%c", "null", (Object) null);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %c - errors
0N/A //---------------------------------------------------------------------
0N/A tryCatch("%c", IllegalFormatConversionException.class,
0N/A Boolean.TRUE);
0N/A tryCatch("%c", IllegalFormatConversionException.class,
0N/A (float) 0.1);
0N/A tryCatch("%c", IllegalFormatConversionException.class,
0N/A new Object());
0N/A tryCatch("%c", IllegalFormatCodePointException.class,
0N/A Byte.MIN_VALUE);
0N/A tryCatch("%c", IllegalFormatCodePointException.class,
0N/A Short.MIN_VALUE);
0N/A tryCatch("%c", IllegalFormatCodePointException.class,
0N/A Integer.MIN_VALUE);
0N/A tryCatch("%c", IllegalFormatCodePointException.class,
0N/A Integer.MAX_VALUE);
0N/A
0N/A tryCatch("%#c", FormatFlagsConversionMismatchException.class);
0N/A tryCatch("%,c", FormatFlagsConversionMismatchException.class);
0N/A tryCatch("%(c", FormatFlagsConversionMismatchException.class);
0N/A tryCatch("%$c", UnknownFormatConversionException.class);
0N/A tryCatch("%.2c", IllegalFormatPrecisionException.class);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %s
0N/A //
0N/A // General conversion applicable to any argument.
0N/A //---------------------------------------------------------------------
0N/A test("%s", "Hello, Duke", "Hello, Duke");
0N/A test("%S", "HELLO, DUKE", "Hello, Duke");
0N/A test("%20S", " HELLO, DUKE", "Hello, Duke");
0N/A test("%20s", " Hello, Duke", "Hello, Duke");
0N/A test("%-20s", "Hello, Duke ", "Hello, Duke");
0N/A test("%-20.5s", "Hello ", "Hello, Duke");
0N/A test("%s", "null", (Object)null);
0N/A
0N/A StringBuffer sb = new StringBuffer("foo bar");
0N/A test("%s", sb.toString(), sb);
0N/A test("%S", sb.toString().toUpperCase(), sb);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %s - errors
0N/A //---------------------------------------------------------------------
0N/A tryCatch("%-s", MissingFormatWidthException.class);
0N/A tryCatch("%--s", DuplicateFormatFlagsException.class);
1469N/A tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
1469N/A tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
1469N/A tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
1469N/A tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %h
0N/A //
0N/A // General conversion applicable to any argument.
0N/A //---------------------------------------------------------------------
0N/A test("%h", Integer.toHexString("Hello, Duke".hashCode()),
0N/A "Hello, Duke");
0N/A test("%10h", " ddf63471", "Hello, Duke");
0N/A test("%-10h", "ddf63471 ", "Hello, Duke");
0N/A test("%-10H", "DDF63471 ", "Hello, Duke");
0N/A test("%10h", " 402e0000", 15.0);
0N/A test("%10H", " 402E0000", 15.0);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %h - errors
0N/A //---------------------------------------------------------------------
0N/A tryCatch("%#h", FormatFlagsConversionMismatchException.class);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // flag/conversion errors
0N/A //---------------------------------------------------------------------
0N/A tryCatch("%F", UnknownFormatConversionException.class);
0N/A
0N/A tryCatch("%#g", FormatFlagsConversionMismatchException.class);
0N/A
0N/A#if[dec]
0N/A
0N/A#if[prim]
0N/A $type$ minByte = Byte.MIN_VALUE; // -128
0N/A#else[prim]
0N/A $type$ minByte = new $type$(Byte.MIN_VALUE);
0N/A#end[prim]
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %d
0N/A //
0N/A // Numeric conversion applicable to byte, short, int, long, and
0N/A // BigInteger.
0N/A //---------------------------------------------------------------------
0N/A test("%d", "null", (Object)null);
0N/A
0N/A#if[byte]
0N/A#if[prim]
0N/A //---------------------------------------------------------------------
0N/A // %d - byte
0N/A //---------------------------------------------------------------------
0N/A $type$ seventeen = ($type$) 17;
0N/A test("%d", "17", seventeen);
0N/A test("%,d", "17", seventeen);
0N/A test("%,d", "-17", negate(seventeen));
0N/A test("%(d", "17", seventeen);
0N/A test("%(d", "(17)", negate(seventeen));
0N/A test("% d", " 17", seventeen);
0N/A test("% d", "-17", negate(seventeen));
0N/A test("%+d", "+17", seventeen);
0N/A test("%+d", "-17", negate(seventeen));
0N/A test("%010d", "0000000017", seventeen);
0N/A test("%010d", "-000000017", negate(seventeen));
0N/A test("%(10d", " (17)", negate(seventeen));
0N/A test("%-10d", "17 ", seventeen);
0N/A test("%-10d", "-17 ", negate(seventeen));
0N/A#end[prim]
0N/A#else[byte]
0N/A#if[short]
0N/A //---------------------------------------------------------------------
0N/A // %d - short
0N/A //---------------------------------------------------------------------
0N/A $type$ oneToFive = ($type$) 12345;
0N/A test("%d", "12345", oneToFive);
0N/A test("%,d", "12,345", oneToFive);
0N/A test("%,d", "-12,345", negate(oneToFive));
0N/A test("%(d", "12345", oneToFive);
0N/A test("%(d", "(12345)", negate(oneToFive));
0N/A test("% d", " 12345", oneToFive);
0N/A test("% d", "-12345", negate(oneToFive));
0N/A test("%+d", "+12345", oneToFive);
0N/A test("%+d", "-12345", negate(oneToFive));
0N/A test("%010d", "0000012345", oneToFive);
0N/A test("%010d", "-000012345", negate(oneToFive));
0N/A test("%(10d", " (12345)", negate(oneToFive));
0N/A test("%-10d", "12345 ", oneToFive);
0N/A test("%-10d", "-12345 ", negate(oneToFive));
0N/A
0N/A#else[short]
0N/A#if[prim]
0N/A //---------------------------------------------------------------------
0N/A // %d - int and long
0N/A //---------------------------------------------------------------------
0N/A $type$ oneToSeven = ($type$) 1234567;
0N/A test("%d", "1234567", oneToSeven);
0N/A test("%,d", "1,234,567", oneToSeven);
0N/A test(Locale.FRANCE, "%,d", "1\u00a0234\u00a0567", oneToSeven);
0N/A test("%,d", "-1,234,567", negate(oneToSeven));
0N/A test("%(d", "1234567", oneToSeven);
0N/A test("%(d", "(1234567)", negate(oneToSeven));
0N/A test("% d", " 1234567", oneToSeven);
0N/A test("% d", "-1234567", negate(oneToSeven));
0N/A test("%+d", "+1234567", oneToSeven);
0N/A test("%+d", "-1234567", negate(oneToSeven));
0N/A test("%010d", "0001234567", oneToSeven);
0N/A test("%010d", "-001234567", negate(oneToSeven));
0N/A test("%(10d", " (1234567)", negate(oneToSeven));
0N/A test("%-10d", "1234567 ", oneToSeven);
0N/A test("%-10d", "-1234567 ", negate(oneToSeven));
0N/A#end[prim]
0N/A#end[short]
0N/A#end[byte]
0N/A //---------------------------------------------------------------------
0N/A // %d - errors
0N/A //---------------------------------------------------------------------
0N/A tryCatch("%#d", FormatFlagsConversionMismatchException.class);
0N/A tryCatch("%D", UnknownFormatConversionException.class);
0N/A tryCatch("%0d", MissingFormatWidthException.class);
0N/A tryCatch("%-d", MissingFormatWidthException.class);
0N/A tryCatch("%7.3d", IllegalFormatPrecisionException.class);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %o
0N/A //
0N/A // Numeric conversion applicable to byte, short, int, long, and
0N/A // BigInteger.
0N/A //---------------------------------------------------------------------
0N/A test("%o", "null", (Object)null);
0N/A
0N/A#if[byte]
0N/A //---------------------------------------------------------------------
0N/A // %o - byte
0N/A //---------------------------------------------------------------------
0N/A test("%010o", "0000000200", minByte);
0N/A test("%-10o", "200 ", minByte);
0N/A test("%#10o", " 0200", minByte);
0N/A#end[byte]
0N/A#if[short]
0N/A //---------------------------------------------------------------------
0N/A // %o - short
0N/A //---------------------------------------------------------------------
0N/A
0N/A test("%010o", "0000177600", minByte);
0N/A test("%-10o", "177600 ", minByte);
0N/A test("%#10o", " 0177600", minByte);
0N/A#end[short]
0N/A#if[int]
0N/A //---------------------------------------------------------------------
0N/A // %o - int
0N/A //---------------------------------------------------------------------
0N/A test("%014o", "00037777777600", minByte);
0N/A test("%-14o", "37777777600 ", minByte);
0N/A test("%#14o", " 037777777600", minByte);
0N/A
0N/A $type$ oneToSevenOct = ($type$) 1234567;
0N/A test("%o", "4553207", oneToSevenOct);
0N/A test("%010o", "0004553207", oneToSevenOct);
0N/A test("%-10o", "4553207 ", oneToSevenOct);
0N/A test("%#10o", " 04553207", oneToSevenOct);
0N/A#end[int]
0N/A#if[long]
0N/A //---------------------------------------------------------------------
0N/A // %o - long
0N/A //---------------------------------------------------------------------
0N/A test("%024o", "001777777777777777777600", minByte);
0N/A test("%-24o", "1777777777777777777600 ", minByte);
0N/A test("%#24o", " 01777777777777777777600", minByte);
0N/A
0N/A $type$ oneToSevenOct = ($type$) 1234567;
0N/A test("%o", "4553207", oneToSevenOct);
0N/A test("%010o", "0004553207", oneToSevenOct);
0N/A test("%-10o", "4553207 ", oneToSevenOct);
0N/A test("%#10o", " 04553207", oneToSevenOct);
0N/A#end[long]
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %o - errors
0N/A //---------------------------------------------------------------------
0N/A tryCatch("%(o", FormatFlagsConversionMismatchException.class,
0N/A minByte);
0N/A tryCatch("%+o", FormatFlagsConversionMismatchException.class,
0N/A minByte);
0N/A tryCatch("% o", FormatFlagsConversionMismatchException.class,
0N/A minByte);
0N/A tryCatch("%0o", MissingFormatWidthException.class);
0N/A tryCatch("%-o", MissingFormatWidthException.class);
0N/A tryCatch("%,o", FormatFlagsConversionMismatchException.class);
0N/A tryCatch("%O", UnknownFormatConversionException.class);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %x
0N/A //
0N/A // Numeric conversion applicable to byte, short, int, long, and
0N/A // BigInteger.
0N/A //---------------------------------------------------------------------
0N/A test("%x", "null", (Object)null);
0N/A
0N/A#if[byte]
0N/A //---------------------------------------------------------------------
0N/A // %x - byte
0N/A //---------------------------------------------------------------------
0N/A test("%010x", "0000000080", minByte);
0N/A test("%-10x", "80 ", minByte);
0N/A test("%#10x", " 0x80", minByte);
0N/A test("%0#10x","0x00000080", minByte);
0N/A test("%#10X", " 0X80", minByte);
0N/A test("%X", "80", minByte);
0N/A#end[byte]
0N/A#if[short]
0N/A //---------------------------------------------------------------------
0N/A // %x - short
0N/A //---------------------------------------------------------------------
0N/A test("%010x", "000000ff80", minByte);
0N/A test("%-10x", "ff80 ", minByte);
0N/A test("%#10x", " 0xff80", minByte);
0N/A test("%0#10x","0x0000ff80", minByte);
0N/A test("%#10X", " 0XFF80", minByte);
0N/A test("%X", "FF80", minByte);
0N/A#end[short]
0N/A#if[int]
0N/A //---------------------------------------------------------------------
0N/A // %x - int
0N/A //---------------------------------------------------------------------
0N/A $type$ oneToSevenHex = ($type$)1234567;
0N/A test("%x", "null", (Object)null);
0N/A test("%x", "12d687", oneToSevenHex);
0N/A test("%010x", "000012d687", oneToSevenHex);
0N/A test("%-10x", "12d687 ", oneToSevenHex);
0N/A test("%#10x", " 0x12d687", oneToSevenHex);
0N/A test("%#10X", " 0X12D687",oneToSevenHex);
0N/A test("%X", "12D687", oneToSevenHex);
0N/A
0N/A test("%010x", "00ffffff80", minByte);
0N/A test("%-10x", "ffffff80 ", minByte);
0N/A test("%#10x", "0xffffff80", minByte);
0N/A test("%0#12x","0x00ffffff80", minByte);
0N/A test("%#12X", " 0XFFFFFF80", minByte);
0N/A test("%X", "FFFFFF80", minByte);
0N/A#end[int]
0N/A#if[long]
0N/A //---------------------------------------------------------------------
0N/A // %x - long
0N/A //---------------------------------------------------------------------
0N/A $type$ oneToSevenHex = ($type$)1234567;
0N/A test("%x", "null", (Object)null);
0N/A test("%x", "12d687", oneToSevenHex);
0N/A test("%010x", "000012d687", oneToSevenHex);
0N/A test("%-10x", "12d687 ", oneToSevenHex);
0N/A test("%#10x", " 0x12d687", oneToSevenHex);
0N/A test("%#10X", " 0X12D687",oneToSevenHex);
0N/A test("%X", "12D687", oneToSevenHex);
0N/A
0N/A test("%018x", "00ffffffffffffff80", minByte);
0N/A test("%-18x", "ffffffffffffff80 ", minByte);
0N/A test("%#20x", " 0xffffffffffffff80", minByte);
0N/A test("%0#20x", "0x00ffffffffffffff80", minByte);
0N/A test("%#20X", " 0XFFFFFFFFFFFFFF80", minByte);
0N/A test("%X", "FFFFFFFFFFFFFF80", minByte);
0N/A#end[long]
0N/A //---------------------------------------------------------------------
0N/A // %x - errors
0N/A //---------------------------------------------------------------------
0N/A tryCatch("%,x", FormatFlagsConversionMismatchException.class);
0N/A tryCatch("%0x", MissingFormatWidthException.class);
0N/A tryCatch("%-x", MissingFormatWidthException.class);
0N/A
0N/A#end[dec]
0N/A
0N/A#if[BigInteger]
0N/A //---------------------------------------------------------------------
0N/A // BigInteger - errors
0N/A //---------------------------------------------------------------------
0N/A tryCatch("%f", IllegalFormatConversionException.class,
0N/A new BigInteger("1"));
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %d - BigInteger
0N/A //---------------------------------------------------------------------
0N/A test("%d", "null", (Object)null);
0N/A test("%d", "1234567", new BigInteger("1234567", 10));
0N/A test("%,d", "1,234,567", new BigInteger("1234567", 10));
0N/A test(Locale.FRANCE, "%,d", "1\u00a0234\u00a0567", new BigInteger("1234567", 10));
0N/A test("%,d", "-1,234,567", new BigInteger("-1234567", 10));
0N/A test("%(d", "1234567", new BigInteger("1234567", 10));
0N/A test("%(d", "(1234567)", new BigInteger("-1234567", 10));
0N/A test("% d", " 1234567", new BigInteger("1234567", 10));
0N/A test("% d", "-1234567", new BigInteger("-1234567", 10));
0N/A test("%+d", "+1234567", new BigInteger("1234567", 10));
0N/A test("%+d", "-1234567", new BigInteger("-1234567", 10));
0N/A test("%010d", "0001234567", new BigInteger("1234567", 10));
0N/A test("%010d", "-001234567", new BigInteger("-1234567", 10));
0N/A test("%(10d", " (1234567)", new BigInteger("-1234567", 10));
0N/A test("%+d", "+1234567", new BigInteger("1234567", 10));
0N/A test("%+d", "-1234567", new BigInteger("-1234567", 10));
0N/A test("%-10d", "1234567 ", new BigInteger("1234567", 10));
0N/A test("%-10d", "-1234567 ", new BigInteger("-1234567", 10));
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %o - BigInteger
0N/A //---------------------------------------------------------------------
0N/A test("%o", "null", (Object)null);
0N/A test("%o", "1234567", new BigInteger("1234567", 8));
0N/A test("%(o", "1234567", new BigInteger("1234567", 8));
0N/A test("%(o", "(1234567)", new BigInteger("-1234567", 8));
0N/A test("% o", " 1234567", new BigInteger("1234567", 8));
0N/A test("% o", "-1234567", new BigInteger("-1234567", 8));
0N/A test("%+o", "+1234567", new BigInteger("1234567", 8));
0N/A test("%+o", "-1234567", new BigInteger("-1234567", 8));
0N/A test("%010o", "0001234567", new BigInteger("1234567", 8));
0N/A test("%010o", "-001234567", new BigInteger("-1234567", 8));
0N/A test("%(10o", " (1234567)", new BigInteger("-1234567", 8));
0N/A test("%+o", "+1234567", new BigInteger("1234567", 8));
0N/A test("%+o", "-1234567", new BigInteger("-1234567", 8));
0N/A test("%-10o", "1234567 ", new BigInteger("1234567", 8));
0N/A test("%-10o", "-1234567 ", new BigInteger("-1234567", 8));
0N/A test("%#10o", " 01234567", new BigInteger("1234567", 8));
0N/A test("%#10o", " -01234567", new BigInteger("-1234567", 8));
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %x - BigInteger
0N/A //---------------------------------------------------------------------
0N/A test("%x", "null", (Object)null);
0N/A test("%x", "1234567", new BigInteger("1234567", 16));
0N/A test("%(x", "1234567", new BigInteger("1234567", 16));
0N/A test("%(x", "(1234567)", new BigInteger("-1234567", 16));
0N/A test("% x", " 1234567", new BigInteger("1234567", 16));
0N/A test("% x", "-1234567", new BigInteger("-1234567", 16));
0N/A test("%+x", "+1234567", new BigInteger("1234567", 16));
0N/A test("%+x", "-1234567", new BigInteger("-1234567", 16));
0N/A test("%010x", "0001234567", new BigInteger("1234567", 16));
0N/A test("%010x", "-001234567", new BigInteger("-1234567", 16));
0N/A test("%(10x", " (1234567)", new BigInteger("-1234567", 16));
0N/A test("%+x", "+1234567", new BigInteger("1234567", 16));
0N/A test("%+x", "-1234567", new BigInteger("-1234567", 16));
0N/A test("%-10x", "1234567 ", new BigInteger("1234567", 16));
0N/A test("%-10x", "-1234567 ", new BigInteger("-1234567", 16));
0N/A test("%#10x", " 0x1234567", new BigInteger("1234567", 16));
0N/A test("%#10x", "-0x1234567", new BigInteger("-1234567", 16));
0N/A test("%#10X", " 0X1234567", new BigInteger("1234567", 16));
0N/A test("%#10X", "-0X1234567", new BigInteger("-1234567", 16));
0N/A test("%X", "1234567A", new BigInteger("1234567a", 16));
0N/A test("%X", "-1234567A", new BigInteger("-1234567a", 16));
0N/A#end[BigInteger]
0N/A
0N/A#if[fp]
0N/A#if[BigDecimal]
0N/A //---------------------------------------------------------------------
0N/A // %s - BigDecimal
0N/A //---------------------------------------------------------------------
0N/A $type$ one = BigDecimal.ONE;
0N/A $type$ ten = BigDecimal.TEN;
0N/A $type$ pi = new $type$(Math.PI);
0N/A $type$ piToThe300 = pi.pow(300);
0N/A
0N/A test("%s", "3.141592653589793115997963468544185161590576171875", pi);
0N/A#end[BigDecimal]
0N/A#if[float]
0N/A //---------------------------------------------------------------------
0N/A // %s - float
0N/A //---------------------------------------------------------------------
0N/A $type$ one = 1.0f;
0N/A $type$ ten = 10.0f;
0N/A $type$ pi = (float) Math.PI;
0N/A
0N/A test("%s", "3.1415927", pi);
0N/A#end[float]
0N/A#if[Float]
0N/A //---------------------------------------------------------------------
0N/A // %s - Float
0N/A //---------------------------------------------------------------------
0N/A $type$ one = new $type$(1.0f);
0N/A $type$ ten = new $type$(10.0f);
0N/A $type$ pi = new $type$(Math.PI);
0N/A
0N/A test("%s", "3.1415927", pi);
0N/A#end[Float]
0N/A#if[double]
0N/A //---------------------------------------------------------------------
0N/A // %s - double
0N/A //---------------------------------------------------------------------
0N/A $type$ one = 1.0;
0N/A $type$ ten = 10.0;
0N/A $type$ pi = Math.PI;
0N/A
0N/A test("%s", "3.141592653589793", pi);
0N/A#end[double]
0N/A#if[Double]
0N/A //---------------------------------------------------------------------
0N/A // %s - Double
0N/A //---------------------------------------------------------------------
0N/A $type$ one = new $type$(1.0);
0N/A $type$ ten = new $type$(10.0);
0N/A $type$ pi = new $type$(Math.PI);
0N/A
0N/A test("%s", "3.141592653589793", pi);
0N/A#end[Double]
0N/A
0N/A //---------------------------------------------------------------------
0N/A // flag/conversion errors
0N/A //---------------------------------------------------------------------
0N/A tryCatch("%d", IllegalFormatConversionException.class, one);
0N/A tryCatch("%,.4e", FormatFlagsConversionMismatchException.class, one);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %e
0N/A //
0N/A // Floating-point conversions applicable to float, double, and
0N/A // BigDecimal.
0N/A //---------------------------------------------------------------------
0N/A test("%e", "null", (Object)null);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %e - float and double
0N/A //---------------------------------------------------------------------
0N/A // double PI = 3.141 592 653 589 793 238 46;
0N/A test("%e", "3.141593e+00", pi);
0N/A test("%.0e", "1e+01", ten);
0N/A test("%#.0e", "1.e+01", ten);
0N/A test("%E", "3.141593E+00", pi);
0N/A test("%10.3e", " 3.142e+00", pi);
0N/A test("%10.3e", "-3.142e+00", negate(pi));
0N/A test("%010.3e", "03.142e+00", pi);
0N/A test("%010.3e", "-3.142e+00", negate(pi));
0N/A test("%-12.3e", "3.142e+00 ", pi);
0N/A test("%-12.3e", "-3.142e+00 ", negate(pi));
0N/A test("%.3e", "3.142e+00", pi);
0N/A test("%.3e", "-3.142e+00", negate(pi));
0N/A test("%.3e", "3.142e+06", mult(pi, 1000000.0));
0N/A test("%.3e", "-3.142e+06", mult(pi, -1000000.0));
0N/A
0N/A test(Locale.FRANCE, "%e", "3,141593e+00", pi);
0N/A
0N/A // double PI^300
0N/A // = 13962455701329742638131355433930076081862072808 ... e+149
0N/A#if[BigDecimal]
0N/A //---------------------------------------------------------------------
0N/A // %e - BigDecimal
0N/A //---------------------------------------------------------------------
0N/A test("%.3e", "1.396e+149", piToThe300);
0N/A test("%.3e", "-1.396e+149", piToThe300.negate());
0N/A test("%.3e", "1.000e-100", recip(ten.pow(100)));
0N/A test("%.3e", "-1.000e-100", negate(recip(ten.pow(100))));
0N/A
0N/A test("%3.0e", "1e-06", new BigDecimal("0.000001"));
0N/A test("%3.0e", "1e-05", new BigDecimal("0.00001"));
0N/A test("%3.0e", "1e-04", new BigDecimal("0.0001"));
0N/A test("%3.0e", "1e-03", new BigDecimal("0.001"));
0N/A test("%3.0e", "1e-02", new BigDecimal("0.01"));
0N/A test("%3.0e", "1e-01", new BigDecimal("0.1"));
0N/A test("%3.0e", "9e-01", new BigDecimal("0.9"));
0N/A test("%3.1e", "9.0e-01", new BigDecimal("0.9"));
0N/A test("%3.0e", "1e+00", new BigDecimal("1.00"));
0N/A test("%3.0e", "1e+01", new BigDecimal("10.00"));
0N/A test("%3.0e", "1e+02", new BigDecimal("99.19"));
0N/A test("%3.1e", "9.9e+01", new BigDecimal("99.19"));
0N/A test("%3.0e", "1e+02", new BigDecimal("99.99"));
0N/A test("%3.0e", "1e+02", new BigDecimal("100.00"));
0N/A test("%#3.0e", "1.e+03", new BigDecimal("1000.00"));
0N/A test("%3.0e", "1e+04", new BigDecimal("10000.00"));
0N/A test("%3.0e", "1e+05", new BigDecimal("100000.00"));
0N/A test("%3.0e", "1e+06", new BigDecimal("1000000.00"));
0N/A test("%3.0e", "1e+07", new BigDecimal("10000000.00"));
0N/A test("%3.0e", "1e+08", new BigDecimal("100000000.00"));
0N/A#end[BigDecimal]
0N/A
0N/A test("%10.3e", " 1.000e+00", one);
0N/A test("%+.3e", "+3.142e+00", pi);
0N/A test("%+.3e", "-3.142e+00", negate(pi));
0N/A test("% .3e", " 3.142e+00", pi);
0N/A test("% .3e", "-3.142e+00", negate(pi));
0N/A test("%#.0e", "3.e+00", create(3.0));
0N/A test("%#.0e", "-3.e+00", create(-3.0));
0N/A test("%.0e", "3e+00", create(3.0));
0N/A test("%.0e", "-3e+00", create(-3.0));
0N/A
0N/A test("%(.4e", "3.1416e+06", mult(pi, 1000000.0));
0N/A test("%(.4e", "(3.1416e+06)", mult(pi, -1000000.0));
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %e - boundary problems
0N/A //---------------------------------------------------------------------
0N/A test("%3.0e", "1e-06", 0.000001);
0N/A test("%3.0e", "1e-05", 0.00001);
0N/A test("%3.0e", "1e-04", 0.0001);
0N/A test("%3.0e", "1e-03", 0.001);
0N/A test("%3.0e", "1e-02", 0.01);
0N/A test("%3.0e", "1e-01", 0.1);
0N/A test("%3.0e", "9e-01", 0.9);
0N/A test("%3.1e", "9.0e-01", 0.9);
0N/A test("%3.0e", "1e+00", 1.00);
0N/A test("%3.0e", "1e+01", 10.00);
0N/A test("%3.0e", "1e+02", 99.19);
0N/A test("%3.1e", "9.9e+01", 99.19);
0N/A test("%3.0e", "1e+02", 99.99);
0N/A test("%3.0e", "1e+02", 100.00);
0N/A test("%#3.0e", "1.e+03", 1000.00);
0N/A test("%3.0e", "1e+04", 10000.00);
0N/A test("%3.0e", "1e+05", 100000.00);
0N/A test("%3.0e", "1e+06", 1000000.00);
0N/A test("%3.0e", "1e+07", 10000000.00);
0N/A test("%3.0e", "1e+08", 100000000.00);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %f
0N/A //
0N/A // Floating-point conversions applicable to float, double, and
0N/A // BigDecimal.
0N/A //---------------------------------------------------------------------
0N/A test("%f", "null", (Object)null);
0N/A test("%f", "3.141593", pi);
0N/A test(Locale.FRANCE, "%f", "3,141593", pi);
0N/A test("%10.3f", " 3.142", pi);
0N/A test("%10.3f", " -3.142", negate(pi));
0N/A test("%010.3f", "000003.142", pi);
0N/A test("%010.3f", "-00003.142", negate(pi));
0N/A test("%-10.3f", "3.142 ", pi);
0N/A test("%-10.3f", "-3.142 ", negate(pi));
0N/A test("%.3f", "3.142", pi);
0N/A test("%.3f", "-3.142", negate(pi));
0N/A test("%+.3f", "+3.142", pi);
0N/A test("%+.3f", "-3.142", negate(pi));
0N/A test("% .3f", " 3.142", pi);
0N/A test("% .3f", "-3.142", negate(pi));
0N/A test("%#.0f", "3.", create(3.0));
0N/A test("%#.0f", "-3.", create(-3.0));
0N/A test("%.0f", "3", create(3.0));
0N/A test("%.0f", "-3", create(-3.0));
0N/A test("%.3f", "10.000", ten);
0N/A test("%.3f", "1.000", one);
0N/A test("%10.3f", " 1.000", one);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %f - boundary problems
0N/A //---------------------------------------------------------------------
0N/A test("%3.0f", " 0", 0.000001);
0N/A test("%3.0f", " 0", 0.00001);
0N/A test("%3.0f", " 0", 0.0001);
0N/A test("%3.0f", " 0", 0.001);
0N/A test("%3.0f", " 0", 0.01);
0N/A test("%3.0f", " 0", 0.1);
0N/A test("%3.0f", " 1", 0.9);
0N/A test("%3.1f", "0.9", 0.9);
0N/A test("%3.0f", " 1", 1.00);
0N/A test("%3.0f", " 10", 10.00);
0N/A test("%3.0f", " 99", 99.19);
0N/A test("%3.1f", "99.2", 99.19);
0N/A test("%3.0f", "100", 99.99);
0N/A test("%3.0f", "100", 100.00);
0N/A test("%#3.0f", "1000.", 1000.00);
0N/A test("%3.0f", "10000", 10000.00);
0N/A test("%3.0f", "100000", 100000.00);
0N/A test("%3.0f", "1000000", 1000000.00);
0N/A test("%3.0f", "10000000", 10000000.00);
0N/A test("%3.0f", "100000000", 100000000.00);
0N/A#if[BigDecimal]
0N/A //---------------------------------------------------------------------
0N/A // %f - BigDecimal
0N/A //---------------------------------------------------------------------
0N/A test("%4.0f", " 99", new BigDecimal("99.19"));
0N/A test("%4.1f", "99.2", new BigDecimal("99.19"));
0N/A
0N/A BigDecimal val = new BigDecimal("99.95");
0N/A test("%4.0f", " 100", val);
0N/A test("%#4.0f", "100.", val);
0N/A test("%4.1f", "100.0", val);
0N/A test("%4.2f", "99.95", val);
0N/A test("%4.3f", "99.950", val);
0N/A
0N/A val = new BigDecimal(".99");
0N/A test("%4.1f", " 1.0", val);
0N/A test("%4.2f", "0.99", val);
0N/A test("%4.3f", "0.990", val);
806N/A
806N/A // #6476425
806N/A val = new BigDecimal("0.00001");
806N/A test("%.0f", "0", val);
806N/A test("%.1f", "0.0", val);
806N/A test("%.2f", "0.00", val);
806N/A test("%.3f", "0.000", val);
806N/A test("%.4f", "0.0000", val);
806N/A test("%.5f", "0.00001", val);
806N/A
806N/A val = new BigDecimal("1.00001");
806N/A test("%.0f", "1", val);
806N/A test("%.1f", "1.0", val);
806N/A test("%.2f", "1.00", val);
806N/A test("%.3f", "1.000", val);
806N/A test("%.4f", "1.0000", val);
806N/A test("%.5f", "1.00001", val);
806N/A
806N/A val = new BigDecimal("1.23456");
806N/A test("%.0f", "1", val);
806N/A test("%.1f", "1.2", val);
806N/A test("%.2f", "1.23", val);
806N/A test("%.3f", "1.235", val);
806N/A test("%.4f", "1.2346", val);
806N/A test("%.5f", "1.23456", val);
806N/A test("%.6f", "1.234560", val);
806N/A
806N/A val = new BigDecimal("9.99999");
806N/A test("%.0f", "10", val);
806N/A test("%.1f", "10.0", val);
806N/A test("%.2f", "10.00", val);
806N/A test("%.3f", "10.000", val);
806N/A test("%.4f", "10.0000", val);
806N/A test("%.5f", "9.99999", val);
806N/A test("%.6f", "9.999990", val);
806N/A
806N/A
806N/A val = new BigDecimal("1.99999");
806N/A test("%.0f", "2", val);
806N/A test("%.1f", "2.0", val);
806N/A test("%.2f", "2.00", val);
806N/A test("%.3f", "2.000", val);
806N/A test("%.4f", "2.0000", val);
806N/A test("%.5f", "1.99999", val);
806N/A test("%.6f", "1.999990", val);
806N/A
0N/A#end[BigDecimal]
0N/A
0N/A#if[float]
0N/A //---------------------------------------------------------------------
0N/A // %f - float
0N/A //---------------------------------------------------------------------
0N/A // Float can not accurately store 1e6 * PI.
0N/A test("%.3f", "3141.593", mult(pi, 1000.0));
0N/A test("%.3f", "-3141.593", mult(pi, -1000.0));
0N/A
0N/A test("%,.2f", "3,141.59", mult(pi, 1000.0));
0N/A test(Locale.FRANCE, "%,.2f", "3\u00a0141,59", mult(pi, 1000.0));
0N/A test("%,.2f", "-3,141.59", mult(pi, -1000.0));
0N/A test("%(.2f", "3141.59", mult(pi, 1000.0));
0N/A test("%(.2f", "(3141.59)", mult(pi, -1000.0));
0N/A test("%(,.2f", "3,141.59", mult(pi, 1000.0));
0N/A test("%(,.2f", "(3,141.59)", mult(pi, -1000.0));
0N/A
0N/A#else[float]
0N/A#if[!Float]
0N/A //---------------------------------------------------------------------
0N/A // %f - float, double, Double, BigDecimal
0N/A //---------------------------------------------------------------------
0N/A test("%.3f", "3141592.654", mult(pi, 1000000.0));
0N/A test("%.3f", "-3141592.654", mult(pi, -1000000.0));
0N/A test("%,.4f", "3,141,592.6536", mult(pi, 1000000.0));
0N/A test(Locale.FRANCE, "%,.4f", "3\u00a0141\u00a0592,6536", mult(pi, 1000000.0));
0N/A test("%,.4f", "-3,141,592.6536", mult(pi, -1000000.0));
0N/A test("%(.4f", "3141592.6536", mult(pi, 1000000.0));
0N/A test("%(.4f", "(3141592.6536)", mult(pi, -1000000.0));
0N/A test("%(,.4f", "3,141,592.6536", mult(pi, 1000000.0));
0N/A test("%(,.4f", "(3,141,592.6536)", mult(pi, -1000000.0));
0N/A#end[!Float]
0N/A#end[float]
0N/A
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %g
0N/A //
0N/A // Floating-point conversions applicable to float, double, and
0N/A // BigDecimal.
0N/A //---------------------------------------------------------------------
0N/A test("%g", "null", (Object)null);
0N/A test("%g", "3.14159", pi);
0N/A test(Locale.FRANCE, "%g", "3,14159", pi);
0N/A test("%.0g", "1e+01", ten);
0N/A test("%G", "3.14159", pi);
0N/A test("%10.3g", " 3.14", pi);
0N/A test("%10.3g", " -3.14", negate(pi));
0N/A test("%010.3g", "0000003.14", pi);
0N/A test("%010.3g", "-000003.14", negate(pi));
0N/A test("%-12.3g", "3.14 ", pi);
0N/A test("%-12.3g", "-3.14 ", negate(pi));
0N/A test("%.3g", "3.14", pi);
0N/A test("%.3g", "-3.14", negate(pi));
0N/A test("%.3g", "3.14e+08", mult(pi, 100000000.0));
0N/A test("%.3g", "-3.14e+08", mult(pi, -100000000.0));
0N/A
0N/A test("%.3g", "1.00e-05", recip(create(100000.0)));
0N/A test("%.3g", "-1.00e-05", recip(create(-100000.0)));
0N/A test("%.0g", "-1e-05", recip(create(-100000.0)));
0N/A test("%.0g", "1e+05", create(100000.0));
0N/A test("%.3G", "1.00E-05", recip(create(100000.0)));
0N/A test("%.3G", "-1.00E-05", recip(create(-100000.0)));
0N/A
0N/A test("%3.0g", "1e-06", 0.000001);
0N/A test("%3.0g", "1e-05", 0.00001);
0N/A test("%3.0g", "1e-05", 0.0000099);
0N/A test("%3.1g", "1e-05", 0.0000099);
0N/A test("%3.2g", "9.9e-06", 0.0000099);
0N/A test("%3.0g", "0.0001", 0.0001);
0N/A test("%3.0g", "9e-05", 0.00009);
0N/A test("%3.0g", "0.0001", 0.000099);
0N/A test("%3.1g", "0.0001", 0.000099);
0N/A test("%3.2g", "9.9e-05", 0.000099);
0N/A test("%3.0g", "0.001", 0.001);
0N/A test("%3.0g", "0.001", 0.00099);
0N/A test("%3.1g", "0.001", 0.00099);
0N/A test("%3.2g", "0.00099", 0.00099);
0N/A test("%3.3g", "0.00100", 0.001);
0N/A test("%3.4g", "0.001000", 0.001);
0N/A test("%3.0g", "0.01", 0.01);
0N/A test("%3.0g", "0.1", 0.1);
0N/A test("%3.0g", "0.9", 0.9);
0N/A test("%3.1g", "0.9", 0.9);
0N/A test("%3.0g", " 1", 1.00);
0N/A test("%3.2g", " 10", 10.00);
0N/A test("%3.0g", "1e+01", 10.00);
0N/A test("%3.0g", "1e+02", 99.19);
0N/A test("%3.1g", "1e+02", 99.19);
0N/A test("%3.2g", " 99", 99.19);
0N/A test("%3.0g", "1e+02", 99.9);
0N/A test("%3.1g", "1e+02", 99.9);
0N/A test("%3.2g", "1.0e+02", 99.9);
0N/A test("%3.0g", "1e+02", 99.99);
0N/A test("%3.0g", "1e+02", 100.00);
0N/A test("%3.0g", "1e+03", 999.9);
0N/A test("%3.1g", "1e+03", 999.9);
0N/A test("%3.2g", "1.0e+03", 999.9);
0N/A test("%3.3g", "1.00e+03", 999.9);
0N/A test("%3.4g", "999.9", 999.9);
0N/A test("%3.4g", "1000", 999.99);
0N/A test("%3.0g", "1e+03", 1000.00);
0N/A test("%3.0g", "1e+04", 10000.00);
0N/A test("%3.0g", "1e+05", 100000.00);
0N/A test("%3.0g", "1e+06", 1000000.00);
0N/A test("%3.0g", "1e+07", 10000000.00);
0N/A test("%3.9g", "100000000", 100000000.00);
0N/A test("%3.10g", "100000000.0", 100000000.00);
0N/A
0N/A tryCatch("%#3.0g", FormatFlagsConversionMismatchException.class, 1000.00);
0N/A
0N/A // double PI^300
0N/A // = 13962455701329742638131355433930076081862072808 ... e+149
0N/A#if[BigDecimal]
0N/A //---------------------------------------------------------------------
0N/A // %g - BigDecimal
0N/A //---------------------------------------------------------------------
0N/A test("%.3g", "1.40e+149", piToThe300);
0N/A test("%.3g", "-1.40e+149", piToThe300.negate());
0N/A test(Locale.FRANCE, "%.3g", "-1,40e+149", piToThe300.negate());
0N/A test("%.3g", "1.00e-100", recip(ten.pow(100)));
0N/A test("%.3g", "-1.00e-100", negate(recip(ten.pow(100))));
0N/A
0N/A test("%3.0g", "1e-06", new BigDecimal("0.000001"));
0N/A test("%3.0g", "1e-05", new BigDecimal("0.00001"));
0N/A test("%3.0g", "0.0001", new BigDecimal("0.0001"));
0N/A test("%3.0g", "0.001", new BigDecimal("0.001"));
0N/A test("%3.3g", "0.00100", new BigDecimal("0.001"));
0N/A test("%3.4g", "0.001000", new BigDecimal("0.001"));
0N/A test("%3.0g", "0.01", new BigDecimal("0.01"));
0N/A test("%3.0g", "0.1", new BigDecimal("0.1"));
0N/A test("%3.0g", "0.9", new BigDecimal("0.9"));
0N/A test("%3.1g", "0.9", new BigDecimal("0.9"));
0N/A test("%3.0g", " 1", new BigDecimal("1.00"));
0N/A test("%3.2g", " 10", new BigDecimal("10.00"));
0N/A test("%3.0g", "1e+01", new BigDecimal("10.00"));
0N/A test("%3.0g", "1e+02", new BigDecimal("99.19"));
0N/A test("%3.1g", "1e+02", new BigDecimal("99.19"));
0N/A test("%3.2g", " 99", new BigDecimal("99.19"));
0N/A test("%3.0g", "1e+02", new BigDecimal("99.99"));
0N/A test("%3.0g", "1e+02", new BigDecimal("100.00"));
0N/A test("%3.0g", "1e+03", new BigDecimal("1000.00"));
0N/A test("%3.0g", "1e+04", new BigDecimal("10000.00"));
0N/A test("%3.0g", "1e+05", new BigDecimal("100000.00"));
0N/A test("%3.0g", "1e+06", new BigDecimal("1000000.00"));
0N/A test("%3.0g", "1e+07", new BigDecimal("10000000.00"));
0N/A test("%3.9g", "100000000", new BigDecimal("100000000.00"));
0N/A test("%3.10g", "100000000.0", new BigDecimal("100000000.00"));
0N/A#end[BigDecimal]
0N/A
0N/A test("%.3g", "10.0", ten);
0N/A test("%.3g", "1.00", one);
0N/A test("%10.3g", " 1.00", one);
0N/A test("%+10.3g", " +3.14", pi);
0N/A test("%+10.3g", " -3.14", negate(pi));
0N/A test("% .3g", " 3.14", pi);
0N/A test("% .3g", "-3.14", negate(pi));
0N/A test("%.0g", "3", create(3.0));
0N/A test("%.0g", "-3", create(-3.0));
0N/A
0N/A test("%(.4g", "3.142e+08", mult(pi, 100000000.0));
0N/A test("%(.4g", "(3.142e+08)", mult(pi, -100000000.0));
0N/A
0N/A#if[float]
0N/A // Float can not accurately store 1e6 * PI.
0N/A test("%,.6g", "3,141.59", mult(pi, 1000.0));
0N/A test("%(,.6g", "(3,141.59)", mult(pi, -1000.0));
0N/A#else[float]
0N/A#if[!Float]
0N/A test("%,.11g", "3,141,592.6536", mult(pi, 1000000.0));
0N/A test("%(,.11g", "(3,141,592.6536)", mult(pi, -1000000.0));
0N/A#end[!Float]
0N/A#end[float]
0N/A
0N/A#if[double]
0N/A //---------------------------------------------------------------------
0N/A // %a
0N/A //
0N/A // Floating-point conversions applicable to float, double, and
0N/A // BigDecimal.
0N/A //---------------------------------------------------------------------
0N/A test("%a", "null", (Object)null);
0N/A test("%.11a", "0x0.00000000000p0", 0.0);
0N/A test(Locale.FRANCE, "%.11a", "0x0.00000000000p0", 0.0); // no localization
0N/A test("%.1a", "0x0.0p0", 0.0);
0N/A test("%.11a", "-0x0.00000000000p0", -0.0);
0N/A test("%.1a", "-0x0.0p0", -0.0);
0N/A test("%.11a", "0x1.00000000000p0", 1.0);
0N/A test("%.1a", "0x1.0p0", 1.0);
0N/A test("%.11a", "-0x1.00000000000p0", -1.0);
0N/A test("%.1a", "-0x1.0p0", -1.0);
0N/A test("%.11a", "0x1.80000000000p1", 3.0);
0N/A test("%.1a", "0x1.8p1", 3.0);
0N/A test("%.11a", "0x1.00000000000p-1022", DoubleConsts.MIN_NORMAL);
0N/A test("%.1a", "0x1.0p-1022", DoubleConsts.MIN_NORMAL);
0N/A test("%.11a", "0x1.00000000000p-1022",
0N/A FpUtils.nextDown(DoubleConsts.MIN_NORMAL));
0N/A test("%.1a", "0x1.0p-1022",
0N/A FpUtils.nextDown(DoubleConsts.MIN_NORMAL));
0N/A test("%.11a", "0x1.ffffffffffep-1023",
0N/A Double.parseDouble("0x0.fffffffffffp-1022"));
0N/A test("%.1a", "0x1.0p-1022",
0N/A Double.parseDouble("0x0.fffffffffffp-1022"));
0N/A test("%.30a", "0x0.000000000000100000000000000000p-1022", Double.MIN_VALUE);
0N/A test("%.13a", "0x0.0000000000001p-1022", Double.MIN_VALUE);
0N/A test("%.11a", "0x1.00000000000p-1074", Double.MIN_VALUE);
0N/A test("%.1a", "0x1.0p-1074", Double.MIN_VALUE);
0N/A
0N/A test("%.11a", "0x1.08000000000p-1069",
0N/A Double.MIN_VALUE + Double.MIN_VALUE*32);
0N/A test("%.1a", "0x1.0p-1069",
0N/A Double.MIN_VALUE + Double.MIN_VALUE*32);
0N/A test("%.30a", "0x1.fffffffffffff00000000000000000p1023", Double.MAX_VALUE);
0N/A test("%.13a", "0x1.fffffffffffffp1023", Double.MAX_VALUE);
0N/A test("%.11a", "0x1.00000000000p1024", Double.MAX_VALUE);
0N/A test("%.1a", "0x1.0p1024", Double.MAX_VALUE);
0N/A test("%.11a", "0x1.18000000000p0", Double.parseDouble("0x1.18p0"));
0N/A test("%.1a", "0x1.2p0", Double.parseDouble("0x1.18p0"));
0N/A
0N/A test("%.11a", "0x1.18000000000p0",
0N/A Double.parseDouble("0x1.180000000001p0"));
0N/A test("%.1a", "0x1.2p0",
0N/A Double.parseDouble("0x1.180000000001p0"));
0N/A test("%.11a", "0x1.28000000000p0", Double.parseDouble("0x1.28p0"));
0N/A test("%.1a", "0x1.2p0", Double.parseDouble("0x1.28p0"));
0N/A
0N/A test("%.11a", "0x1.28000000000p0",
0N/A Double.parseDouble("0x1.280000000001p0"));
0N/A test("%.1a", "0x1.3p0", Double.parseDouble("0x1.280000000001p0"));
0N/A#end[double]
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %f, %e, %g, %a - Boundaries
0N/A //---------------------------------------------------------------------
0N/A#if[float]
0N/A //---------------------------------------------------------------------
0N/A // %f, %e, %g, %a - NaN
0N/A //---------------------------------------------------------------------
0N/A test("%f", "NaN", Float.NaN);
0N/A // s
0N/A test("%+f", "NaN", Float.NaN);
0N/A// test("%F", "NAN", Float.NaN);
0N/A test("%e", "NaN", Float.NaN);
0N/A test("%+e", "NaN", Float.NaN);
0N/A test("%E", "NAN", Float.NaN);
0N/A test("%g", "NaN", Float.NaN);
0N/A test("%+g", "NaN", Float.NaN);
0N/A test("%G", "NAN", Float.NaN);
0N/A test("%a", "NaN", Float.NaN);
0N/A test("%+a", "NaN", Float.NaN);
0N/A test("%A", "NAN", Float.NaN);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %f, %e, %g, %a - +0.0
0N/A //---------------------------------------------------------------------
0N/A test("%f", "0.000000", +0.0);
0N/A test("%+f", "+0.000000", +0.0);
0N/A test("% f", " 0.000000", +0.0);
0N/A// test("%F", "0.000000", +0.0);
0N/A test("%e", "0.000000e+00", 0e0);
0N/A test("%e", "0.000000e+00", +0.0);
0N/A test("%+e", "+0.000000e+00", +0.0);
0N/A test("% e", " 0.000000e+00", +0.0);
0N/A test("%E", "0.000000E+00", 0e0);
0N/A test("%E", "0.000000E+00", +0.0);
0N/A test("%+E", "+0.000000E+00", +0.0);
0N/A test("% E", " 0.000000E+00", +0.0);
0N/A test("%g", "0.00000", +0.0);
0N/A test("%+g", "+0.00000", +0.0);
0N/A test("% g", " 0.00000", +0.0);
0N/A test("%G", "0.00000", +0.0);
0N/A test("% G", " 0.00000", +0.0);
0N/A test("%a", "0x0.0p0", +0.0);
0N/A test("%+a", "+0x0.0p0", +0.0);
0N/A test("% a", " 0x0.0p0", +0.0);
0N/A test("%A", "0X0.0P0", +0.0);
0N/A test("% A", " 0X0.0P0", +0.0);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %f, %e, %g, %a - -0.0
0N/A //---------------------------------------------------------------------
0N/A test("%f", "-0.000000", -0.0);
0N/A test("%+f", "-0.000000", -0.0);
0N/A// test("%F", "-0.000000", -0.0);
0N/A test("%e", "-0.000000e+00", -0.0);
0N/A test("%+e", "-0.000000e+00", -0.0);
0N/A test("%E", "-0.000000E+00", -0.0);
0N/A test("%+E", "-0.000000E+00", -0.0);
0N/A test("%g", "-0.00000", -0.0);
0N/A test("%+g", "-0.00000", -0.0);
0N/A test("%G", "-0.00000", -0.0);
0N/A test("%a", "-0x0.0p0", -0.0);
0N/A test("%+a", "-0x0.0p0", -0.0);
0N/A test("%+A", "-0X0.0P0", -0.0);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %f, %e, %g, %a - +Infinity
0N/A //---------------------------------------------------------------------
0N/A test("%f", "Infinity", Float.POSITIVE_INFINITY);
0N/A test("%+f", "+Infinity", Float.POSITIVE_INFINITY);
0N/A test("% f", " Infinity", Float.POSITIVE_INFINITY);
0N/A// test("%F", "INFINITY", Float.POSITIVE_INFINITY);
0N/A test("%e", "Infinity", Float.POSITIVE_INFINITY);
0N/A test("%+e", "+Infinity", Float.POSITIVE_INFINITY);
0N/A test("% e", " Infinity", Float.POSITIVE_INFINITY);
0N/A test("%E", "INFINITY", Float.POSITIVE_INFINITY);
0N/A test("%+E", "+INFINITY", Float.POSITIVE_INFINITY);
0N/A test("% E", " INFINITY", Float.POSITIVE_INFINITY);
0N/A test("%g", "Infinity", Float.POSITIVE_INFINITY);
0N/A test("%+g", "+Infinity", Float.POSITIVE_INFINITY);
0N/A test("%G", "INFINITY", Float.POSITIVE_INFINITY);
0N/A test("% G", " INFINITY", Float.POSITIVE_INFINITY);
0N/A test("%+G", "+INFINITY", Float.POSITIVE_INFINITY);
0N/A test("%a", "Infinity", Float.POSITIVE_INFINITY);
0N/A test("%+a", "+Infinity", Float.POSITIVE_INFINITY);
0N/A test("% a", " Infinity", Float.POSITIVE_INFINITY);
0N/A test("%A", "INFINITY", Float.POSITIVE_INFINITY);
0N/A test("%+A", "+INFINITY", Float.POSITIVE_INFINITY);
0N/A test("% A", " INFINITY", Float.POSITIVE_INFINITY);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %f, %e, %g, %a - -Infinity
0N/A //---------------------------------------------------------------------
0N/A test("%f", "-Infinity", Float.NEGATIVE_INFINITY);
0N/A test("%+f", "-Infinity", Float.NEGATIVE_INFINITY);
0N/A test("%(f", "(Infinity)", Float.NEGATIVE_INFINITY);
0N/A// test("%F", "-INFINITY", Float.NEGATIVE_INFINITY);
0N/A test("%e", "-Infinity", Float.NEGATIVE_INFINITY);
0N/A test("%+e", "-Infinity", Float.NEGATIVE_INFINITY);
0N/A test("%E", "-INFINITY", Float.NEGATIVE_INFINITY);
0N/A test("%+E", "-INFINITY", Float.NEGATIVE_INFINITY);
0N/A test("%g", "-Infinity", Float.NEGATIVE_INFINITY);
0N/A test("%+g", "-Infinity", Float.NEGATIVE_INFINITY);
0N/A test("%G", "-INFINITY", Float.NEGATIVE_INFINITY);
0N/A test("%+G", "-INFINITY", Float.NEGATIVE_INFINITY);
0N/A test("%a", "-Infinity", Float.NEGATIVE_INFINITY);
0N/A test("%+a", "-Infinity", Float.NEGATIVE_INFINITY);
0N/A test("%A", "-INFINITY", Float.NEGATIVE_INFINITY);
0N/A test("%+A", "-INFINITY", Float.NEGATIVE_INFINITY);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %f, %e, %g, %a - Float.MIN_VALUE
0N/A //---------------------------------------------------------------------
0N/A test("%f", "0.000000", Float.MIN_VALUE);
0N/A test("%,f", "0.000000", Float.MIN_VALUE);
0N/A test("%(f", "(0.000000)", -Float.MIN_VALUE);
0N/A test("%30.0f", " 0", Float.MIN_VALUE);
0N/A test("%30.5f", " 0.00000", Float.MIN_VALUE);
0N/A test("%30.13f", " 0.0000000000000", Float.MIN_VALUE);
0N/A test("%30.20f", " 0.00000000000000000000", Float.MIN_VALUE);
0N/A test("%e", "1.401298e-45", Float.MIN_VALUE);
0N/A test("%E", "1.401298E-45", Float.MIN_VALUE);
0N/A test("%(.1e", "1.4e-45", Float.MIN_VALUE);
0N/A test("%(E", "(1.401298E-45)", -Float.MIN_VALUE);
0N/A test("%30.5e", " 1.40130e-45", Float.MIN_VALUE);
0N/A test("%30.13e", " 1.4012984643248e-45", Float.MIN_VALUE);
0N/A test("%30.20e", " 1.40129846432481700000e-45", Float.MIN_VALUE);
0N/A test("%g", "1.40130e-45", Float.MIN_VALUE);
0N/A test("%G", "1.40130E-45", Float.MIN_VALUE);
0N/A test("%(g", "1.40130e-45", Float.MIN_VALUE);
0N/A test("%,g", "1.40130e-45", Float.MIN_VALUE);
0N/A test("%(G", "(1.40130E-45)", -Float.MIN_VALUE);
0N/A test("%30.5g", " 1.4013e-45", Float.MIN_VALUE);
0N/A test("%30.13g", " 1.401298464325e-45", Float.MIN_VALUE);
0N/A test("%30.20g", " 1.4012984643248170000e-45", Float.MIN_VALUE);
0N/A test("%a", "0x1.0p-149", Float.MIN_VALUE);
0N/A test("%A", "0X1.0P-149", Float.MIN_VALUE);
0N/A test("%20a", " 0x1.0p-149", Float.MIN_VALUE);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %f, %e, %g, %a - Float.MAX_VALUE
0N/A //---------------------------------------------------------------------
0N/A test("%f", "340282346638528860000000000000000000000.000000", Float.MAX_VALUE);
0N/A test("%,f","340,282,346,638,528,860,000,000,000,000,000,000,000.000000",
0N/A Float.MAX_VALUE);
0N/A test("%(f", "(340282346638528860000000000000000000000.000000)", -Float.MAX_VALUE);
0N/A test("%60.5f", " 340282346638528860000000000000000000000.00000",
0N/A Float.MAX_VALUE);
0N/A test("%60.13f", " 340282346638528860000000000000000000000.0000000000000",
0N/A Float.MAX_VALUE);
0N/A test("%61.20f", " 340282346638528860000000000000000000000.00000000000000000000",
0N/A Float.MAX_VALUE);
0N/A test("%e", "3.402823e+38", Float.MAX_VALUE);
0N/A test("%E", "3.402823E+38", Float.MAX_VALUE);
0N/A test("%(e", "3.402823e+38", Float.MAX_VALUE);
0N/A test("%(e", "(3.402823e+38)", -Float.MAX_VALUE);
0N/A test("%30.5e", " 3.40282e+38", Float.MAX_VALUE);
0N/A test("%30.13e", " 3.4028234663853e+38", Float.MAX_VALUE);
0N/A test("%30.20e", " 3.40282346638528860000e+38", Float.MAX_VALUE);
0N/A test("%g", "3.40282e+38", Float.MAX_VALUE);
0N/A test("%G", "3.40282E+38", Float.MAX_VALUE);
0N/A test("%,g", "3.40282e+38", Float.MAX_VALUE);
0N/A test("%(g", "(3.40282e+38)", -Float.MAX_VALUE);
0N/A test("%30.5g", " 3.4028e+38", Float.MAX_VALUE);
0N/A test("%30.13g", " 3.402823466385e+38", Float.MAX_VALUE);
0N/A test("%30.20G", " 3.4028234663852886000E+38", Float.MAX_VALUE);
0N/A test("%a", "0x1.fffffep127", Float.MAX_VALUE);
0N/A test("%A", "0X1.FFFFFEP127", Float.MAX_VALUE);
0N/A test("%20a"," 0x1.fffffep127", Float.MAX_VALUE);
0N/A
0N/A#end[float]
0N/A
0N/A#if[double]
0N/A //---------------------------------------------------------------------
0N/A // %f, %e, %g, %a - Double.MIN_VALUE
0N/A //---------------------------------------------------------------------
0N/A test("%f", "0.000000", Double.MIN_VALUE);
0N/A test("%,f", "0.000000", Double.MIN_VALUE);
0N/A test("%(f", "(0.000000)", -Double.MIN_VALUE);
0N/A test("%30.0f", " 0", Double.MIN_VALUE);
0N/A test("%30.5f", " 0.00000", Double.MIN_VALUE);
0N/A test("%30.13f", " 0.0000000000000", Double.MIN_VALUE);
0N/A test("%30.20f", " 0.00000000000000000000", Double.MIN_VALUE);
0N/A test("%30.350f","0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000490000000000000000000000000",
0N/A Double.MIN_VALUE);
0N/A test("%e", "4.900000e-324", Double.MIN_VALUE);
0N/A test("%E", "4.900000E-324", Double.MIN_VALUE);
0N/A test("%(.1e", "4.9e-324", Double.MIN_VALUE);
0N/A test("%(E", "(4.900000E-324)", -Double.MIN_VALUE);
0N/A test("%30.5e", " 4.90000e-324", Double.MIN_VALUE);
0N/A test("%30.13e", " 4.9000000000000e-324", Double.MIN_VALUE);
0N/A test("%30.20e", " 4.90000000000000000000e-324", Double.MIN_VALUE);
0N/A test("%g", "4.90000e-324", Double.MIN_VALUE);
0N/A test("%G", "4.90000E-324", Double.MIN_VALUE);
0N/A test("%(g", "4.90000e-324", Double.MIN_VALUE);
0N/A test("%,g", "4.90000e-324", Double.MIN_VALUE);
0N/A test("%30.5g", " 4.9000e-324", Double.MIN_VALUE);
0N/A test("%30.13g", " 4.900000000000e-324", Double.MIN_VALUE);
0N/A test("%30.20g", " 4.9000000000000000000e-324", Double.MIN_VALUE);
0N/A test("%a", "0x0.0000000000001p-1022", Double.MIN_VALUE);
0N/A test("%A", "0X0.0000000000001P-1022", Double.MIN_VALUE);
0N/A test("%30a", " 0x0.0000000000001p-1022", Double.MIN_VALUE);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %f, %e, %g, %a - Double.MAX_VALUE
0N/A //---------------------------------------------------------------------
0N/A test("%f", "179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000",
0N/A Double.MAX_VALUE);
0N/A test("%,f", "179,769,313,486,231,570,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000.000000",
0N/A Double.MAX_VALUE);
0N/A test("%,(f", "(179,769,313,486,231,570,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000.000000)",
0N/A -Double.MAX_VALUE);
0N/A test("%,30.5f", "179,769,313,486,231,570,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000.00000",
0N/A Double.MAX_VALUE);
0N/A test("%30.13f", "179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0000000000000",
0N/A Double.MAX_VALUE);
0N/A test("%30.20f", "179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.00000000000000000000",
0N/A Double.MAX_VALUE);
0N/A test("%e", "1.797693e+308", Double.MAX_VALUE);
0N/A test("%E", "1.797693E+308", Double.MAX_VALUE);
0N/A test("%(e", "1.797693e+308", Double.MAX_VALUE);
0N/A test("%(e", "(1.797693e+308)", -Double.MAX_VALUE);
0N/A test("%30.5e", " 1.79769e+308", Double.MAX_VALUE);
0N/A test("%30.13e", " 1.7976931348623e+308", Double.MAX_VALUE);
0N/A test("%30.20e", " 1.79769313486231570000e+308", Double.MAX_VALUE);
0N/A test("%g", "1.79769e+308", Double.MAX_VALUE);
0N/A test("%G", "1.79769E+308", Double.MAX_VALUE);
0N/A test("%,g", "1.79769e+308", Double.MAX_VALUE);
0N/A test("%(g", "(1.79769e+308)", -Double.MAX_VALUE);
0N/A test("%30.5g", " 1.7977e+308", Double.MAX_VALUE);
0N/A test("%30.13g", " 1.797693134862e+308", Double.MAX_VALUE);
0N/A test("%30.20g", " 1.7976931348623157000e+308", Double.MAX_VALUE);
0N/A test("%a", "0x1.fffffffffffffp1023", Double.MAX_VALUE);
0N/A test("%A", "0X1.FFFFFFFFFFFFFP1023", Double.MAX_VALUE);
0N/A test("%30a", " 0x1.fffffffffffffp1023", Double.MAX_VALUE);
0N/A#end[double]
0N/A
0N/A#end[fp]
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %t
0N/A //
0N/A // Date/Time conversions applicable to Calendar, Date, and long.
0N/A //---------------------------------------------------------------------
0N/A test("%tA", "null", (Object)null);
0N/A test("%TA", "NULL", (Object)null);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %t - errors
0N/A //---------------------------------------------------------------------
0N/A tryCatch("%t", UnknownFormatConversionException.class);
0N/A tryCatch("%T", UnknownFormatConversionException.class);
0N/A tryCatch("%tP", UnknownFormatConversionException.class);
0N/A tryCatch("%TP", UnknownFormatConversionException.class);
0N/A tryCatch("%.5tB", IllegalFormatPrecisionException.class);
0N/A tryCatch("%#tB", FormatFlagsConversionMismatchException.class);
0N/A tryCatch("%-tB", MissingFormatWidthException.class);
0N/A
0N/A#if[datetime]
0N/A //---------------------------------------------------------------------
0N/A // %t - create test Calendar
0N/A //---------------------------------------------------------------------
0N/A
0N/A // Get the supported ids for GMT-08:00 (Pacific Standard Time)
0N/A String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
0N/A // Create a Pacific Standard Time time zone
0N/A SimpleTimeZone tz = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);
0N/A // public GregorianCalendar(TimeZone zone, Locale aLocale);
0N/A Calendar c0 = new GregorianCalendar(tz, Locale.US);
0N/A // public final void set(int year, int month, int date,
0N/A // int hourOfDay, int minute, int second);
0N/A c0.set(1995, MAY, 23, 19, 48, 34);
0N/A c0.set(Calendar.MILLISECOND, 584);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %t - Minutes, {nano,milli}*seconds
0N/A //
0N/A // testDateTime() verifies the expected output for all applicable types
0N/A // (Calendar, Date, and long). It also verifies output for "%t" and
0N/A // "%T". Thus it is sufficient to invoke that method once per
0N/A // conversion/expected output.
0N/A //---------------------------------------------------------------------
0N/A testDateTime("%tM", "48", c0);
0N/A testDateTime("%tN", "584000000", c0);
0N/A testDateTime("%tL", "584", c0);
0N/A// testDateTime("%tQ", "801283714584", c0);
0N/A
0N/A testDateTime("%ts", String.valueOf(c0.getTimeInMillis() / 1000), c0);
0N/A testDateTime("%tS", "34", c0);
0N/A testDateTime("%tT", "19:48:34", c0);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %t - Hours, morning/afternoon markers
0N/A //
0N/A // testHours() iterates through all twenty-four hours to verify
0N/A // numeric return value and morning/afternoon markers.
0N/A //---------------------------------------------------------------------
0N/A testHours();
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %t - Portions of date [ day, month, dates, weeks ]
0N/A //---------------------------------------------------------------------
0N/A testDateTime("%ta", "Tue", c0);
0N/A testDateTime("%tA", "Tuesday", c0);
0N/A testDateTime("%tb", "May", c0);
0N/A testDateTime("%tB", "May", c0);
0N/A testDateTime("%tC", "19", c0);
0N/A testDateTime("%td", "23", c0);
0N/A testDateTime("%te", "23", c0);
0N/A testDateTime("%th", "May", c0);
0N/A testDateTime("%tj", "143", c0);
0N/A testDateTime("%tm", "05", c0);
0N/A testDateTime("%ty", "95", c0);
0N/A testDateTime("%tY", "1995", c0);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %t - TimeZone
0N/A //---------------------------------------------------------------------
0N/A testDateTime("%tz", "-0800", c0);
0N/A testDateTime("%tZ", "PST", c0);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %tz should always adjust for DST
0N/A //---------------------------------------------------------------------
0N/A TimeZone dtz = TimeZone.getDefault();
0N/A
0N/A // Artificial TimeZone based on PST with 3:15 DST always in effect
0N/A TimeZone atz = new SimpleTimeZone(-8 * 60 * 60 * 1000, "AlwaysDST",
0N/A JANUARY, 1, 0, 0, STANDARD_TIME,
0N/A // 24hrs - 1m = 60 * 60 * 1000 * 24 - 1
0N/A DECEMBER, 31, 0, 60 * 60 * 1000 * 24 - 1, STANDARD_TIME,
0N/A (int)(60 * 60 * 1000 * 3.25));
0N/A TimeZone.setDefault(atz);
0N/A testDateTime("%tz", "-0445", Calendar.getInstance(atz));
0N/A
0N/A // Restore the TimeZone and verify
0N/A TimeZone.setDefault(dtz);
0N/A if (atz.hasSameRules(TimeZone.getDefault()))
0N/A throw new RuntimeException("Default TimeZone not restored");
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %t - Composites
0N/A //---------------------------------------------------------------------
0N/A testDateTime("%tr", "07:48:34 PM", c0);
0N/A testDateTime("%tR", "19:48", c0);
0N/A testDateTime("%tc", "Tue May 23 19:48:34 PST 1995", c0);
0N/A testDateTime("%tD", "05/23/95", c0);
0N/A testDateTime("%tF", "1995-05-23", c0);
0N/A testDateTime("%-12tF", "1995-05-23 ", c0);
0N/A testDateTime("%12tF", " 1995-05-23", c0);
0N/A#end[datetime]
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %n
0N/A //---------------------------------------------------------------------
0N/A test("%n", System.getProperty("line.separator"), (Object)null);
0N/A test("%n", System.getProperty("line.separator"), "");
0N/A
0N/A tryCatch("%,n", IllegalFormatFlagsException.class);
0N/A tryCatch("%.n", UnknownFormatConversionException.class);
0N/A tryCatch("%5.n", UnknownFormatConversionException.class);
0N/A tryCatch("%5n", IllegalFormatWidthException.class);
0N/A tryCatch("%.7n", IllegalFormatPrecisionException.class);
0N/A tryCatch("%<n", IllegalFormatFlagsException.class);
0N/A
0N/A //---------------------------------------------------------------------
0N/A // %%
0N/A //---------------------------------------------------------------------
0N/A test("%%", "%", (Object)null);
0N/A test("%%", "%", "");
0N/A tryCatch("%%%", UnknownFormatConversionException.class);
0N/A // perhaps an IllegalFormatArgumentIndexException should be defined?
0N/A tryCatch("%<%", IllegalFormatFlagsException.class);
0N/A }
0N/A}