test/java/util/Formatter/BasicBigInteger.java

Print this page
rev 10699 : 8058887: (fmt) Improve java/util/Formatter test coverage of group separators and width

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -34,32 +34,33 @@
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.text.DateFormatSymbols;
 import java.util.*;
 
-
-
-
 import static java.util.Calendar.*;
 
-
-
-
-
 public class BasicBigInteger extends Basic {
 
     private static void test(String fs, String exp, Object ... args) {
         Formatter f = new Formatter(new StringBuilder(), Locale.US);
         f.format(fs, args);
         ck(fs, exp, f.toString());
+
+        f = new Formatter(new StringBuilder(), Locale.US);
+        f.format("foo " + fs + " bar", args);
+        ck(fs, "foo " + exp + " bar", f.toString());
     }
 
     private static void test(Locale l, String fs, String exp, Object ... args)
     {
         Formatter f = new Formatter(new StringBuilder(), l);
         f.format(fs, args);
         ck(fs, exp, f.toString());
+
+        f = new Formatter(new StringBuilder(), l);
+        f.format("foo " + fs + " bar", args);
+        ck(fs, "foo " + exp + " bar", f.toString());
     }
 
     private static void test(String fs, Object ... args) {
         Formatter f = new Formatter(new StringBuilder(), Locale.US);
         f.format(fs, args);

@@ -133,205 +134,10 @@
             fail(fs, ex);
         else
             pass();
     }
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
     public static void test() {
         TimeZone.setDefault(TimeZone.getTimeZone("GMT-0800"));
 
         // Any characters not explicitly defined as conversions, date/time
         // conversion suffixes, or flags are illegal and are reserved for

@@ -513,1067 +319,91 @@
         //---------------------------------------------------------------------
         tryCatch("%F", UnknownFormatConversionException.class);
 
         tryCatch("%#g", FormatFlagsConversionMismatchException.class);
 
+        //---------------------------------------------------------------------
+        // BigInteger - errors
+        //---------------------------------------------------------------------
+        tryCatch("%f", IllegalFormatConversionException.class,
+                 new BigInteger("1"));
 
+        //---------------------------------------------------------------------
+        // %d - BigInteger
+        //---------------------------------------------------------------------
+        test("%d", "null", (Object)null);
+        test("%d", "1234567", new BigInteger("1234567", 10));
+        test("%,d", "1,234,567", new BigInteger("1234567", 10));
+        test(Locale.FRANCE, "%,d", "1\u00a0234\u00a0567", new BigInteger("1234567", 10));
+        test("%,d", "-1,234,567", new BigInteger("-1234567", 10));
+        test("%(d", "1234567", new BigInteger("1234567", 10));
+        test("%(d", "(1234567)", new BigInteger("-1234567", 10));
+        test("% d", " 1234567", new BigInteger("1234567", 10));
+        test("% d", "-1234567", new BigInteger("-1234567", 10));
+        test("%+d", "+1234567", new BigInteger("1234567", 10));
+        test("%+d", "-1234567", new BigInteger("-1234567", 10));
+        test("%010d", "0001234567", new BigInteger("1234567", 10));
+        test("%010d", "-001234567", new BigInteger("-1234567", 10));
+        test("%(10d", " (1234567)", new BigInteger("-1234567", 10));
+        test("%+d", "+1234567", new BigInteger("1234567", 10));
+        test("%+d", "-1234567", new BigInteger("-1234567", 10));
+        test("%-10d", "1234567   ", new BigInteger("1234567", 10));
+        test("%-10d", "-1234567  ", new BigInteger("-1234567", 10));
+        // , variations:
+        test("%0,10d", "01,234,567", new BigInteger("1234567", 10));
+        test("%0,10d", "-1,234,567", new BigInteger("-1234567", 10));
+        test("%(,10d", "(1,234,567)", new BigInteger("-1234567", 10));
+        test("%+,d", "+1,234,567", new BigInteger("1234567", 10));
+        test("%+,d", "-1,234,567", new BigInteger("-1234567", 10));
+        test("%-,10d", "1,234,567 ", new BigInteger("1234567", 10));
+        test("%-,10d", "-1,234,567", new BigInteger("-1234567", 10));
 
+        //---------------------------------------------------------------------
+        // %o - BigInteger
+        //---------------------------------------------------------------------
+        test("%o", "null", (Object)null);
+        test("%o", "1234567", new BigInteger("1234567", 8));
+        test("%(o", "1234567", new BigInteger("1234567", 8));
+        test("%(o", "(1234567)", new BigInteger("-1234567", 8));
+        test("% o", " 1234567", new BigInteger("1234567", 8));
+        test("% o", "-1234567", new BigInteger("-1234567", 8));
+        test("%+o", "+1234567", new BigInteger("1234567", 8));
+        test("%+o", "-1234567", new BigInteger("-1234567", 8));
+        test("%010o", "0001234567", new BigInteger("1234567", 8));
+        test("%010o", "-001234567", new BigInteger("-1234567", 8));
+        test("%(10o", " (1234567)", new BigInteger("-1234567", 8));
+        test("%+o", "+1234567", new BigInteger("1234567", 8));
+        test("%+o", "-1234567", new BigInteger("-1234567", 8));
+        test("%-10o", "1234567   ", new BigInteger("1234567", 8));
+        test("%-10o", "-1234567  ", new BigInteger("-1234567", 8));
+        test("%#10o", "  01234567", new BigInteger("1234567", 8));
+        test("%#10o", " -01234567", new BigInteger("-1234567", 8));
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-        //---------------------------------------------------------------------
-        // BigInteger - errors
-        //---------------------------------------------------------------------
-        tryCatch("%f", IllegalFormatConversionException.class,
-                 new BigInteger("1"));
-
-        //---------------------------------------------------------------------
-        // %d - BigInteger
-        //---------------------------------------------------------------------
-        test("%d", "null", (Object)null);
-        test("%d", "1234567", new BigInteger("1234567", 10));
-        test("%,d", "1,234,567", new BigInteger("1234567", 10));
-        test(Locale.FRANCE, "%,d", "1\u00a0234\u00a0567", new BigInteger("1234567", 10));
-        test("%,d", "-1,234,567", new BigInteger("-1234567", 10));
-        test("%(d", "1234567", new BigInteger("1234567", 10));
-        test("%(d", "(1234567)", new BigInteger("-1234567", 10));
-        test("% d", " 1234567", new BigInteger("1234567", 10));
-        test("% d", "-1234567", new BigInteger("-1234567", 10));
-        test("%+d", "+1234567", new BigInteger("1234567", 10));
-        test("%+d", "-1234567", new BigInteger("-1234567", 10));
-        test("%010d", "0001234567", new BigInteger("1234567", 10));
-        test("%010d", "-001234567", new BigInteger("-1234567", 10));
-        test("%(10d", " (1234567)", new BigInteger("-1234567", 10));
-        test("%+d", "+1234567", new BigInteger("1234567", 10));
-        test("%+d", "-1234567", new BigInteger("-1234567", 10));
-        test("%-10d", "1234567   ", new BigInteger("1234567", 10));
-        test("%-10d", "-1234567  ", new BigInteger("-1234567", 10));
-
-        //---------------------------------------------------------------------
-        // %o - BigInteger
-        //---------------------------------------------------------------------
-        test("%o", "null", (Object)null);
-        test("%o", "1234567", new BigInteger("1234567", 8));
-        test("%(o", "1234567", new BigInteger("1234567", 8));
-        test("%(o", "(1234567)", new BigInteger("-1234567", 8));
-        test("% o", " 1234567", new BigInteger("1234567", 8));
-        test("% o", "-1234567", new BigInteger("-1234567", 8));
-        test("%+o", "+1234567", new BigInteger("1234567", 8));
-        test("%+o", "-1234567", new BigInteger("-1234567", 8));
-        test("%010o", "0001234567", new BigInteger("1234567", 8));
-        test("%010o", "-001234567", new BigInteger("-1234567", 8));
-        test("%(10o", " (1234567)", new BigInteger("-1234567", 8));
-        test("%+o", "+1234567", new BigInteger("1234567", 8));
-        test("%+o", "-1234567", new BigInteger("-1234567", 8));
-        test("%-10o", "1234567   ", new BigInteger("1234567", 8));
-        test("%-10o", "-1234567  ", new BigInteger("-1234567", 8));
-        test("%#10o", "  01234567", new BigInteger("1234567", 8));
-        test("%#10o", " -01234567", new BigInteger("-1234567", 8));
-
-        //---------------------------------------------------------------------
-        // %x - BigInteger
-        //---------------------------------------------------------------------
-        test("%x", "null", (Object)null);
-        test("%x", "1234567", new BigInteger("1234567", 16));
-        test("%(x", "1234567", new BigInteger("1234567", 16));
-        test("%(x", "(1234567)", new BigInteger("-1234567", 16));
-        test("% x", " 1234567", new BigInteger("1234567", 16));
-        test("% x", "-1234567", new BigInteger("-1234567", 16));
-        test("%+x", "+1234567", new BigInteger("1234567", 16));
-        test("%+x", "-1234567", new BigInteger("-1234567", 16));
-        test("%010x", "0001234567", new BigInteger("1234567", 16));
-        test("%010x", "-001234567", new BigInteger("-1234567", 16));
-        test("%(10x", " (1234567)", new BigInteger("-1234567", 16));
-        test("%+x", "+1234567", new BigInteger("1234567", 16));
-        test("%+x", "-1234567", new BigInteger("-1234567", 16));
-        test("%-10x", "1234567   ", new BigInteger("1234567", 16));
-        test("%-10x", "-1234567  ", new BigInteger("-1234567", 16));
-        test("%#10x", " 0x1234567", new BigInteger("1234567", 16));
-        test("%#10x", "-0x1234567", new BigInteger("-1234567", 16));
-        test("%#10X", " 0X1234567", new BigInteger("1234567", 16));
-        test("%#10X", "-0X1234567", new BigInteger("-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-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+        //---------------------------------------------------------------------
+        // %x - BigInteger
+        //---------------------------------------------------------------------
+        test("%x", "null", (Object)null);
+        test("%x", "1234567", new BigInteger("1234567", 16));
+        test("%(x", "1234567", new BigInteger("1234567", 16));
+        test("%(x", "(1234567)", new BigInteger("-1234567", 16));
+        test("% x", " 1234567", new BigInteger("1234567", 16));
+        test("% x", "-1234567", new BigInteger("-1234567", 16));
+        test("%+x", "+1234567", new BigInteger("1234567", 16));
+        test("%+x", "-1234567", new BigInteger("-1234567", 16));
+        test("%010x", "0001234567", new BigInteger("1234567", 16));
+        test("%010x", "-001234567", new BigInteger("-1234567", 16));
+        test("%(10x", " (1234567)", new BigInteger("-1234567", 16));
+        test("%+x", "+1234567", new BigInteger("1234567", 16));
+        test("%+x", "-1234567", new BigInteger("-1234567", 16));
+        test("%-10x", "1234567   ", new BigInteger("1234567", 16));
+        test("%-10x", "-1234567  ", new BigInteger("-1234567", 16));
+        test("%#10x", " 0x1234567", new BigInteger("1234567", 16));
+        test("%#10x", "-0x1234567", new BigInteger("-1234567", 16));
+        test("%#10X", " 0X1234567", new BigInteger("1234567", 16));
+        test("%#10X", "-0X1234567", new BigInteger("-1234567", 16));
+        test("%X", "1234567A", new BigInteger("1234567a", 16));
+        test("%X", "-1234567A", new BigInteger("-1234567a", 16));
 
         //---------------------------------------------------------------------
         // %t
         //
         // Date/Time conversions applicable to Calendar, Date, and long.

@@ -1590,104 +420,10 @@
         tryCatch("%TP", UnknownFormatConversionException.class);
         tryCatch("%.5tB", IllegalFormatPrecisionException.class);
         tryCatch("%#tB", FormatFlagsConversionMismatchException.class);
         tryCatch("%-tB", MissingFormatWidthException.class);
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
         //---------------------------------------------------------------------
         // %n
         //---------------------------------------------------------------------
         test("%n", System.getProperty("line.separator"), (Object)null);
         test("%n", System.getProperty("line.separator"), "");