/* * Copyright (c) 2003, 2022, 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. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* Type-specific source code for unit test * * Regenerate the BasicX classes via genBasic.sh whenever this file changes. * We check in the generated source files so that the test tree can be used * independently of the rest of the source tree.
*/
// -- This file was mechanically generated: Do not edit! -- //
// Any characters not explicitly defined as conversions, date/time // conversion suffixes, or flags are illegal and are reserved for // future extensions. Use of such a character in a format string will // cause an UnknownFormatConversionException or // UnknownFormatFlagsException to be thrown.
tryCatch("%q", UnknownFormatConversionException.class);
tryCatch("%t&", UnknownFormatConversionException.class);
tryCatch("%&d", UnknownFormatConversionException.class);
tryCatch("%^b", UnknownFormatConversionException.class);
//--------------------------------------------------------------------- // Formatter.java class javadoc examples //---------------------------------------------------------------------
test(Locale.FRANCE, "e = %+10.4f", "e = +2,7183", Math.E);
test("%4$2s %3$2s %2$2s %1$2s", " d c b a", "a", "b", "c", "d");
test("Amount gained or lost since last statement: $ %,(.2f", "Amount gained or lost since last statement: $ (6,217.58)",
(new BigDecimal("-6217.58")));
Calendar c = new GregorianCalendar(1969, JULY, 20, 16, 17, 0);
testSysOut("Local time: %tT", "Local time: 16:17:00", c);
test("Unable to open file '%1$s': %2$s", "Unable to open file 'food': No such file or directory", "food", "No such file or directory");
Calendar duke = new GregorianCalendar(1995, MAY, 23, 19, 48, 34);
duke.set(Calendar.MILLISECOND, 584);
test("Duke's Birthday: %1$tB %1$te, %1$tY", "Duke's Birthday: May 23, 1995",
duke);
test("Duke's Birthday: %1$tB %1$te, %1$tY", "Duke's Birthday: May 23, 1995",
duke.getTime());
test("Duke's Birthday: %1$tB %1$te, %1$tY", "Duke's Birthday: May 23, 1995",
duke.getTimeInMillis());
test("%4$s %3$s %2$s %1$s %4$s %3$s %2$s %1$s", "d c b a d c b a", "a", "b", "c", "d");
test("%s %s %, "a b b b", "a", "b", "c", "d");
test("%s %s %s %s", "a b c d", "a", "b", "c", "d");
test("%2$s %s %, "b a a b", "a", "b", "c", "d");
// Boolean.java hardcodes the Strings for "true" and "false", so no // localization is possible.
test(Locale.FRANCE, "%b", "true", true);
test(Locale.FRANCE, "%b", "false", false);
// If you pass in a single array to a varargs method, the compiler // uses it as the array of arguments rather than treating it as a // single array-type argument.
test("%b", "false", (Object[])new String[2]);
test("%b", "true", new String[2], new String[2]);
int [] ia = { 1, 2, 3 };
test("%b", "true", ia);
//--------------------------------------------------------------------- // %b - errors //---------------------------------------------------------------------
tryCatch("%#b", FormatFlagsConversionMismatchException.class);
tryCatch("%-b", MissingFormatWidthException.class); // correct or side-effect of implementation?
tryCatch("%.b", UnknownFormatConversionException.class);
tryCatch("%,b", FormatFlagsConversionMismatchException.class);
//--------------------------------------------------------------------- // %c // // General conversion applicable to any argument. //---------------------------------------------------------------------
test("%c", "i", 'i');
test("%C", "I", 'i');
test("%4c", " i", 'i');
test("%-4c", "i ", 'i');
test("%4C", " I", 'i');
test("%-4C", "I ", 'i');
test("%c", "i", Character.valueOf('i'));
test("%c", "H", (byte) 72);
test("%c", "i", (short) 105);
test("%c", "!", (int) 33);
test("%c", "\u007F", Byte.MAX_VALUE);
test("%c", new String(Character.toChars(Short.MAX_VALUE)), Short.MAX_VALUE);
test("%c", "null", (Object) null);
test("%3.0e", "1e-06", new BigDecimal("0.000001"));
test("%3.0e", "1e-05", new BigDecimal("0.00001"));
test("%3.0e", "1e-04", new BigDecimal("0.0001"));
test("%3.0e", "1e-03", new BigDecimal("0.001"));
test("%3.0e", "1e-02", new BigDecimal("0.01"));
test("%3.0e", "1e-01", new BigDecimal("0.1"));
test("%3.0e", "9e-01", new BigDecimal("0.9"));
test("%3.1e", "9.0e-01", new BigDecimal("0.9"));
test("%3.0e", "1e+00", new BigDecimal("1.00"));
test("%3.0e", "1e+01", new BigDecimal("10.00"));
test("%3.0e", "1e+02", new BigDecimal("99.19"));
test("%3.1e", "9.9e+01", new BigDecimal("99.19"));
test("%3.0e", "1e+02", new BigDecimal("99.99"));
test("%3.0e", "1e+02", new BigDecimal("100.00"));
test("%#3.0e", "1.e+03", new BigDecimal("1000.00"));
test("%3.0e", "1e+04", new BigDecimal("10000.00"));
test("%3.0e", "1e+05", new BigDecimal("100000.00"));
test("%3.0e", "1e+06", new BigDecimal("1000000.00"));
test("%3.0e", "1e+07", new BigDecimal("10000000.00"));
test("%3.0e", "1e+08", new BigDecimal("100000000.00"));
test("%3.0g", "1e-06", new BigDecimal("0.000001"));
test("%3.0g", "1e-05", new BigDecimal("0.00001"));
test("%3.0g", "0.0001", new BigDecimal("0.0001"));
test("%3.0g", "0.001", new BigDecimal("0.001"));
test("%3.3g", "0.00100", new BigDecimal("0.001"));
test("%3.4g", "0.001000", new BigDecimal("0.001"));
test("%3.0g", "0.01", new BigDecimal("0.01"));
test("%3.0g", "0.1", new BigDecimal("0.1"));
test("%3.0g", "0.9", new BigDecimal("0.9"));
test("%3.1g", "0.9", new BigDecimal("0.9"));
test("%3.0g", " 1", new BigDecimal("1.00"));
test("%3.2g", " 10", new BigDecimal("10.00"));
test("%3.0g", "1e+01", new BigDecimal("10.00"));
test("%3.0g", "1e+02", new BigDecimal("99.19"));
test("%3.1g", "1e+02", new BigDecimal("99.19"));
test("%3.2g", " 99", new BigDecimal("99.19"));
test("%3.0g", "1e+02", new BigDecimal("99.99"));
test("%3.0g", "1e+02", new BigDecimal("100.00"));
test("%3.0g", "1e+03", new BigDecimal("1000.00"));
test("%3.0g", "1e+04", new BigDecimal("10000.00"));
test("%3.0g", "1e+05", new BigDecimal("100000.00"));
test("%3.0g", "1e+06", new BigDecimal("1000000.00"));
test("%3.0g", "1e+07", new BigDecimal("10000000.00"));
test("%3.9g", "100000000", new BigDecimal("100000000.00"));
test("%3.10g", "100000000.0", new BigDecimal("100000000.00"));
tryCatch("%%%", UnknownFormatConversionException.class); // perhaps an IllegalFormatArgumentIndexException should be defined?
tryCatch("%<%", IllegalFormatFlagsException.class);
}
}
¤ Dauer der Verarbeitung: 0.5 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.