test/java/util/Formatter/BasicShort.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 BasicShort 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,14 @@
             fail(fs, ex);
         else
             pass();
     }
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
     private static short negate(short v) {
         return (short) -v;
     }
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
     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,49 +323,20 @@
         //---------------------------------------------------------------------
         tryCatch("%F", UnknownFormatConversionException.class);
 
         tryCatch("%#g", FormatFlagsConversionMismatchException.class);
 
-
-
-
         short minByte = Byte.MIN_VALUE;   // -128
 
-
-
-
         //---------------------------------------------------------------------
         // %d
         //
         // Numeric conversion applicable to byte, short, int, long, and
         // BigInteger.
         //---------------------------------------------------------------------
         test("%d", "null", (Object)null);
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
         //---------------------------------------------------------------------
         // %d - short
         //---------------------------------------------------------------------
         short oneToFive = (short) 12345;
         test("%d", "12345", oneToFive);

@@ -570,34 +351,18 @@
         test("%010d", "0000012345", oneToFive);
         test("%010d", "-000012345", negate(oneToFive));
         test("%(10d", "   (12345)", negate(oneToFive));
         test("%-10d", "12345     ", oneToFive);
         test("%-10d", "-12345    ", negate(oneToFive));
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+        // , variations:
+        test("% ,d", " 12,345", oneToFive);
+        test("% ,d", "-12,345", negate(oneToFive));
+        test("%0,10d", "000012,345", oneToFive);
+        test("%0,10d", "-00012,345", negate(oneToFive));
+        test("%(,10d", "  (12,345)", negate(oneToFive));
+        test("%-,10d", "12,345    ", oneToFive);
+        test("%-,10d", "-12,345   ", negate(oneToFive));
 
         //---------------------------------------------------------------------
         // %d - errors
         //---------------------------------------------------------------------
         tryCatch("%#d", FormatFlagsConversionMismatchException.class);

@@ -612,56 +377,18 @@
         // Numeric conversion applicable to byte, short, int, long, and
         // BigInteger.
         //---------------------------------------------------------------------
         test("%o", "null", (Object)null);
 
-
-
-
-
-
-
-
-
-
-        //---------------------------------------------------------------------
-        // %o - short
-        //---------------------------------------------------------------------
+        //---------------------------------------------------------------------
+        // %o - short
+        //---------------------------------------------------------------------
 
         test("%010o", "0000177600", minByte);
         test("%-10o", "177600    ", minByte);
         test("%#10o", "   0177600", minByte);
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
         //---------------------------------------------------------------------
         // %o - errors
         //---------------------------------------------------------------------
         tryCatch("%(o", FormatFlagsConversionMismatchException.class,
                  minByte);

@@ -680,908 +407,34 @@
         // Numeric conversion applicable to byte, short, int, long, and
         // BigInteger.
         //---------------------------------------------------------------------
         test("%x", "null", (Object)null);
 
-
-
-
-
-
-
-
-
-
-
-
-
         //---------------------------------------------------------------------
         // %x - short
         //---------------------------------------------------------------------
         test("%010x", "000000ff80", minByte);
         test("%-10x", "ff80      ", minByte);
         test("%#10x", "    0xff80", minByte);
         test("%0#10x","0x0000ff80", minByte);
         test("%#10X", "    0XFF80", minByte);
         test("%X", "FF80", minByte);
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
         //---------------------------------------------------------------------
         // %x - errors
         //---------------------------------------------------------------------
         tryCatch("%,x", FormatFlagsConversionMismatchException.class);
         tryCatch("%0x", MissingFormatWidthException.class);
         tryCatch("%-x", MissingFormatWidthException.class);
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
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-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-        //---------------------------------------------------------------------
-        // %t
-        //
-        // Date/Time conversions applicable to Calendar, Date, and long.
-        //---------------------------------------------------------------------
-        test("%tA", "null", (Object)null);
-        test("%TA", "NULL", (Object)null);
+        //---------------------------------------------------------------------
+        // %t
+        //
+        // Date/Time conversions applicable to Calendar, Date, and long.
+        //---------------------------------------------------------------------
+        test("%tA", "null", (Object)null);
+        test("%TA", "NULL", (Object)null);
 
         //---------------------------------------------------------------------
         // %t - errors
         //---------------------------------------------------------------------
         tryCatch("%t", UnknownFormatConversionException.class);

@@ -1590,104 +443,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"), "");