1 /*
   2  * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* Type-specific source code for unit test
  25  *
  26  * Regenerate the BasicX classes via genBasic.sh whenever this file changes.
  27  * We check in the generated source files so that the test tree can be used
  28  * independently of the rest of the source tree.
  29  */
  30 
  31 #warn This file is preprocessed before being compiled
  32 
  33 import java.io.*;
  34 import java.math.BigDecimal;
  35 import java.math.BigInteger;
  36 import java.text.DateFormatSymbols;
  37 import java.util.*;
  38 
  39 import static java.util.Calendar.*;
  40 #if[datetime]
  41 import static java.util.SimpleTimeZone.*;
  42 import java.util.regex.Pattern;
  43 #end[datetime]
  44 
  45 public class Basic$Type$ extends Basic {
  46 
  47     private static void test(String fs, String exp, Object ... args) {
  48         Formatter f = new Formatter(new StringBuilder(), Locale.US);
  49         f.format(fs, args);
  50         ck(fs, exp, f.toString());
  51 
  52         f = new Formatter(new StringBuilder(), Locale.US);
  53         f.format("foo " + fs + " bar", args);
  54         ck(fs, "foo " + exp + " bar", f.toString());
  55 
  56         JavacIntrinsicsSupport.formatAndCheck(fs, exp, Locale.US, args);
  57         JavacIntrinsicsSupport.formatAndCheck("foo " + fs + " bar", "foo " + exp + " bar", Locale.US, args);
  58     }
  59 
  60     private static void test(Locale l, String fs, String exp, Object ... args)
  61     {
  62         Formatter f = new Formatter(new StringBuilder(), l);
  63         f.format(fs, args);
  64         ck(fs, exp, f.toString());
  65 
  66         f = new Formatter(new StringBuilder(), l);
  67         f.format("foo " + fs + " bar", args);
  68         ck(fs, "foo " + exp + " bar", f.toString());
  69 
  70         JavacIntrinsicsSupport.formatAndCheck(fs, exp, l, args);
  71         JavacIntrinsicsSupport.formatAndCheck("foo " + fs + " bar", "foo " + exp + " bar", l, args);
  72     }
  73 
  74     private static void test(String fs, Object ... args) {
  75         Formatter f = new Formatter(new StringBuilder(), Locale.US);
  76         f.format(fs, args);
  77         ck(fs, "fail", f.toString());
  78     }
  79 
  80     private static void test(String fs) {
  81         Formatter f = new Formatter(new StringBuilder(), Locale.US);
  82         f.format(fs, "fail");
  83         ck(fs, "fail", f.toString());
  84     }
  85 
  86     private static void testSysOut(String fs, String exp, Object ... args) {
  87         FileOutputStream fos = null;
  88         FileInputStream fis = null;
  89         try {
  90             PrintStream saveOut = System.out;
  91             fos = new FileOutputStream("testSysOut");
  92             System.setOut(new PrintStream(fos));
  93             System.out.format(Locale.US, fs, args);
  94             fos.close();
  95 
  96             fis = new FileInputStream("testSysOut");
  97             byte [] ba = new byte[exp.length()];
  98             int len = fis.read(ba);
  99             String got = new String(ba);
 100             if (len != ba.length)
 101                 fail(fs, exp, got);
 102             ck(fs, exp, got);
 103 
 104             System.setOut(saveOut);
 105         } catch (FileNotFoundException ex) {
 106             fail(fs, ex.getClass());
 107         } catch (IOException ex) {
 108             fail(fs, ex.getClass());
 109         } finally {
 110             try {
 111                 if (fos != null)
 112                     fos.close();
 113                 if (fis != null)
 114                     fis.close();
 115             } catch (IOException ex) {
 116                 fail(fs, ex.getClass());
 117             }
 118         }
 119     }
 120 
 121     private static void tryCatch(String fs, Class<?> ex) {
 122         boolean caught = false;
 123         try {
 124             test(fs);
 125         } catch (Throwable x) {
 126             if (ex.isAssignableFrom(x.getClass()))
 127                 caught = true;
 128         }
 129         if (!caught)
 130             fail(fs, ex);
 131         else
 132             pass();
 133 
 134         tryCatchIntrinsic(fs, ex);
 135     }
 136 
 137     private static void tryCatch(String fs, Class<?> ex, Object ... args) {
 138         boolean caught = false;
 139         try {
 140             test(fs, args);
 141         } catch (Throwable x) {
 142             if (ex.isAssignableFrom(x.getClass()))
 143                 caught = true;
 144         }
 145         if (!caught)
 146             fail(fs, ex);
 147         else
 148             pass();
 149 
 150         tryCatchIntrinsic(fs, ex, args);
 151     }
 152 
 153     private static void tryCatchIntrinsic(String fs, Class<?> ex) {
 154         boolean caught = false;
 155         try {
 156             JavacIntrinsicsSupport.formatAndCheck(fs, "fail", Locale.US, "fail");
 157         } catch (Throwable x) {
 158             if (ex.isAssignableFrom(x.getClass()))
 159                 caught = true;
 160         }
 161         if (!caught)
 162             fail(fs, ex);
 163         else
 164             pass();
 165     }
 166 
 167     private static void tryCatchIntrinsic(String fs, Class<?> ex, Object ... args) {
 168         boolean caught = false;
 169         try {
 170             JavacIntrinsicsSupport.formatAndCheck(fs, "fail", Locale.US, args);
 171         } catch (Throwable x) {
 172             if (ex.isAssignableFrom(x.getClass()))
 173                 caught = true;
 174         }
 175         if (!caught)
 176             fail(fs, ex);
 177         else
 178             pass();
 179     }
 180 
 181 #if[datetime]
 182     private static void testDateTime(String fs, String exp, Calendar c) {
 183         testDateTime(fs, exp, c, true);
 184     }
 185 
 186     private static void testDateTime(String fs, String exp, Calendar c, boolean upper) {
 187         //---------------------------------------------------------------------
 188         // Date/Time conversions applicable to Calendar, Date, and long.
 189         //---------------------------------------------------------------------
 190 
 191         // Calendar
 192         test(fs, exp, c);
 193         test((Locale)null, fs, exp, c);
 194         test(Locale.US, fs, exp, c);
 195 
 196         // Date/long do not have timezone information so they will always use
 197         // the default timezone.
 198         String nexp = (fs.equals("%tZ") || fs.equals("%TZ")
 199                        || fs.equals("%tc") || fs.equals("%Tc")
 200                        ? exp.replace("PST", "GMT-08:00")
 201                        : exp);
 202 
 203         // Date (implemented via conversion to Calendar)
 204         Date d = c.getTime();
 205         test(fs, nexp, d);
 206         test((Locale)null, fs, nexp, d);
 207         test(Locale.US, fs, nexp, d);
 208 
 209         // long (implemented via conversion to Calendar)
 210         long l = c.getTimeInMillis();
 211         test(fs, nexp, l);
 212         test((Locale)null, fs, nexp, l);
 213         test(Locale.US, fs, nexp, l);
 214 
 215         if (upper)
 216             // repeat all tests for upper case variant (%T)
 217             testDateTime(Pattern.compile("t").matcher(fs).replaceFirst("T"),
 218                          exp.toUpperCase(), c, false);
 219     }
 220 
 221     private static void testHours() {
 222         for (int i = 0; i < 24; i++) {
 223             // GregorianCalendar(int year, int month, int dayOfMonth,
 224             //    int hourOfDay, int minute, int second);
 225             Calendar c = new GregorianCalendar(1995, MAY, 23, i, 48, 34);
 226 
 227             //-----------------------------------------------------------------
 228             // DateTime.HOUR_OF_DAY - 'k' (0 - 23) -- like H
 229             //-----------------------------------------------------------------
 230             String exp = Integer.toString(i);
 231             testDateTime("%tk", exp, c);
 232 
 233             //-----------------------------------------------------------------
 234             // DateTime.HOUR - 'l' (1 - 12) -- like I
 235             //-----------------------------------------------------------------
 236             int v = i % 12;
 237             v = (v == 0 ? 12 : v);
 238             String exp2 = Integer.toString(v);
 239             testDateTime("%tl", exp2, c);
 240 
 241             //-----------------------------------------------------------------
 242             // DateTime.HOUR_OF_DAY_0 - 'H' (00 - 23) [zero padded]
 243             //-----------------------------------------------------------------
 244             if (exp.length() < 2) exp = "0" + exp;
 245             testDateTime("%tH", exp, c);
 246 
 247             //-----------------------------------------------------------------
 248             // DateTime.HOUR_0 - 'I' (01 - 12)
 249             //-----------------------------------------------------------------
 250             if (exp2.length() < 2) exp2 = "0" + exp2;
 251             testDateTime("%tI", exp2, c);
 252 
 253             //-----------------------------------------------------------------
 254             // DateTime.AM_PM - (am or pm)
 255             //-----------------------------------------------------------------
 256             testDateTime("%tp", (i <12 ? "am" : "pm"), c);
 257         }
 258     }
 259 #end[datetime]
 260 
 261 #if[dec]
 262 #if[prim]
 263     private static $type$ negate($type$ v) {
 264         return ($type$) -v;
 265     }
 266 #end[prim]
 267 #end[dec]
 268 #if[Byte]
 269     private static $type$ negate($type$ v) {
 270         return new $type$((byte) -v.byteValue());
 271     }
 272 #end[Byte]
 273 #if[Short]
 274     private static $type$ negate($type$ v) {
 275         return new $type$((short) -v.shortValue());
 276     }
 277 #end[Short]
 278 #if[Integer]
 279     private static $type$ negate($type$ v) {
 280         return new $type$(-v.intValue());
 281     }
 282 #end[Integer]
 283 #if[Long]
 284     private static $type$ negate($type$ v) {
 285         return new $type$(-v.longValue());
 286     }
 287 #end[Long]
 288 
 289 #if[BigDecimal]
 290     private static $type$ create(double v) {
 291         return new $type$(v);
 292     }
 293 
 294     private static $type$ negate($type$ v) {
 295         return v.negate();
 296     }
 297 
 298     private static $type$ mult($type$ v, double mul) {
 299         return v.multiply(new $type$(mul));
 300     }
 301 
 302     private static $type$ recip($type$ v) {
 303         return BigDecimal.ONE.divide(v);
 304     }
 305 #end[BigDecimal]
 306 #if[float]
 307     private static $type$ create(double v) {
 308         return ($type$) v;
 309     }
 310 
 311     private static $type$ negate(double v) {
 312         return ($type$) -v;
 313     }
 314 
 315     private static $type$ mult($type$ v, double mul) {
 316         return v * ($type$) mul;
 317     }
 318 
 319     private static $type$ recip($type$ v) {
 320         return 1.0f / v;
 321     }
 322 #end[float]
 323 #if[Float]
 324     private static $type$ create(double v) {
 325         return new $type$(v);
 326     }
 327 
 328     private static $type$ negate($type$ v) {
 329         return new $type$(-v.floatValue());
 330     }
 331 
 332     private static $type$ mult($type$ v, double mul) {
 333         return new $type$(v.floatValue() * (float) mul);
 334     }
 335 
 336     private static $type$ recip($type$ v) {
 337         return new $type$(1.0f / v.floatValue());
 338     }
 339 #end[Float]
 340 #if[double]
 341     private static $type$ create(double v) {
 342         return ($type$) v;
 343     }
 344 
 345 
 346     private static $type$ negate(double v) {
 347         return -v;
 348     }
 349 
 350     private static $type$ mult($type$ v, double mul) {
 351         return v * mul;
 352     }
 353 
 354     private static $type$ recip($type$ v) {
 355         return 1.0 / v;
 356     }
 357 #end[double]
 358 #if[Double]
 359     private static $type$ create(double v) {
 360         return new $type$(v);
 361     }
 362 
 363     private static $type$ negate($type$ v) {
 364         return new $type$(-v.doubleValue());
 365     }
 366 
 367     private static $type$ mult($type$ v, double mul) {
 368         return new $type$(v.doubleValue() * mul);
 369     }
 370 
 371     private static $type$ recip($type$ v) {
 372         return new $type$(1.0 / v.doubleValue());
 373     }
 374 #end[Double]
 375 
 376     public static void test() {
 377         TimeZone.setDefault(TimeZone.getTimeZone("GMT-0800"));
 378 
 379         // Any characters not explicitly defined as conversions, date/time
 380         // conversion suffixes, or flags are illegal and are reserved for
 381         // future extensions.  Use of such a character in a format string will
 382         // cause an UnknownFormatConversionException or
 383         // UnknownFormatFlagsException to be thrown.
 384         tryCatch("%q", UnknownFormatConversionException.class);
 385         tryCatch("%t&", UnknownFormatConversionException.class);
 386         tryCatch("%&d", UnknownFormatConversionException.class);
 387         tryCatch("%^b", UnknownFormatConversionException.class);
 388 
 389         //---------------------------------------------------------------------
 390         // Formatter.java class javadoc examples
 391         //---------------------------------------------------------------------
 392         test(Locale.FRANCE, "e = %+10.4f", "e =    +2,7183", Math.E);
 393         test("%4$2s %3$2s %2$2s %1$2s", " d  c  b  a", "a", "b", "c", "d");
 394         test("Amount gained or lost since last statement: $ %,(.2f",
 395              "Amount gained or lost since last statement: $ (6,217.58)",
 396              (new BigDecimal("-6217.58")));
 397         Calendar c = new GregorianCalendar(1969, JULY, 20, 16, 17, 0);
 398         testSysOut("Local time: %tT", "Local time: 16:17:00", c);
 399 
 400         test("Unable to open file '%1$s': %2$s",
 401              "Unable to open file 'food': No such file or directory",
 402              "food", "No such file or directory");
 403         Calendar duke = new GregorianCalendar(1995, MAY, 23, 19, 48, 34);
 404         duke.set(Calendar.MILLISECOND, 584);
 405         test("Duke's Birthday: %1$tB %1$te, %1$tY",
 406              "Duke's Birthday: May 23, 1995",
 407              duke);
 408         test("Duke's Birthday: %1$tB %1$te, %1$tY",
 409              "Duke's Birthday: May 23, 1995",
 410              duke.getTime());
 411         test("Duke's Birthday: %1$tB %1$te, %1$tY",
 412              "Duke's Birthday: May 23, 1995",
 413              duke.getTimeInMillis());
 414 
 415         test("%4$s %3$s %2$s %1$s %4$s %3$s %2$s %1$s",
 416              "d c b a d c b a", "a", "b", "c", "d");
 417         test("%s %s %<s %<s", "a b b b", "a", "b", "c", "d");
 418         test("%s %s %s %s", "a b c d", "a", "b", "c", "d");
 419         test("%2$s %s %<s %s", "b a a b", "a", "b", "c", "d");
 420 
 421         //---------------------------------------------------------------------
 422         // %b
 423         //
 424         // General conversion applicable to any argument.
 425         //---------------------------------------------------------------------
 426         test("%b", "true", true);
 427         test("%b", "false", false);
 428         test("%B", "TRUE", true);
 429         test("%B", "FALSE", false);
 430         test("%b", "true", Boolean.TRUE);
 431         test("%b", "false", Boolean.FALSE);
 432         test("%B", "TRUE", Boolean.TRUE);
 433         test("%B", "FALSE", Boolean.FALSE);
 434         test("%14b", "          true", true);
 435         test("%-14b", "true          ", true);
 436         test("%5.1b", "    f", false);
 437         test("%-5.1b", "f    ", false);
 438 
 439         test("%b", "true", "foo");
 440         test("%b", "false", (Object)null);
 441 
 442         // Boolean.java hardcodes the Strings for "true" and "false", so no
 443         // localization is possible.
 444         test(Locale.FRANCE, "%b", "true", true);
 445         test(Locale.FRANCE, "%b", "false", false);
 446 
 447         // If you pass in a single array to a varargs method, the compiler
 448         // uses it as the array of arguments rather than treating it as a
 449         // single array-type argument.
 450         test("%b", "false", (Object[])new String[2]);
 451         test("%b", "true", new String[2], new String[2]);
 452 
 453         int [] ia = { 1, 2, 3 };
 454         test("%b", "true", ia);
 455 
 456         //---------------------------------------------------------------------
 457         // %b - errors
 458         //---------------------------------------------------------------------
 459         tryCatch("%#b", FormatFlagsConversionMismatchException.class);
 460         tryCatch("%-b", MissingFormatWidthException.class);
 461         // correct or side-effect of implementation?
 462         tryCatch("%.b", UnknownFormatConversionException.class);
 463         tryCatch("%,b", FormatFlagsConversionMismatchException.class);
 464 
 465         //---------------------------------------------------------------------
 466         // %c
 467         //
 468         // General conversion applicable to any argument.
 469         //---------------------------------------------------------------------
 470         test("%c", "i", 'i');
 471         test("%C", "I", 'i');
 472         test("%4c",  "   i", 'i');
 473         test("%-4c", "i   ", 'i');
 474         test("%4C",  "   I", 'i');
 475         test("%-4C", "I   ", 'i');
 476         test("%c", "i", new Character('i'));
 477         test("%c", "H", (byte) 72);
 478         test("%c", "i", (short) 105);
 479         test("%c", "!", (int) 33);
 480         test("%c", "\u007F", Byte.MAX_VALUE);
 481         test("%c", new String(Character.toChars(Short.MAX_VALUE)),
 482              Short.MAX_VALUE);
 483         test("%c", "null", (Object) null);
 484 
 485         //---------------------------------------------------------------------
 486         // %c - errors
 487         //---------------------------------------------------------------------
 488         tryCatch("%c", IllegalFormatConversionException.class,
 489                  Boolean.TRUE);
 490         tryCatch("%c", IllegalFormatConversionException.class,
 491                  (float) 0.1);
 492         tryCatch("%c", IllegalFormatConversionException.class,
 493                  new Object());
 494         tryCatch("%c", IllegalFormatCodePointException.class,
 495                  Byte.MIN_VALUE);
 496         tryCatch("%c", IllegalFormatCodePointException.class,
 497                  Short.MIN_VALUE);
 498         tryCatch("%c", IllegalFormatCodePointException.class,
 499                  Integer.MIN_VALUE);
 500         tryCatch("%c", IllegalFormatCodePointException.class,
 501                  Integer.MAX_VALUE);
 502 
 503         tryCatch("%#c", FormatFlagsConversionMismatchException.class);
 504         tryCatch("%,c", FormatFlagsConversionMismatchException.class);
 505         tryCatch("%(c", FormatFlagsConversionMismatchException.class);
 506         tryCatch("%$c", UnknownFormatConversionException.class);
 507         tryCatch("%.2c", IllegalFormatPrecisionException.class);
 508 
 509         //---------------------------------------------------------------------
 510         // %s
 511         //
 512         // General conversion applicable to any argument.
 513         //---------------------------------------------------------------------
 514         test("%s", "Hello, Duke", "Hello, Duke");
 515         test("%S", "HELLO, DUKE", "Hello, Duke");
 516         test("%20S", "         HELLO, DUKE", "Hello, Duke");
 517         test("%20s", "         Hello, Duke", "Hello, Duke");
 518         test("%-20s", "Hello, Duke         ", "Hello, Duke");
 519         test("%-20.5s", "Hello               ", "Hello, Duke");
 520         test("%s", "null", (Object)null);
 521 
 522         StringBuffer sb = new StringBuffer("foo bar");
 523         test("%s", sb.toString(), sb);
 524         test("%S", sb.toString().toUpperCase(), sb);
 525 
 526         //---------------------------------------------------------------------
 527         // %s - errors
 528         //---------------------------------------------------------------------
 529         tryCatch("%-s", MissingFormatWidthException.class);
 530         tryCatch("%--s", DuplicateFormatFlagsException.class);
 531         tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0);
 532         tryCatch("%#s", FormatFlagsConversionMismatchException.class, 0.5f);
 533         tryCatch("%#s", FormatFlagsConversionMismatchException.class, "hello");
 534         tryCatch("%#s", FormatFlagsConversionMismatchException.class, null);
 535 
 536         //---------------------------------------------------------------------
 537         // %h
 538         //
 539         // General conversion applicable to any argument.
 540         //---------------------------------------------------------------------
 541         test("%h", Integer.toHexString("Hello, Duke".hashCode()),
 542              "Hello, Duke");
 543         test("%10h", "  ddf63471", "Hello, Duke");
 544         test("%-10h", "ddf63471  ", "Hello, Duke");
 545         test("%-10H", "DDF63471  ", "Hello, Duke");
 546         test("%10h", "  402e0000", 15.0);
 547         test("%10H", "  402E0000", 15.0);
 548 
 549         //---------------------------------------------------------------------
 550         // %h - errors
 551         //---------------------------------------------------------------------
 552         tryCatch("%#h", FormatFlagsConversionMismatchException.class);
 553 
 554         //---------------------------------------------------------------------
 555         // flag/conversion errors
 556         //---------------------------------------------------------------------
 557         tryCatch("%F", UnknownFormatConversionException.class);
 558 
 559         tryCatch("%#g", FormatFlagsConversionMismatchException.class);
 560 
 561 #if[dec]
 562 
 563 #if[prim]
 564         $type$ minByte = Byte.MIN_VALUE;   // -128
 565 #else[prim]
 566         $type$ minByte = new $type$(Byte.MIN_VALUE);
 567 #end[prim]
 568 
 569         //---------------------------------------------------------------------
 570         // %d
 571         //
 572         // Numeric conversion applicable to byte, short, int, long, and
 573         // BigInteger.
 574         //---------------------------------------------------------------------
 575         test("%d", "null", (Object)null);
 576 
 577 #if[byte]
 578 #if[prim]
 579         //---------------------------------------------------------------------
 580         // %d - byte
 581         //---------------------------------------------------------------------
 582         $type$ seventeen = ($type$) 17;
 583         test("%d", "17", seventeen);
 584         test("%,d", "17", seventeen);
 585         test("%,d", "-17", negate(seventeen));
 586         test("%(d", "17", seventeen);
 587         test("%(d", "(17)", negate(seventeen));
 588         test("% d", " 17", seventeen);
 589         test("% d", "-17", negate(seventeen));
 590         test("%+d", "+17", seventeen);
 591         test("%+d", "-17", negate(seventeen));
 592         test("%010d", "0000000017", seventeen);
 593         test("%010d", "-000000017", negate(seventeen));
 594         test("%(10d", "      (17)", negate(seventeen));
 595         test("%-10d", "17        ", seventeen);
 596         test("%-10d", "-17       ", negate(seventeen));
 597 #end[prim]
 598 #else[byte]
 599 #if[short]
 600         //---------------------------------------------------------------------
 601         // %d - short
 602         //---------------------------------------------------------------------
 603         $type$ oneToFive = ($type$) 12345;
 604         test("%d", "12345", oneToFive);
 605         test("%,d", "12,345", oneToFive);
 606         test("%,d", "-12,345", negate(oneToFive));
 607         test("%(d", "12345", oneToFive);
 608         test("%(d", "(12345)", negate(oneToFive));
 609         test("% d", " 12345", oneToFive);
 610         test("% d", "-12345", negate(oneToFive));
 611         test("%+d", "+12345", oneToFive);
 612         test("%+d", "-12345", negate(oneToFive));
 613         test("%010d", "0000012345", oneToFive);
 614         test("%010d", "-000012345", negate(oneToFive));
 615         test("%(10d", "   (12345)", negate(oneToFive));
 616         test("%-10d", "12345     ", oneToFive);
 617         test("%-10d", "-12345    ", negate(oneToFive));
 618         // , variations:
 619         test("% ,d", " 12,345", oneToFive);
 620         test("% ,d", "-12,345", negate(oneToFive));
 621         test("%0,10d", "000012,345", oneToFive);
 622         test("%0,10d", "-00012,345", negate(oneToFive));
 623         test("%(,10d", "  (12,345)", negate(oneToFive));
 624         test("%-,10d", "12,345    ", oneToFive);
 625         test("%-,10d", "-12,345   ", negate(oneToFive));
 626 
 627 #else[short]
 628 #if[prim]
 629         //---------------------------------------------------------------------
 630         // %d - int and long
 631         //---------------------------------------------------------------------
 632         $type$ oneToSeven = ($type$) 1234567;
 633         test("%d", "1234567", oneToSeven);
 634         test("%,d", "1,234,567", oneToSeven);
 635         test(Locale.FRANCE, "%,d", "1\u00a0234\u00a0567", oneToSeven);
 636         test("%,d", "-1,234,567", negate(oneToSeven));
 637         test("%(d", "1234567", oneToSeven);
 638         test("%(d", "(1234567)", negate(oneToSeven));
 639         test("% d", " 1234567", oneToSeven);
 640         test("% d", "-1234567", negate(oneToSeven));
 641         test("%+d", "+1234567", oneToSeven);
 642         test("%+d", "-1234567", negate(oneToSeven));
 643         test("%010d", "0001234567", oneToSeven);
 644         test("%010d", "-001234567", negate(oneToSeven));
 645         test("%(10d", " (1234567)", negate(oneToSeven));
 646         test("%-10d", "1234567   ", oneToSeven);
 647         test("%-10d", "-1234567  ", negate(oneToSeven));
 648         // , variations:
 649         test("% ,d", " 1,234,567", oneToSeven);
 650         test("% ,d", "-1,234,567", negate(oneToSeven));
 651         test("%+,10d", "+1,234,567", oneToSeven);
 652         test("%0,10d", "01,234,567", oneToSeven);
 653         test("%0,10d", "-1,234,567", negate(oneToSeven));
 654         test("%(,10d", "(1,234,567)", negate(oneToSeven));
 655         test("%-,10d", "1,234,567 ", oneToSeven);
 656         test("%-,10d", "-1,234,567", negate(oneToSeven));
 657 
 658 #end[prim]
 659 #end[short]
 660 #end[byte]
 661         //---------------------------------------------------------------------
 662         // %d - errors
 663         //---------------------------------------------------------------------
 664         tryCatch("%#d", FormatFlagsConversionMismatchException.class);
 665         tryCatch("%D", UnknownFormatConversionException.class);
 666         tryCatch("%0d", MissingFormatWidthException.class);
 667         tryCatch("%-d", MissingFormatWidthException.class);
 668         tryCatch("%7.3d", IllegalFormatPrecisionException.class);
 669 
 670         //---------------------------------------------------------------------
 671         // %o
 672         //
 673         // Numeric conversion applicable to byte, short, int, long, and
 674         // BigInteger.
 675         //---------------------------------------------------------------------
 676         test("%o", "null", (Object)null);
 677 
 678 #if[byte]
 679         //---------------------------------------------------------------------
 680         // %o - byte
 681         //---------------------------------------------------------------------
 682         test("%010o", "0000000200", minByte);
 683         test("%-10o", "200       ", minByte);
 684         test("%#10o", "      0200", minByte);
 685 #end[byte]
 686 #if[short]
 687         //---------------------------------------------------------------------
 688         // %o - short
 689         //---------------------------------------------------------------------
 690 
 691         test("%010o", "0000177600", minByte);
 692         test("%-10o", "177600    ", minByte);
 693         test("%#10o", "   0177600", minByte);
 694 #end[short]
 695 #if[int]
 696         //---------------------------------------------------------------------
 697         // %o - int
 698         //---------------------------------------------------------------------
 699         test("%014o", "00037777777600", minByte);
 700         test("%-14o", "37777777600   ", minByte);
 701         test("%#14o", "  037777777600", minByte);
 702 
 703         $type$ oneToSevenOct = ($type$) 1234567;
 704         test("%o", "4553207", oneToSevenOct);
 705         test("%010o", "0004553207", oneToSevenOct);
 706         test("%-10o", "4553207   ", oneToSevenOct);
 707         test("%#10o", "  04553207", oneToSevenOct);
 708 #end[int]
 709 #if[long]
 710         //---------------------------------------------------------------------
 711         // %o - long
 712         //---------------------------------------------------------------------
 713         test("%024o", "001777777777777777777600", minByte);
 714         test("%-24o", "1777777777777777777600  ", minByte);
 715         test("%#24o", " 01777777777777777777600", minByte);
 716 
 717         $type$ oneToSevenOct = ($type$) 1234567;
 718         test("%o", "4553207", oneToSevenOct);
 719         test("%010o", "0004553207", oneToSevenOct);
 720         test("%-10o", "4553207   ", oneToSevenOct);
 721         test("%#10o", "  04553207", oneToSevenOct);
 722 #end[long]
 723 
 724         //---------------------------------------------------------------------
 725         // %o - errors
 726         //---------------------------------------------------------------------
 727         tryCatch("%(o", FormatFlagsConversionMismatchException.class,
 728                  minByte);
 729         tryCatch("%+o", FormatFlagsConversionMismatchException.class,
 730                  minByte);
 731         tryCatch("% o", FormatFlagsConversionMismatchException.class,
 732                  minByte);
 733         tryCatch("%0o", MissingFormatWidthException.class);
 734         tryCatch("%-o", MissingFormatWidthException.class);
 735         tryCatch("%,o", FormatFlagsConversionMismatchException.class);
 736         tryCatch("%O", UnknownFormatConversionException.class);
 737 
 738         //---------------------------------------------------------------------
 739         // %x
 740         //
 741         // Numeric conversion applicable to byte, short, int, long, and
 742         // BigInteger.
 743         //---------------------------------------------------------------------
 744         test("%x", "null", (Object)null);
 745 
 746 #if[byte]
 747         //---------------------------------------------------------------------
 748         // %x - byte
 749         //---------------------------------------------------------------------
 750         test("%010x", "0000000080", minByte);
 751         test("%-10x", "80        ", minByte);
 752         test("%#10x", "      0x80", minByte);
 753         test("%0#10x","0x00000080", minByte);
 754         test("%#10X", "      0X80", minByte);
 755         test("%X", "80", minByte);
 756 #end[byte]
 757 #if[short]
 758         //---------------------------------------------------------------------
 759         // %x - short
 760         //---------------------------------------------------------------------
 761         test("%010x", "000000ff80", minByte);
 762         test("%-10x", "ff80      ", minByte);
 763         test("%#10x", "    0xff80", minByte);
 764         test("%0#10x","0x0000ff80", minByte);
 765         test("%#10X", "    0XFF80", minByte);
 766         test("%X", "FF80", minByte);
 767 #end[short]
 768 #if[int]
 769         //---------------------------------------------------------------------
 770         // %x - int
 771         //---------------------------------------------------------------------
 772         $type$ oneToSevenHex = ($type$)1234567;
 773         test("%x", "null", (Object)null);
 774         test("%x", "12d687", oneToSevenHex);
 775         test("%010x", "000012d687", oneToSevenHex);
 776         test("%-10x", "12d687    ", oneToSevenHex);
 777         test("%#10x", "  0x12d687", oneToSevenHex);
 778         test("%#10X", "  0X12D687",oneToSevenHex);
 779         test("%X", "12D687", oneToSevenHex);
 780 
 781         test("%010x", "00ffffff80", minByte);
 782         test("%-10x", "ffffff80  ", minByte);
 783         test("%#10x", "0xffffff80", minByte);
 784         test("%0#12x","0x00ffffff80", minByte);
 785         test("%#12X", "  0XFFFFFF80", minByte);
 786         test("%X", "FFFFFF80", minByte);
 787 #end[int]
 788 #if[long]
 789         //---------------------------------------------------------------------
 790         // %x - long
 791         //---------------------------------------------------------------------
 792         $type$ oneToSevenHex = ($type$)1234567;
 793         test("%x", "null", (Object)null);
 794         test("%x", "12d687", oneToSevenHex);
 795         test("%010x", "000012d687", oneToSevenHex);
 796         test("%-10x", "12d687    ", oneToSevenHex);
 797         test("%#10x", "  0x12d687", oneToSevenHex);
 798         test("%#10X", "  0X12D687",oneToSevenHex);
 799         test("%X", "12D687", oneToSevenHex);
 800 
 801         test("%018x",    "00ffffffffffffff80", minByte);
 802         test("%-18x",      "ffffffffffffff80  ", minByte);
 803         test("%#20x",  "  0xffffffffffffff80", minByte);
 804         test("%0#20x", "0x00ffffffffffffff80", minByte);
 805         test("%#20X", "  0XFFFFFFFFFFFFFF80", minByte);
 806         test("%X",        "FFFFFFFFFFFFFF80", minByte);
 807 #end[long]
 808         //---------------------------------------------------------------------
 809         // %x - errors
 810         //---------------------------------------------------------------------
 811         tryCatch("%,x", FormatFlagsConversionMismatchException.class);
 812         tryCatch("%0x", MissingFormatWidthException.class);
 813         tryCatch("%-x", MissingFormatWidthException.class);
 814 
 815 #end[dec]
 816 
 817 #if[BigInteger]
 818         //---------------------------------------------------------------------
 819         // BigInteger - errors
 820         //---------------------------------------------------------------------
 821         tryCatch("%f", IllegalFormatConversionException.class,
 822                  new BigInteger("1"));
 823 
 824         //---------------------------------------------------------------------
 825         // %d - BigInteger
 826         //---------------------------------------------------------------------
 827         test("%d", "null", (Object)null);
 828         test("%d", "1234567", new BigInteger("1234567", 10));
 829         test("%,d", "1,234,567", new BigInteger("1234567", 10));
 830         test(Locale.FRANCE, "%,d", "1\u00a0234\u00a0567", new BigInteger("1234567", 10));
 831         test("%,d", "-1,234,567", new BigInteger("-1234567", 10));
 832         test("%(d", "1234567", new BigInteger("1234567", 10));
 833         test("%(d", "(1234567)", new BigInteger("-1234567", 10));
 834         test("% d", " 1234567", new BigInteger("1234567", 10));
 835         test("% d", "-1234567", new BigInteger("-1234567", 10));
 836         test("%+d", "+1234567", new BigInteger("1234567", 10));
 837         test("%+d", "-1234567", new BigInteger("-1234567", 10));
 838         test("%010d", "0001234567", new BigInteger("1234567", 10));
 839         test("%010d", "-001234567", new BigInteger("-1234567", 10));
 840         test("%(10d", " (1234567)", new BigInteger("-1234567", 10));
 841         test("%+d", "+1234567", new BigInteger("1234567", 10));
 842         test("%+d", "-1234567", new BigInteger("-1234567", 10));
 843         test("%-10d", "1234567   ", new BigInteger("1234567", 10));
 844         test("%-10d", "-1234567  ", new BigInteger("-1234567", 10));
 845         // , variations:
 846         test("%0,10d", "01,234,567", new BigInteger("1234567", 10));
 847         test("%0,10d", "-1,234,567", new BigInteger("-1234567", 10));
 848         test("%(,10d", "(1,234,567)", new BigInteger("-1234567", 10));
 849         test("%+,d", "+1,234,567", new BigInteger("1234567", 10));
 850         test("%+,d", "-1,234,567", new BigInteger("-1234567", 10));
 851         test("%-,10d", "1,234,567 ", new BigInteger("1234567", 10));
 852         test("%-,10d", "-1,234,567", new BigInteger("-1234567", 10));
 853 
 854         //---------------------------------------------------------------------
 855         // %o - BigInteger
 856         //---------------------------------------------------------------------
 857         test("%o", "null", (Object)null);
 858         test("%o", "1234567", new BigInteger("1234567", 8));
 859         test("%(o", "1234567", new BigInteger("1234567", 8));
 860         test("%(o", "(1234567)", new BigInteger("-1234567", 8));
 861         test("% o", " 1234567", new BigInteger("1234567", 8));
 862         test("% o", "-1234567", new BigInteger("-1234567", 8));
 863         test("%+o", "+1234567", new BigInteger("1234567", 8));
 864         test("%+o", "-1234567", new BigInteger("-1234567", 8));
 865         test("%010o", "0001234567", new BigInteger("1234567", 8));
 866         test("%010o", "-001234567", new BigInteger("-1234567", 8));
 867         test("%(10o", " (1234567)", new BigInteger("-1234567", 8));
 868         test("%+o", "+1234567", new BigInteger("1234567", 8));
 869         test("%+o", "-1234567", new BigInteger("-1234567", 8));
 870         test("%-10o", "1234567   ", new BigInteger("1234567", 8));
 871         test("%-10o", "-1234567  ", new BigInteger("-1234567", 8));
 872         test("%#10o", "  01234567", new BigInteger("1234567", 8));
 873         test("%#10o", " -01234567", new BigInteger("-1234567", 8));
 874 
 875         //---------------------------------------------------------------------
 876         // %x - BigInteger
 877         //---------------------------------------------------------------------
 878         test("%x", "null", (Object)null);
 879         test("%x", "1234567", new BigInteger("1234567", 16));
 880         test("%(x", "1234567", new BigInteger("1234567", 16));
 881         test("%(x", "(1234567)", new BigInteger("-1234567", 16));
 882         test("% x", " 1234567", new BigInteger("1234567", 16));
 883         test("% x", "-1234567", new BigInteger("-1234567", 16));
 884         test("%+x", "+1234567", new BigInteger("1234567", 16));
 885         test("%+x", "-1234567", new BigInteger("-1234567", 16));
 886         test("%010x", "0001234567", new BigInteger("1234567", 16));
 887         test("%010x", "-001234567", new BigInteger("-1234567", 16));
 888         test("%(10x", " (1234567)", new BigInteger("-1234567", 16));
 889         test("%+x", "+1234567", new BigInteger("1234567", 16));
 890         test("%+x", "-1234567", new BigInteger("-1234567", 16));
 891         test("%-10x", "1234567   ", new BigInteger("1234567", 16));
 892         test("%-10x", "-1234567  ", new BigInteger("-1234567", 16));
 893         test("%#10x", " 0x1234567", new BigInteger("1234567", 16));
 894         test("%#10x", "-0x1234567", new BigInteger("-1234567", 16));
 895         test("%#10X", " 0X1234567", new BigInteger("1234567", 16));
 896         test("%#10X", "-0X1234567", new BigInteger("-1234567", 16));
 897         test("%X", "1234567A", new BigInteger("1234567a", 16));
 898         test("%X", "-1234567A", new BigInteger("-1234567a", 16));
 899 #end[BigInteger]
 900 
 901 #if[fp]
 902 #if[BigDecimal]
 903         //---------------------------------------------------------------------
 904         // %s - BigDecimal
 905         //---------------------------------------------------------------------
 906         $type$ one = BigDecimal.ONE;
 907         $type$ ten = BigDecimal.TEN;
 908         $type$ pi  = new $type$(Math.PI);
 909         $type$ piToThe300 = pi.pow(300);
 910 
 911         test("%s", "3.141592653589793115997963468544185161590576171875", pi);
 912 #end[BigDecimal]
 913 #if[float]
 914         //---------------------------------------------------------------------
 915         // %s - float
 916         //---------------------------------------------------------------------
 917         $type$ one = 1.0f;
 918         $type$ ten = 10.0f;
 919         $type$ pi  = (float) Math.PI;
 920 
 921         test("%s", "3.1415927", pi);
 922 #end[float]
 923 #if[Float]
 924         //---------------------------------------------------------------------
 925         // %s - Float
 926         //---------------------------------------------------------------------
 927         $type$ one = new $type$(1.0f);
 928         $type$ ten = new $type$(10.0f);
 929         $type$ pi  = new $type$(Math.PI);
 930 
 931         test("%s", "3.1415927", pi);
 932 #end[Float]
 933 #if[double]
 934         //---------------------------------------------------------------------
 935         // %s - double
 936         //---------------------------------------------------------------------
 937         $type$ one = 1.0;
 938         $type$ ten = 10.0;
 939         $type$ pi  = Math.PI;
 940 
 941         test("%s", "3.141592653589793", pi);
 942 #end[double]
 943 #if[Double]
 944         //---------------------------------------------------------------------
 945         // %s - Double
 946         //---------------------------------------------------------------------
 947         $type$ one = new $type$(1.0);
 948         $type$ ten = new $type$(10.0);
 949         $type$ pi  = new $type$(Math.PI);
 950 
 951         test("%s", "3.141592653589793", pi);
 952 #end[Double]
 953 
 954         //---------------------------------------------------------------------
 955         // flag/conversion errors
 956         //---------------------------------------------------------------------
 957         tryCatch("%d", IllegalFormatConversionException.class, one);
 958         tryCatch("%,.4e", FormatFlagsConversionMismatchException.class, one);
 959 
 960         //---------------------------------------------------------------------
 961         // %e
 962         //
 963         // Floating-point conversions applicable to float, double, and
 964         // BigDecimal.
 965         //---------------------------------------------------------------------
 966         test("%e", "null", (Object)null);
 967 
 968         //---------------------------------------------------------------------
 969         // %e - float and double
 970         //---------------------------------------------------------------------
 971         // double PI = 3.141 592 653 589 793 238 46;
 972         test("%e", "3.141593e+00", pi);
 973         test("%.0e", "1e+01", ten);
 974         test("%#.0e", "1.e+01", ten);
 975         test("%E", "3.141593E+00", pi);
 976         test("%10.3e", " 3.142e+00", pi);
 977         test("%10.3e", "-3.142e+00", negate(pi));
 978         test("%010.3e", "03.142e+00", pi);
 979         test("%010.3e", "-3.142e+00", negate(pi));
 980         test("%-12.3e", "3.142e+00   ", pi);
 981         test("%-12.3e", "-3.142e+00  ", negate(pi));
 982         test("%.3e", "3.142e+00", pi);
 983         test("%.3e", "-3.142e+00", negate(pi));
 984         test("%.3e", "3.142e+06", mult(pi, 1000000.0));
 985         test("%.3e", "-3.142e+06", mult(pi, -1000000.0));
 986 
 987         test(Locale.FRANCE, "%e", "3,141593e+00", pi);
 988 
 989         // double PI^300
 990         //    = 13962455701329742638131355433930076081862072808 ... e+149
 991 #if[BigDecimal]
 992         //---------------------------------------------------------------------
 993         // %e - BigDecimal
 994         //---------------------------------------------------------------------
 995         test("%.3e", "1.396e+149", piToThe300);
 996         test("%.3e", "-1.396e+149", piToThe300.negate());
 997         test("%.3e", "1.000e-100", recip(ten.pow(100)));
 998         test("%.3e", "-1.000e-100", negate(recip(ten.pow(100))));
 999 
1000         test("%3.0e", "1e-06", new BigDecimal("0.000001"));
1001         test("%3.0e", "1e-05", new BigDecimal("0.00001"));
1002         test("%3.0e", "1e-04", new BigDecimal("0.0001"));
1003         test("%3.0e", "1e-03", new BigDecimal("0.001"));
1004         test("%3.0e", "1e-02", new BigDecimal("0.01"));
1005         test("%3.0e", "1e-01", new BigDecimal("0.1"));
1006         test("%3.0e", "9e-01", new BigDecimal("0.9"));
1007         test("%3.1e", "9.0e-01", new BigDecimal("0.9"));
1008         test("%3.0e", "1e+00", new BigDecimal("1.00"));
1009         test("%3.0e", "1e+01", new BigDecimal("10.00"));
1010         test("%3.0e", "1e+02", new BigDecimal("99.19"));
1011         test("%3.1e", "9.9e+01", new BigDecimal("99.19"));
1012         test("%3.0e", "1e+02", new BigDecimal("99.99"));
1013         test("%3.0e", "1e+02", new BigDecimal("100.00"));
1014         test("%#3.0e", "1.e+03",    new BigDecimal("1000.00"));
1015         test("%3.0e", "1e+04",     new BigDecimal("10000.00"));
1016         test("%3.0e", "1e+05",    new BigDecimal("100000.00"));
1017         test("%3.0e", "1e+06",   new BigDecimal("1000000.00"));
1018         test("%3.0e", "1e+07",  new BigDecimal("10000000.00"));
1019         test("%3.0e", "1e+08", new BigDecimal("100000000.00"));
1020 #end[BigDecimal]
1021 
1022         test("%10.3e", " 1.000e+00", one);
1023         test("%+.3e", "+3.142e+00", pi);
1024         test("%+.3e", "-3.142e+00", negate(pi));
1025         test("% .3e", " 3.142e+00", pi);
1026         test("% .3e", "-3.142e+00", negate(pi));
1027         test("%#.0e", "3.e+00", create(3.0));
1028         test("%#.0e", "-3.e+00", create(-3.0));
1029         test("%.0e", "3e+00", create(3.0));
1030         test("%.0e", "-3e+00", create(-3.0));
1031 
1032         test("%(.4e", "3.1416e+06", mult(pi, 1000000.0));
1033         test("%(.4e", "(3.1416e+06)", mult(pi, -1000000.0));
1034 
1035         //---------------------------------------------------------------------
1036         // %e - boundary problems
1037         //---------------------------------------------------------------------
1038         test("%3.0e", "1e-06", 0.000001);
1039         test("%3.0e", "1e-05", 0.00001);
1040         test("%3.0e", "1e-04", 0.0001);
1041         test("%3.0e", "1e-03", 0.001);
1042         test("%3.0e", "1e-02", 0.01);
1043         test("%3.0e", "1e-01", 0.1);
1044         test("%3.0e", "9e-01", 0.9);
1045         test("%3.1e", "9.0e-01", 0.9);
1046         test("%3.0e", "1e+00", 1.00);
1047         test("%3.0e", "1e+01", 10.00);
1048         test("%3.0e", "1e+02", 99.19);
1049         test("%3.1e", "9.9e+01", 99.19);
1050         test("%3.0e", "1e+02", 99.99);
1051         test("%3.0e", "1e+02", 100.00);
1052         test("%#3.0e", "1.e+03",     1000.00);
1053         test("%3.0e", "1e+04",     10000.00);
1054         test("%3.0e", "1e+05",    100000.00);
1055         test("%3.0e", "1e+06",   1000000.00);
1056         test("%3.0e", "1e+07",  10000000.00);
1057         test("%3.0e", "1e+08", 100000000.00);
1058 
1059         //---------------------------------------------------------------------
1060         // %f
1061         //
1062         // Floating-point conversions applicable to float, double, and
1063         // BigDecimal.
1064         //---------------------------------------------------------------------
1065         test("%f", "null", (Object)null);
1066         test("%f", "3.141593", pi);
1067         test(Locale.FRANCE, "%f", "3,141593", pi);
1068         test("%10.3f", "     3.142", pi);
1069         test("%10.3f", "    -3.142", negate(pi));
1070         test("%010.3f", "000003.142", pi);
1071         test("%010.3f", "-00003.142", negate(pi));
1072         test("%-10.3f", "3.142     ", pi);
1073         test("%-10.3f", "-3.142    ", negate(pi));
1074         test("%.3f", "3.142", pi);
1075         test("%.3f", "-3.142", negate(pi));
1076         test("%+.3f", "+3.142", pi);
1077         test("%+.3f", "-3.142", negate(pi));
1078         test("% .3f", " 3.142", pi);
1079         test("% .3f", "-3.142", negate(pi));
1080         test("%#.0f", "3.", create(3.0));
1081         test("%#.0f", "-3.", create(-3.0));
1082         test("%.0f", "3", create(3.0));
1083         test("%.0f", "-3", create(-3.0));
1084         test("%.3f", "10.000", ten);
1085         test("%.3f", "1.000", one);
1086         test("%10.3f", "     1.000", one);
1087 
1088         //---------------------------------------------------------------------
1089         // %f - boundary problems
1090         //---------------------------------------------------------------------
1091         test("%3.0f", "  0", 0.000001);
1092         test("%3.0f", "  0", 0.00001);
1093         test("%3.0f", "  0", 0.0001);
1094         test("%3.0f", "  0", 0.001);
1095         test("%3.0f", "  0", 0.01);
1096         test("%3.0f", "  0", 0.1);
1097         test("%3.0f", "  1", 0.9);
1098         test("%3.1f", "0.9", 0.9);
1099         test("%3.0f", "  1", 1.00);
1100         test("%3.0f", " 10", 10.00);
1101         test("%3.0f", " 99", 99.19);
1102         test("%3.1f", "99.2", 99.19);
1103         test("%3.0f", "100", 99.99);
1104         test("%3.0f", "100", 100.00);
1105         test("%#3.0f", "1000.",     1000.00);
1106         test("%3.0f", "10000",     10000.00);
1107         test("%3.0f", "100000",    100000.00);
1108         test("%3.0f", "1000000",   1000000.00);
1109         test("%3.0f", "10000000",  10000000.00);
1110         test("%3.0f", "100000000", 100000000.00);
1111         test("%10.0f", "   1000000",   1000000.00);
1112         test("%,10.0f", " 1,000,000",   1000000.00);
1113         test("%,10.1f", "1,000,000.0",   1000000.00);
1114         test("%,3.0f", "1,000,000",   1000000.00);
1115         test("%,3.0f", "10,000,000",  10000000.00);
1116         test("%,3.0f", "100,000,000", 100000000.00);
1117         test("%,3.0f", "10,000,000",  10000000.00);
1118         test("%,3.0f", "100,000,000", 100000000.00);
1119 #if[BigDecimal]
1120         //---------------------------------------------------------------------
1121         // %f - BigDecimal
1122         //---------------------------------------------------------------------
1123         test("%4.0f", "  99", new BigDecimal("99.19"));
1124         test("%4.1f", "99.2", new BigDecimal("99.19"));
1125 
1126         BigDecimal val = new BigDecimal("99.95");
1127         test("%4.0f", " 100", val);
1128         test("%#4.0f", "100.", val);
1129         test("%4.1f", "100.0", val);
1130         test("%4.2f", "99.95", val);
1131         test("%4.3f", "99.950", val);
1132 
1133         val = new BigDecimal(".99");
1134         test("%4.1f", " 1.0", val);
1135         test("%4.2f", "0.99", val);
1136         test("%4.3f", "0.990", val);
1137 
1138         // #6476425
1139         val = new BigDecimal("0.00001");
1140         test("%.0f", "0", val);
1141         test("%.1f", "0.0", val);
1142         test("%.2f", "0.00", val);
1143         test("%.3f", "0.000", val);
1144         test("%.4f", "0.0000", val);
1145         test("%.5f", "0.00001", val);
1146 
1147         val = new BigDecimal("1.00001");
1148         test("%.0f", "1", val);
1149         test("%.1f", "1.0", val);
1150         test("%.2f", "1.00", val);
1151         test("%.3f", "1.000", val);
1152         test("%.4f", "1.0000", val);
1153         test("%.5f", "1.00001", val);
1154 
1155         val = new BigDecimal("1.23456");
1156         test("%.0f", "1", val);
1157         test("%.1f", "1.2", val);
1158         test("%.2f", "1.23", val);
1159         test("%.3f", "1.235", val);
1160         test("%.4f", "1.2346", val);
1161         test("%.5f", "1.23456", val);
1162         test("%.6f", "1.234560", val);
1163 
1164         val = new BigDecimal("9.99999");
1165         test("%.0f", "10", val);
1166         test("%.1f", "10.0", val);
1167         test("%.2f", "10.00", val);
1168         test("%.3f", "10.000", val);
1169         test("%.4f", "10.0000", val);
1170         test("%.5f", "9.99999", val);
1171         test("%.6f", "9.999990", val);
1172 
1173 
1174         val = new BigDecimal("1.99999");
1175         test("%.0f", "2", val);
1176         test("%.1f", "2.0", val);
1177         test("%.2f", "2.00", val);
1178         test("%.3f", "2.000", val);
1179         test("%.4f", "2.0000", val);
1180         test("%.5f", "1.99999", val);
1181         test("%.6f", "1.999990", val);
1182 
1183         val = new BigDecimal(0.9996);
1184         test("%.0f", "1", val);
1185         test("%.1f", "1.0", val);
1186         test("%.2f", "1.00", val);
1187         test("%.3f", "1.000", val);
1188         test("%.4f", "0.9996", val);
1189         test("%.5f", "0.99960", val);
1190         test("%.6f", "0.999600", val);
1191 
1192         val = new BigDecimal(BigInteger.ZERO, 6);
1193         test("%.4f", "0.0000", val);
1194         val = new BigDecimal(BigInteger.ZERO, -6);
1195         test("%.4f", "0.0000", val);
1196 #end[BigDecimal]
1197 
1198 #if[float]
1199         //---------------------------------------------------------------------
1200         // %f - float
1201         //---------------------------------------------------------------------
1202         // Float can not accurately store 1e6 * PI.
1203         test("%.3f", "3141.593", mult(pi, 1000.0));
1204         test("%.3f", "-3141.593", mult(pi, -1000.0));
1205 
1206         test("%,.2f", "3,141.59", mult(pi, 1000.0));
1207         test(Locale.FRANCE, "%,.2f", "3\u00a0141,59", mult(pi, 1000.0));
1208         test("%,.2f", "-3,141.59", mult(pi, -1000.0));
1209         test("%(.2f", "3141.59", mult(pi, 1000.0));
1210         test("%(.2f", "(3141.59)", mult(pi, -1000.0));
1211         test("%(,.2f", "3,141.59", mult(pi, 1000.0));
1212         test("%(,.2f", "(3,141.59)", mult(pi, -1000.0));
1213 
1214 #else[float]
1215 #if[!Float]
1216         //---------------------------------------------------------------------
1217         // %f - float, double, Double, BigDecimal
1218         //---------------------------------------------------------------------
1219         test("%.3f", "3141592.654", mult(pi, 1000000.0));
1220         test("%.3f", "-3141592.654", mult(pi, -1000000.0));
1221         test("%,.4f", "3,141,592.6536", mult(pi, 1000000.0));
1222         test(Locale.FRANCE, "%,.4f", "3\u00a0141\u00a0592,6536", mult(pi, 1000000.0));
1223         test("%,.4f", "-3,141,592.6536", mult(pi, -1000000.0));
1224         test("%(.4f", "3141592.6536", mult(pi, 1000000.0));
1225         test("%(.4f", "(3141592.6536)", mult(pi, -1000000.0));
1226         test("%(,.4f", "3,141,592.6536", mult(pi, 1000000.0));
1227         test("%(,.4f", "(3,141,592.6536)", mult(pi, -1000000.0));
1228 #end[!Float]
1229 #end[float]
1230 
1231 
1232         //---------------------------------------------------------------------
1233         // %g
1234         //
1235         // Floating-point conversions applicable to float, double, and
1236         // BigDecimal.
1237         //---------------------------------------------------------------------
1238         test("%g", "null", (Object)null);
1239         test("%g", "3.14159", pi);
1240         test(Locale.FRANCE, "%g", "3,14159", pi);
1241         test("%.0g", "1e+01", ten);
1242         test("%G", "3.14159", pi);
1243         test("%10.3g", "      3.14", pi);
1244         test("%10.3g", "     -3.14", negate(pi));
1245         test("%010.3g", "0000003.14", pi);
1246         test("%010.3g", "-000003.14", negate(pi));
1247         test("%-12.3g", "3.14        ", pi);
1248         test("%-12.3g", "-3.14       ", negate(pi));
1249         test("%.3g", "3.14", pi);
1250         test("%.3g", "-3.14", negate(pi));
1251         test("%.3g", "3.14e+08", mult(pi, 100000000.0));
1252         test("%.3g", "-3.14e+08", mult(pi, -100000000.0));
1253 
1254         test("%.3g", "1.00e-05", recip(create(100000.0)));
1255         test("%.3g", "-1.00e-05", recip(create(-100000.0)));
1256         test("%.0g", "-1e-05", recip(create(-100000.0)));
1257         test("%.0g", "1e+05", create(100000.0));
1258         test("%.3G", "1.00E-05", recip(create(100000.0)));
1259         test("%.3G", "-1.00E-05", recip(create(-100000.0)));
1260 
1261         test("%.1g", "-0", -0.0);
1262         test("%3.0g", " -0", -0.0);
1263         test("%.1g", "0", 0.0);
1264         test("%3.0g", "  0", 0.0);
1265         test("%.1g", "0", +0.0);
1266         test("%3.0g", "  0", +0.0);
1267 
1268         test("%3.0g", "1e-06", 0.000001);
1269         test("%3.0g", "1e-05", 0.00001);
1270         test("%3.0g", "1e-05", 0.0000099);
1271         test("%3.1g", "1e-05", 0.0000099);
1272         test("%3.2g", "9.9e-06", 0.0000099);
1273         test("%3.0g", "0.0001", 0.0001);
1274         test("%3.0g", "9e-05",  0.00009);
1275         test("%3.0g", "0.0001", 0.000099);
1276         test("%3.1g", "0.0001", 0.000099);
1277         test("%3.2g", "9.9e-05", 0.000099);
1278         test("%3.0g", "0.001", 0.001);
1279         test("%3.0g", "0.001", 0.00099);
1280         test("%3.1g", "0.001", 0.00099);
1281         test("%3.2g", "0.00099", 0.00099);
1282         test("%3.3g", "0.00100", 0.001);
1283         test("%3.4g", "0.001000", 0.001);
1284         test("%3.0g", "0.01", 0.01);
1285         test("%3.0g", "0.1", 0.1);
1286         test("%3.0g", "0.9", 0.9);
1287         test("%3.1g", "0.9", 0.9);
1288         test("%3.0g", "  1", 1.00);
1289         test("%3.2g", " 10", 10.00);
1290         test("%3.0g", "1e+01", 10.00);
1291         test("%3.0g", "1e+02", 99.19);
1292         test("%3.1g", "1e+02", 99.19);
1293         test("%3.2g", " 99", 99.19);
1294         test("%3.0g", "1e+02", 99.9);
1295         test("%3.1g", "1e+02", 99.9);
1296         test("%3.2g", "1.0e+02", 99.9);
1297         test("%3.0g", "1e+02", 99.99);
1298         test("%3.0g", "1e+02", 100.00);
1299         test("%3.0g", "1e+03", 999.9);
1300         test("%3.1g", "1e+03", 999.9);
1301         test("%3.2g", "1.0e+03", 999.9);
1302         test("%3.3g", "1.00e+03", 999.9);
1303         test("%3.4g", "999.9", 999.9);
1304         test("%3.4g", "1000", 999.99);
1305         test("%3.0g", "1e+03", 1000.00);
1306         test("%3.0g", "1e+04",     10000.00);
1307         test("%3.0g", "1e+05",    100000.00);
1308         test("%3.0g", "1e+06",   1000000.00);
1309         test("%3.0g", "1e+07",  10000000.00);
1310         test("%3.9g", "100000000",  100000000.00);
1311         test("%3.10g", "100000000.0", 100000000.00);
1312 
1313         tryCatch("%#3.0g", FormatFlagsConversionMismatchException.class, 1000.00);
1314 
1315         // double PI^300
1316         //    = 13962455701329742638131355433930076081862072808 ... e+149
1317 #if[BigDecimal]
1318         //---------------------------------------------------------------------
1319         // %g - BigDecimal
1320         //---------------------------------------------------------------------
1321         test("%.3g", "1.40e+149", piToThe300);
1322         test("%.3g", "-1.40e+149", piToThe300.negate());
1323         test(Locale.FRANCE, "%.3g", "-1,40e+149", piToThe300.negate());
1324         test("%.3g", "1.00e-100", recip(ten.pow(100)));
1325         test("%.3g", "-1.00e-100", negate(recip(ten.pow(100))));
1326 
1327         test("%3.0g", "1e-06", new BigDecimal("0.000001"));
1328         test("%3.0g", "1e-05", new BigDecimal("0.00001"));
1329         test("%3.0g", "0.0001", new BigDecimal("0.0001"));
1330         test("%3.0g", "0.001", new BigDecimal("0.001"));
1331         test("%3.3g", "0.00100", new BigDecimal("0.001"));
1332         test("%3.4g", "0.001000", new BigDecimal("0.001"));
1333         test("%3.0g", "0.01", new BigDecimal("0.01"));
1334         test("%3.0g", "0.1", new BigDecimal("0.1"));
1335         test("%3.0g", "0.9", new BigDecimal("0.9"));
1336         test("%3.1g", "0.9", new BigDecimal("0.9"));
1337         test("%3.0g", "  1", new BigDecimal("1.00"));
1338         test("%3.2g", " 10", new BigDecimal("10.00"));
1339         test("%3.0g", "1e+01", new BigDecimal("10.00"));
1340         test("%3.0g", "1e+02", new BigDecimal("99.19"));
1341         test("%3.1g", "1e+02", new BigDecimal("99.19"));
1342         test("%3.2g", " 99", new BigDecimal("99.19"));
1343         test("%3.0g", "1e+02", new BigDecimal("99.99"));
1344         test("%3.0g", "1e+02", new BigDecimal("100.00"));
1345         test("%3.0g", "1e+03", new BigDecimal("1000.00"));
1346         test("%3.0g", "1e+04",      new BigDecimal("10000.00"));
1347         test("%3.0g", "1e+05",      new BigDecimal("100000.00"));
1348         test("%3.0g", "1e+06",      new BigDecimal("1000000.00"));
1349         test("%3.0g", "1e+07",      new BigDecimal("10000000.00"));
1350         test("%3.9g", "100000000",  new BigDecimal("100000000.00"));
1351         test("%3.10g", "100000000.0", new BigDecimal("100000000.00"));
1352 #end[BigDecimal]
1353 
1354         test("%.3g", "10.0", ten);
1355         test("%.3g", "1.00", one);
1356         test("%10.3g", "      1.00", one);
1357         test("%+10.3g", "     +3.14", pi);
1358         test("%+10.3g", "     -3.14", negate(pi));
1359         test("% .3g", " 3.14", pi);
1360         test("% .3g", "-3.14", negate(pi));
1361         test("%.0g", "3", create(3.0));
1362         test("%.0g", "-3", create(-3.0));
1363 
1364         test("%(.4g", "3.142e+08", mult(pi, 100000000.0));
1365         test("%(.4g", "(3.142e+08)", mult(pi, -100000000.0));
1366 
1367 #if[float]
1368         // Float can not accurately store 1e6 * PI.
1369         test("%,.6g", "3,141.59", mult(pi, 1000.0));
1370         test("%(,.6g", "(3,141.59)", mult(pi, -1000.0));
1371 #else[float]
1372 #if[!Float]
1373         test("%,.11g", "3,141,592.6536", mult(pi, 1000000.0));
1374         test("%(,.11g", "(3,141,592.6536)", mult(pi, -1000000.0));
1375 #end[!Float]
1376 #end[float]
1377 
1378 #if[double]
1379         //---------------------------------------------------------------------
1380         // %a
1381         //
1382         // Floating-point conversions applicable to float, double, and
1383         // BigDecimal.
1384         //---------------------------------------------------------------------
1385         test("%a", "null", (Object)null);
1386         test("%.11a", "0x0.00000000000p0", 0.0);
1387         test(Locale.FRANCE, "%.11a", "0x0.00000000000p0", 0.0); // no localization
1388         test("%.1a", "0x0.0p0", 0.0);
1389         test("%.11a", "-0x0.00000000000p0", -0.0);
1390         test("%.1a", "-0x0.0p0", -0.0);
1391         test("%.11a", "0x1.00000000000p0", 1.0);
1392         test("%.1a", "0x1.0p0", 1.0);
1393         test("%.11a", "-0x1.00000000000p0", -1.0);
1394         test("%.1a", "-0x1.0p0", -1.0);
1395         test("%.11a", "0x1.80000000000p1", 3.0);
1396         test("%.1a", "0x1.8p1", 3.0);
1397         test("%.11a", "0x1.00000000000p-1022", Double.MIN_NORMAL);
1398         test("%.1a", "0x1.0p-1022", Double.MIN_NORMAL);
1399         test("%.11a", "0x1.00000000000p-1022",
1400              Math.nextDown(Double.MIN_NORMAL));
1401         test("%.1a", "0x1.0p-1022",
1402              Math.nextDown(Double.MIN_NORMAL));
1403         test("%.11a", "0x1.ffffffffffep-1023", 0x0.fffffffffffp-1022);
1404         test("%.1a", "0x1.0p-1022", 0x0.fffffffffffp-1022);
1405         test("%.30a", "0x0.000000000000100000000000000000p-1022", Double.MIN_VALUE);
1406         test("%.13a", "0x0.0000000000001p-1022", Double.MIN_VALUE);
1407         test("%.11a", "0x1.00000000000p-1074", Double.MIN_VALUE);
1408         test("%.1a", "0x1.0p-1074", Double.MIN_VALUE);
1409 
1410         test("%.11a", "0x1.08000000000p-1069",
1411              Double.MIN_VALUE + Double.MIN_VALUE*32);
1412         test("%.1a", "0x1.0p-1069",
1413              Double.MIN_VALUE + Double.MIN_VALUE*32);
1414         test("%.30a", "0x1.fffffffffffff00000000000000000p1023", Double.MAX_VALUE);
1415         test("%.13a", "0x1.fffffffffffffp1023", Double.MAX_VALUE);
1416         test("%.11a", "0x1.00000000000p1024", Double.MAX_VALUE);
1417         test("%.1a", "0x1.0p1024", Double.MAX_VALUE);
1418         test("%.11a", "0x1.18000000000p0", 0x1.18p0);
1419         test("%.1a", "0x1.2p0", 0x1.18p0);
1420 
1421         test("%.11a", "0x1.18000000000p0", 0x1.180000000001p0);
1422         test("%.1a", "0x1.2p0", 0x1.180000000001p0);
1423         test("%.11a", "0x1.28000000000p0", 0x1.28p0);
1424         test("%.1a", "0x1.2p0", 0x1.28p0);
1425 
1426         test("%.11a", "0x1.28000000000p0", 0x1.280000000001p0);
1427         test("%.1a", "0x1.3p0", 0x1.280000000001p0);
1428 
1429         test("%a", "0x0.123p-1022", 0x0.123p-1022);
1430         test("%1.3a", "0x1.230p-1026", 0x0.123p-1022);
1431         test("%1.12a", "0x1.230000000000p-1026", 0x0.123p-1022);
1432         test("%1.15a", "0x0.123000000000000p-1022", 0x0.123p-1022);
1433         test("%1.5a", "0x1.00000p-1074", 0x0.0000000000001p-1022);
1434         test("%1.7a", "0x1.0000000p-1022", 0x0.fffffffffffffp-1022);
1435 
1436         test("%1.6a", "0x1.230000p-1026", 0x0.123000057p-1022);
1437         test("%1.7a", "0x1.2300005p-1026", 0x0.123000057p-1022);
1438         test("%1.8a", "0x1.23000057p-1026", 0x0.123000057p-1022);
1439         test("%1.9a", "0x1.230000570p-1026", 0x0.123000057p-1022);
1440 
1441         test("%1.6a", "0x1.230000p-1026", 0x0.123000058p-1022);
1442         test("%1.7a", "0x1.2300006p-1026", 0x0.123000058p-1022);
1443         test("%1.8a", "0x1.23000058p-1026", 0x0.123000058p-1022);
1444         test("%1.9a", "0x1.230000580p-1026", 0x0.123000058p-1022);
1445 
1446         test("%1.6a", "0x1.230000p-1026", 0x0.123000059p-1022);
1447         test("%1.7a", "0x1.2300006p-1026", 0x0.123000059p-1022);
1448         test("%1.8a", "0x1.23000059p-1026", 0x0.123000059p-1022);
1449         test("%1.9a", "0x1.230000590p-1026", 0x0.123000059p-1022);
1450 
1451         test("%1.4a", "0x1.0000p-1022", Math.nextDown(Double.MIN_NORMAL));
1452 
1453         test("%a", "0x1.fffffffffffffp1023", Double.MAX_VALUE);
1454         test("%1.1a", "0x1.0p1024", Double.MAX_VALUE);
1455         test("%1.2a", "0x1.00p1024", Double.MAX_VALUE);
1456         test("%1.6a", "0x1.000000p1024", Double.MAX_VALUE);
1457         test("%1.9a", "0x1.000000000p1024", Double.MAX_VALUE);
1458         test("%1.11a", "0x1.00000000000p1024", Double.MAX_VALUE);
1459         test("%1.12a", "0x1.000000000000p1024", Double.MAX_VALUE);
1460         test("%1.13a", "0x1.fffffffffffffp1023", Double.MAX_VALUE);
1461 
1462 #end[double]
1463 
1464         //---------------------------------------------------------------------
1465         // %f, %e, %g, %a - Boundaries
1466         //---------------------------------------------------------------------
1467 #if[float]
1468         //---------------------------------------------------------------------
1469         // %f, %e, %g, %a - NaN
1470         //---------------------------------------------------------------------
1471         test("%f", "NaN", Float.NaN);
1472         // s
1473         test("%+f", "NaN", Float.NaN);
1474 //      test("%F", "NAN", Float.NaN);
1475         test("%e", "NaN", Float.NaN);
1476         test("%+e", "NaN", Float.NaN);
1477         test("%E", "NAN", Float.NaN);
1478         test("%g", "NaN", Float.NaN);
1479         test("%+g", "NaN", Float.NaN);
1480         test("%G", "NAN", Float.NaN);
1481         test("%a", "NaN", Float.NaN);
1482         test("%+a", "NaN", Float.NaN);
1483         test("%A", "NAN", Float.NaN);
1484 
1485         //---------------------------------------------------------------------
1486         // %f, %e, %g, %a - +0.0
1487         //---------------------------------------------------------------------
1488         test("%f", "0.000000", +0.0);
1489         test("%+f", "+0.000000", +0.0);
1490         test("% f", " 0.000000", +0.0);
1491 //      test("%F", "0.000000", +0.0);
1492         test("%e", "0.000000e+00", 0e0);
1493         test("%e", "0.000000e+00", +0.0);
1494         test("%+e", "+0.000000e+00", +0.0);
1495         test("% e", " 0.000000e+00", +0.0);
1496         test("%E", "0.000000E+00", 0e0);
1497         test("%E", "0.000000E+00", +0.0);
1498         test("%+E", "+0.000000E+00", +0.0);
1499         test("% E", " 0.000000E+00", +0.0);
1500         test("%g", "0.00000", +0.0);
1501         test("%+g", "+0.00000", +0.0);
1502         test("% g", " 0.00000", +0.0);
1503         test("%G", "0.00000", +0.0);
1504         test("% G", " 0.00000", +0.0);
1505         test("%a", "0x0.0p0", +0.0);
1506         test("%+a", "+0x0.0p0", +0.0);
1507         test("% a", " 0x0.0p0", +0.0);
1508         test("%A", "0X0.0P0", +0.0);
1509         test("% A", " 0X0.0P0", +0.0);
1510 
1511         //---------------------------------------------------------------------
1512         // %f, %e, %g, %a - -0.0
1513         //---------------------------------------------------------------------
1514         test("%f", "-0.000000", -0.0);
1515         test("%+f", "-0.000000", -0.0);
1516 //      test("%F", "-0.000000", -0.0);
1517         test("%e", "-0.000000e+00", -0.0);
1518         test("%+e", "-0.000000e+00", -0.0);
1519         test("%E", "-0.000000E+00", -0.0);
1520         test("%+E", "-0.000000E+00", -0.0);
1521         test("%g", "-0.00000", -0.0);
1522         test("%+g", "-0.00000", -0.0);
1523         test("%G", "-0.00000", -0.0);
1524         test("%a", "-0x0.0p0", -0.0);
1525         test("%+a", "-0x0.0p0", -0.0);
1526         test("%+A", "-0X0.0P0", -0.0);
1527 
1528         //---------------------------------------------------------------------
1529         // %f, %e, %g, %a - +Infinity
1530         //---------------------------------------------------------------------
1531         test("%f", "Infinity", Float.POSITIVE_INFINITY);
1532         test("%+f", "+Infinity", Float.POSITIVE_INFINITY);
1533         test("% f", " Infinity", Float.POSITIVE_INFINITY);
1534 //      test("%F", "INFINITY", Float.POSITIVE_INFINITY);
1535         test("%e", "Infinity", Float.POSITIVE_INFINITY);
1536         test("%+e", "+Infinity", Float.POSITIVE_INFINITY);
1537         test("% e", " Infinity", Float.POSITIVE_INFINITY);
1538         test("%E", "INFINITY", Float.POSITIVE_INFINITY);
1539         test("%+E", "+INFINITY", Float.POSITIVE_INFINITY);
1540         test("% E", " INFINITY", Float.POSITIVE_INFINITY);
1541         test("%g", "Infinity", Float.POSITIVE_INFINITY);
1542         test("%+g", "+Infinity", Float.POSITIVE_INFINITY);
1543         test("%G", "INFINITY", Float.POSITIVE_INFINITY);
1544         test("% G", " INFINITY", Float.POSITIVE_INFINITY);
1545         test("%+G", "+INFINITY", Float.POSITIVE_INFINITY);
1546         test("%a", "Infinity", Float.POSITIVE_INFINITY);
1547         test("%+a", "+Infinity", Float.POSITIVE_INFINITY);
1548         test("% a", " Infinity", Float.POSITIVE_INFINITY);
1549         test("%A", "INFINITY", Float.POSITIVE_INFINITY);
1550         test("%+A", "+INFINITY", Float.POSITIVE_INFINITY);
1551         test("% A", " INFINITY", Float.POSITIVE_INFINITY);
1552 
1553         //---------------------------------------------------------------------
1554         // %f, %e, %g, %a - -Infinity
1555         //---------------------------------------------------------------------
1556         test("%f", "-Infinity", Float.NEGATIVE_INFINITY);
1557         test("%+f", "-Infinity", Float.NEGATIVE_INFINITY);
1558         test("%(f", "(Infinity)", Float.NEGATIVE_INFINITY);
1559 //      test("%F", "-INFINITY", Float.NEGATIVE_INFINITY);
1560         test("%e", "-Infinity", Float.NEGATIVE_INFINITY);
1561         test("%+e", "-Infinity", Float.NEGATIVE_INFINITY);
1562         test("%E", "-INFINITY", Float.NEGATIVE_INFINITY);
1563         test("%+E", "-INFINITY", Float.NEGATIVE_INFINITY);
1564         test("%g", "-Infinity", Float.NEGATIVE_INFINITY);
1565         test("%+g", "-Infinity", Float.NEGATIVE_INFINITY);
1566         test("%G", "-INFINITY", Float.NEGATIVE_INFINITY);
1567         test("%+G", "-INFINITY", Float.NEGATIVE_INFINITY);
1568         test("%a", "-Infinity", Float.NEGATIVE_INFINITY);
1569         test("%+a", "-Infinity", Float.NEGATIVE_INFINITY);
1570         test("%A", "-INFINITY", Float.NEGATIVE_INFINITY);
1571         test("%+A", "-INFINITY", Float.NEGATIVE_INFINITY);
1572 
1573         //---------------------------------------------------------------------
1574         // %f, %e, %g, %a - Float.MIN_VALUE
1575         //---------------------------------------------------------------------
1576         test("%f", "0.000000", Float.MIN_VALUE);
1577         test("%,f", "0.000000", Float.MIN_VALUE);
1578         test("%(f", "(0.000000)", -Float.MIN_VALUE);
1579         test("%30.0f",  "                             0", Float.MIN_VALUE);
1580         test("%30.5f",  "                       0.00000", Float.MIN_VALUE);
1581         test("%30.13f", "               0.0000000000000", Float.MIN_VALUE);
1582         test("%30.20f", "        0.00000000000000000000", Float.MIN_VALUE);
1583         test("%e", "1.401298e-45", Float.MIN_VALUE);
1584         test("%E", "1.401298E-45", Float.MIN_VALUE);
1585         test("%(.1e", "1.4e-45", Float.MIN_VALUE);
1586         test("%(E", "(1.401298E-45)", -Float.MIN_VALUE);
1587         test("%30.5e",  "                   1.40130e-45", Float.MIN_VALUE);
1588         test("%30.13e", "           1.4012984643248e-45", Float.MIN_VALUE);
1589         test("%30.20e", "    1.40129846432481700000e-45", Float.MIN_VALUE);
1590         test("%g", "1.40130e-45", Float.MIN_VALUE);
1591         test("%G", "1.40130E-45", Float.MIN_VALUE);
1592         test("%(g", "1.40130e-45", Float.MIN_VALUE);
1593         test("%,g", "1.40130e-45", Float.MIN_VALUE);
1594         test("%(G", "(1.40130E-45)", -Float.MIN_VALUE);
1595         test("%30.5g",  "                    1.4013e-45", Float.MIN_VALUE);
1596         test("%30.13g", "            1.401298464325e-45", Float.MIN_VALUE);
1597         test("%30.20g", "     1.4012984643248170000e-45", Float.MIN_VALUE);
1598         test("%a", "0x1.0p-149", Float.MIN_VALUE);
1599         test("%A", "0X1.0P-149", Float.MIN_VALUE);
1600         test("%20a", "          0x1.0p-149", Float.MIN_VALUE);
1601 
1602         //---------------------------------------------------------------------
1603         // %f, %e, %g, %a - Float.MAX_VALUE
1604         //---------------------------------------------------------------------
1605         test("%f", "340282346638528860000000000000000000000.000000", Float.MAX_VALUE);
1606         test("%,f","340,282,346,638,528,860,000,000,000,000,000,000,000.000000",
1607              Float.MAX_VALUE);
1608         test("%(f", "(340282346638528860000000000000000000000.000000)", -Float.MAX_VALUE);
1609         test("%60.5f",  "               340282346638528860000000000000000000000.00000",
1610              Float.MAX_VALUE);
1611         test("%60.13f", "       340282346638528860000000000000000000000.0000000000000",
1612              Float.MAX_VALUE);
1613         test("%61.20f", " 340282346638528860000000000000000000000.00000000000000000000",
1614              Float.MAX_VALUE);
1615         test("%e", "3.402823e+38", Float.MAX_VALUE);
1616         test("%E", "3.402823E+38", Float.MAX_VALUE);
1617         test("%(e", "3.402823e+38", Float.MAX_VALUE);
1618         test("%(e", "(3.402823e+38)", -Float.MAX_VALUE);
1619         test("%30.5e",  "                   3.40282e+38", Float.MAX_VALUE);
1620         test("%30.13e", "           3.4028234663853e+38", Float.MAX_VALUE);
1621         test("%30.20e", "    3.40282346638528860000e+38", Float.MAX_VALUE);
1622         test("%g", "3.40282e+38", Float.MAX_VALUE);
1623         test("%G", "3.40282E+38", Float.MAX_VALUE);
1624         test("%,g", "3.40282e+38", Float.MAX_VALUE);
1625         test("%(g", "(3.40282e+38)", -Float.MAX_VALUE);
1626         test("%30.5g",  "                    3.4028e+38", Float.MAX_VALUE);
1627         test("%30.13g", "            3.402823466385e+38", Float.MAX_VALUE);
1628         test("%30.20G", "     3.4028234663852886000E+38", Float.MAX_VALUE);
1629         test("%a", "0x1.fffffep127", Float.MAX_VALUE);
1630         test("%A", "0X1.FFFFFEP127", Float.MAX_VALUE);
1631         test("%20a","      0x1.fffffep127", Float.MAX_VALUE);
1632 
1633 #end[float]
1634 
1635 #if[double]
1636         //---------------------------------------------------------------------
1637         // %f, %e, %g, %a - Double.MIN_VALUE
1638         //---------------------------------------------------------------------
1639         test("%f", "0.000000", Double.MIN_VALUE);
1640         test("%,f", "0.000000", Double.MIN_VALUE);
1641         test("%(f", "(0.000000)", -Double.MIN_VALUE);
1642         test("%30.0f",  "                             0", Double.MIN_VALUE);
1643         test("%30.5f",  "                       0.00000", Double.MIN_VALUE);
1644         test("%30.13f", "               0.0000000000000", Double.MIN_VALUE);
1645         test("%30.20f", "        0.00000000000000000000", Double.MIN_VALUE);
1646         test("%30.350f","0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000490000000000000000000000000",
1647              Double.MIN_VALUE);
1648         test("%e", "4.900000e-324", Double.MIN_VALUE);
1649         test("%E", "4.900000E-324", Double.MIN_VALUE);
1650         test("%(.1e", "4.9e-324", Double.MIN_VALUE);
1651         test("%(E", "(4.900000E-324)", -Double.MIN_VALUE);
1652         test("%30.5e",  "                  4.90000e-324", Double.MIN_VALUE);
1653         test("%30.13e", "          4.9000000000000e-324", Double.MIN_VALUE);
1654         test("%30.20e", "   4.90000000000000000000e-324", Double.MIN_VALUE);
1655         test("%g", "4.90000e-324", Double.MIN_VALUE);
1656         test("%G", "4.90000E-324", Double.MIN_VALUE);
1657         test("%(g", "4.90000e-324", Double.MIN_VALUE);
1658         test("%,g", "4.90000e-324", Double.MIN_VALUE);
1659         test("%30.5g",  "                   4.9000e-324", Double.MIN_VALUE);
1660         test("%30.13g", "           4.900000000000e-324", Double.MIN_VALUE);
1661         test("%30.20g", "    4.9000000000000000000e-324", Double.MIN_VALUE);
1662         test("%a", "0x0.0000000000001p-1022", Double.MIN_VALUE);
1663         test("%A", "0X0.0000000000001P-1022", Double.MIN_VALUE);
1664         test("%30a",    "       0x0.0000000000001p-1022", Double.MIN_VALUE);
1665 
1666         //---------------------------------------------------------------------
1667         // %f, %e, %g, %a - Double.MAX_VALUE
1668         //---------------------------------------------------------------------
1669         test("%f", "179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000",
1670              Double.MAX_VALUE);
1671         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",
1672              Double.MAX_VALUE);
1673         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)",
1674              -Double.MAX_VALUE);
1675         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",
1676              Double.MAX_VALUE);
1677         test("%30.13f", "179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0000000000000",
1678              Double.MAX_VALUE);
1679         test("%30.20f", "179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.00000000000000000000",
1680              Double.MAX_VALUE);
1681         test("%e", "1.797693e+308", Double.MAX_VALUE);
1682         test("%E", "1.797693E+308", Double.MAX_VALUE);
1683         test("%(e", "1.797693e+308", Double.MAX_VALUE);
1684         test("%(e", "(1.797693e+308)", -Double.MAX_VALUE);
1685         test("%30.5e",  "                  1.79769e+308", Double.MAX_VALUE);
1686         test("%30.13e", "          1.7976931348623e+308", Double.MAX_VALUE);
1687         test("%30.20e", "   1.79769313486231570000e+308", Double.MAX_VALUE);
1688         test("%g", "1.79769e+308", Double.MAX_VALUE);
1689         test("%G", "1.79769E+308", Double.MAX_VALUE);
1690         test("%,g", "1.79769e+308", Double.MAX_VALUE);
1691         test("%(g", "(1.79769e+308)", -Double.MAX_VALUE);
1692         test("%30.5g",  "                   1.7977e+308", Double.MAX_VALUE);
1693         test("%30.13g", "           1.797693134862e+308", Double.MAX_VALUE);
1694         test("%30.20g", "    1.7976931348623157000e+308", Double.MAX_VALUE);
1695         test("%a", "0x1.fffffffffffffp1023", Double.MAX_VALUE);
1696         test("%A", "0X1.FFFFFFFFFFFFFP1023", Double.MAX_VALUE);
1697         test("%30a",    "        0x1.fffffffffffffp1023", Double.MAX_VALUE);
1698 #end[double]
1699 
1700 #end[fp]
1701 
1702         //---------------------------------------------------------------------
1703         // %t
1704         //
1705         // Date/Time conversions applicable to Calendar, Date, and long.
1706         //---------------------------------------------------------------------
1707         test("%tA", "null", (Object)null);
1708         test("%TA", "NULL", (Object)null);
1709 
1710         //---------------------------------------------------------------------
1711         // %t - errors
1712         //---------------------------------------------------------------------
1713         tryCatch("%t", UnknownFormatConversionException.class);
1714         tryCatch("%T", UnknownFormatConversionException.class);
1715         tryCatch("%tP", UnknownFormatConversionException.class);
1716         tryCatch("%TP", UnknownFormatConversionException.class);
1717         tryCatch("%.5tB", IllegalFormatPrecisionException.class);
1718         tryCatch("%#tB", FormatFlagsConversionMismatchException.class);
1719         tryCatch("%-tB", MissingFormatWidthException.class);
1720 
1721 #if[datetime]
1722         //---------------------------------------------------------------------
1723         // %t - create test Calendar
1724         //---------------------------------------------------------------------
1725 
1726         // Get the supported ids for GMT-08:00 (Pacific Standard Time)
1727         String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
1728         // Create a Pacific Standard Time time zone
1729         SimpleTimeZone tz = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);
1730         // public GregorianCalendar(TimeZone zone, Locale aLocale);
1731         Calendar c0 = new GregorianCalendar(tz, Locale.US);
1732         // public final void set(int year, int month, int date,
1733         //     int hourOfDay, int minute, int second);
1734         c0.set(1995, MAY, 23, 19, 48, 34);
1735         c0.set(Calendar.MILLISECOND, 584);
1736 
1737         //---------------------------------------------------------------------
1738         // %t - Minutes, {nano,milli}*seconds
1739         //
1740         // testDateTime() verifies the expected output for all applicable types
1741         // (Calendar, Date, and long).  It also verifies output for "%t" and
1742         // "%T". Thus it is sufficient to invoke that method once per
1743         // conversion/expected output.
1744         //---------------------------------------------------------------------
1745         testDateTime("%tM", "48", c0);
1746         testDateTime("%tN", "584000000", c0);
1747         testDateTime("%tL", "584", c0);
1748 //      testDateTime("%tQ", "801283714584", c0);
1749 
1750         testDateTime("%ts", String.valueOf(c0.getTimeInMillis() / 1000), c0);
1751         testDateTime("%tS", "34", c0);
1752         testDateTime("%tT", "19:48:34", c0);
1753 
1754         //---------------------------------------------------------------------
1755         // %t - Hours, morning/afternoon markers
1756         //
1757         // testHours() iterates through all twenty-four hours to verify
1758         // numeric return value and morning/afternoon markers.
1759         //---------------------------------------------------------------------
1760         testHours();
1761 
1762         //---------------------------------------------------------------------
1763         // %t - Portions of date [ day, month, dates, weeks ]
1764         //---------------------------------------------------------------------
1765         testDateTime("%ta", "Tue", c0);
1766         testDateTime("%tA", "Tuesday", c0);
1767         testDateTime("%tb", "May", c0);
1768         testDateTime("%tB", "May", c0);
1769         testDateTime("%tC", "19", c0);
1770         testDateTime("%td", "23", c0);
1771         testDateTime("%te", "23", c0);
1772         testDateTime("%th", "May", c0);
1773         testDateTime("%tj", "143", c0);
1774         testDateTime("%tm", "05", c0);
1775         testDateTime("%ty", "95", c0);
1776         testDateTime("%tY", "1995", c0);
1777 
1778         //---------------------------------------------------------------------
1779         // %t - TimeZone
1780         //---------------------------------------------------------------------
1781         testDateTime("%tz", "-0800", c0);
1782         testDateTime("%tZ", "PST", c0);
1783 
1784         //---------------------------------------------------------------------
1785         // %tz should always adjust for DST
1786         //---------------------------------------------------------------------
1787         TimeZone dtz = TimeZone.getDefault();
1788 
1789         // Artificial TimeZone based on PST with 3:15 DST always in effect
1790         TimeZone atz = new SimpleTimeZone(-8 * 60 * 60 * 1000, "AlwaysDST",
1791             JANUARY, 1, 0, 0, STANDARD_TIME,
1792             // 24hrs - 1m = 60 * 60 * 1000 * 24 - 1
1793             DECEMBER, 31, 0, 60 * 60 * 1000 * 24 - 1, STANDARD_TIME,
1794             (int)(60 * 60 * 1000 * 3.25));
1795         TimeZone.setDefault(atz);
1796         testDateTime("%tz", "-0445", Calendar.getInstance(atz));
1797 
1798         // Restore the TimeZone and verify
1799         TimeZone.setDefault(dtz);
1800         if (atz.hasSameRules(TimeZone.getDefault()))
1801             throw new RuntimeException("Default TimeZone not restored");
1802 
1803         //---------------------------------------------------------------------
1804         // %t - Composites
1805         //---------------------------------------------------------------------
1806         testDateTime("%tr", "07:48:34 PM", c0);
1807         testDateTime("%tR", "19:48", c0);
1808         testDateTime("%tc", "Tue May 23 19:48:34 PST 1995", c0);
1809         testDateTime("%tD", "05/23/95", c0);
1810         testDateTime("%tF", "1995-05-23", c0);
1811         testDateTime("%-12tF", "1995-05-23  ", c0);
1812         testDateTime("%12tF", "  1995-05-23", c0);
1813 #end[datetime]
1814 
1815         //---------------------------------------------------------------------
1816         // %n
1817         //---------------------------------------------------------------------
1818         test("%n", System.getProperty("line.separator"), (Object)null);
1819         test("%n", System.getProperty("line.separator"), "");
1820 
1821         tryCatch("%,n", IllegalFormatFlagsException.class);
1822         tryCatch("%.n", UnknownFormatConversionException.class);
1823         tryCatch("%5.n", UnknownFormatConversionException.class);
1824         tryCatch("%5n", IllegalFormatWidthException.class);
1825         tryCatch("%.7n", IllegalFormatPrecisionException.class);
1826         tryCatch("%<n", IllegalFormatFlagsException.class);
1827 
1828         //---------------------------------------------------------------------
1829         // %%
1830         //---------------------------------------------------------------------
1831         test("%%", "%", (Object)null);
1832         test("%%", "%", "");
1833 
1834         test("%5%", "    %", (Object)null);
1835         test("%5%", "    %", "");
1836         test("%-5%", "%    ", (Object)null);
1837         test("%-5%", "%    ", "");
1838 
1839         tryCatch("%.5%", IllegalFormatPrecisionException.class);
1840         tryCatch("%5.5%", IllegalFormatPrecisionException.class);
1841 
1842         tryCatch("%%%", UnknownFormatConversionException.class);
1843         // perhaps an IllegalFormatArgumentIndexException should be defined?
1844         tryCatch("%<%", IllegalFormatFlagsException.class);
1845     }
1846 }