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