test/java/util/Formatter/Basic-X.java.template

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

*** 1,7 **** /* ! * Copyright (c) 2003, 2013, 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. --- 1,7 ---- /* ! * 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.
*** 49,65 **** --- 49,73 ---- 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);
*** 570,579 **** --- 578,595 ---- 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)); #else[short] #if[prim] //--------------------------------------------------------------------- // %d - int and long
*** 592,601 **** --- 608,627 ---- test("%010d", "0001234567", oneToSeven); test("%010d", "-001234567", negate(oneToSeven)); test("%(10d", " (1234567)", negate(oneToSeven)); test("%-10d", "1234567 ", oneToSeven); test("%-10d", "-1234567 ", negate(oneToSeven)); + // , variations: + test("% ,d", " 1,234,567", oneToSeven); + test("% ,d", "-1,234,567", negate(oneToSeven)); + test("%+,10d", "+1,234,567", oneToSeven); + test("%0,10d", "01,234,567", oneToSeven); + test("%0,10d", "-1,234,567", negate(oneToSeven)); + test("%(,10d", "(1,234,567)", negate(oneToSeven)); + test("%-,10d", "1,234,567 ", oneToSeven); + test("%-,10d", "-1,234,567", negate(oneToSeven)); + #end[prim] #end[short] #end[byte] //--------------------------------------------------------------------- // %d - errors
*** 779,788 **** --- 805,822 ---- 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);
*** 1037,1046 **** --- 1071,1088 ---- test("%3.0f", "10000", 10000.00); test("%3.0f", "100000", 100000.00); test("%3.0f", "1000000", 1000000.00); test("%3.0f", "10000000", 10000000.00); test("%3.0f", "100000000", 100000000.00); + test("%10.0f", " 1000000", 1000000.00); + test("%,10.0f", " 1,000,000", 1000000.00); + test("%,10.1f", "1,000,000.0", 1000000.00); + test("%,3.0f", "1,000,000", 1000000.00); + test("%,3.0f", "10,000,000", 10000000.00); + test("%,3.0f", "100,000,000", 100000000.00); + test("%,3.0f", "10,000,000", 10000000.00); + test("%,3.0f", "100,000,000", 100000000.00); #if[BigDecimal] //--------------------------------------------------------------------- // %f - BigDecimal //--------------------------------------------------------------------- test("%4.0f", " 99", new BigDecimal("99.19"));