1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
|
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
import java.util.Calendar;
import java.util.Locale;
import junit.framework.TestCase;
import org.apache.poi.hssf.usermodel.TestHSSFDataFormatter;
/**
* Tests of {@link DataFormatter}
*
* See {@link TestHSSFDataFormatter} too for
* more tests.
*/
public class TestDataFormatter extends TestCase {
/**
* Test that we use the specified locale when deciding
* how to format normal numbers
*/
public void testLocale() {
DataFormatter dfUS = new DataFormatter(Locale.US);
DataFormatter dfFR = new DataFormatter(Locale.FRENCH);
assertEquals("1234", dfUS.formatRawCellContents(1234, -1, "@"));
assertEquals("1234", dfFR.formatRawCellContents(1234, -1, "@"));
assertEquals("12.34", dfUS.formatRawCellContents(12.34, -1, "@"));
assertEquals("12,34", dfFR.formatRawCellContents(12.34, -1, "@"));
}
/**
* Ensure that colours get correctly
* zapped from within the format strings
*/
public void testColours() {
DataFormatter dfUS = new DataFormatter(Locale.US);
String[] formats = new String[] {
"##.##",
"[WHITE]##.##",
"[BLACK]##.##;[RED]-##.##",
"[COLOR11]##.##;[COLOR 43]-##.00",
};
for(String format : formats) {
assertEquals(
"Wrong format for: " + format,
"12.34",
dfUS.formatRawCellContents(12.343, -1, format)
);
assertEquals(
"Wrong format for: " + format,
"-12.34",
dfUS.formatRawCellContents(-12.343, -1, format)
);
}
// Ensure that random square brackets remain
assertEquals("12.34[a]", dfUS.formatRawCellContents(12.343, -1, "##.##[a]"));
assertEquals("[ab]12.34[x]", dfUS.formatRawCellContents(12.343, -1, "[ab]##.##[x]"));
}
public void testColoursAndBrackets() {
DataFormatter dfUS = new DataFormatter(Locale.US);
// Without currency symbols
String[] formats = new String[] {
"#,##0.00;[Blue](#,##0.00)",
};
for(String format : formats) {
assertEquals(
"Wrong format for: " + format,
"12.34",
dfUS.formatRawCellContents(12.343, -1, format)
);
assertEquals(
"Wrong format for: " + format,
"(12.34)",
dfUS.formatRawCellContents(-12.343, -1, format)
);
}
// With
formats = new String[] {
"$#,##0.00;[Red]($#,##0.00)"
};
for(String format : formats) {
assertEquals(
"Wrong format for: " + format,
"$12.34",
dfUS.formatRawCellContents(12.343, -1, format)
);
assertEquals(
"Wrong format for: " + format,
"($12.34)",
dfUS.formatRawCellContents(-12.343, -1, format)
);
}
}
/**
* Test how we handle negative and zeros.
* Note - some tests are disabled as DecimalFormat
* and Excel differ, and workarounds are not
* yet in place for all of these
*/
public void testNegativeZero() {
DataFormatter dfUS = new DataFormatter(Locale.US);
String all2dp = "00.00";
String alln1dp = "(00.0)";
String p1dp_n1dp = "00.0;(00.0)";
String p2dp_n1dp = "00.00;(00.0)";
String p2dp_n1dp_z0 = "00.00;(00.0);0";
String all2dpTSP = "00.00_x";
String p2dp_n2dpTSP = "00.00_x;(00.00)_x";
String p2dp_n1dpTSP = "00.00_x;(00.0)_x";
assertEquals("12.34", dfUS.formatRawCellContents(12.343, -1, all2dp));
assertEquals("12.34", dfUS.formatRawCellContents(12.343, -1, p2dp_n1dp));
assertEquals("12.34", dfUS.formatRawCellContents(12.343, -1, p2dp_n1dp_z0));
assertEquals("(12.3)", dfUS.formatRawCellContents(12.343, -1, alln1dp));
assertEquals("-(12.3)", dfUS.formatRawCellContents(-12.343, -1, alln1dp));
assertEquals("12.3", dfUS.formatRawCellContents(12.343, -1, p1dp_n1dp));
assertEquals("(12.3)", dfUS.formatRawCellContents(-12.343, -1, p1dp_n1dp));
assertEquals("-12.34", dfUS.formatRawCellContents(-12.343, -1, all2dp));
// TODO - fix case of negative subpattern differing from the
// positive one by more than just the prefix+suffix, which
// is all DecimalFormat supports...
// assertEquals("(12.3)", dfUS.formatRawCellContents(-12.343, -1, p2dp_n1dp));
// assertEquals("(12.3)", dfUS.formatRawCellContents(-12.343, -1, p2dp_n1dp_z0));
assertEquals("00.00", dfUS.formatRawCellContents(0, -1, all2dp));
assertEquals("00.00", dfUS.formatRawCellContents(0, -1, p2dp_n1dp));
assertEquals("0", dfUS.formatRawCellContents(0, -1, p2dp_n1dp_z0));
// Spaces are skipped
assertEquals("12.34", dfUS.formatRawCellContents(12.343, -1, all2dpTSP));
assertEquals("12.34", dfUS.formatRawCellContents(12.343, -1, p2dp_n2dpTSP));
assertEquals("(12.34)", dfUS.formatRawCellContents(-12.343, -1, p2dp_n2dpTSP));
// assertEquals("12.34", dfUS.formatRawCellContents(12.343, -1, p2dp_n1dpTSP));
// assertEquals("(12.3)", dfUS.formatRawCellContents(-12.343, -1, p2dp_n1dpTSP));
}
/**
* Test that we correctly handle fractions in the
* format string, eg # #/#
*/
public void testFractions() {
DataFormatter dfUS = new DataFormatter(Locale.US);
// Excel often prefers "# #/#"
assertEquals("321 1/3", dfUS.formatRawCellContents(321.321, -1, "# #/#"));
assertEquals("321 26/81", dfUS.formatRawCellContents(321.321, -1, "# #/##"));
assertEquals("26027/81", dfUS.formatRawCellContents(321.321, -1, "#/##"));
// OOo seems to like the "# ?/?" form
assertEquals("321 1/3", dfUS.formatRawCellContents(321.321, -1, "# ?/?"));
assertEquals("321 26/81", dfUS.formatRawCellContents(321.321, -1, "# ?/??"));
assertEquals("26027/81", dfUS.formatRawCellContents(321.321, -1, "?/??"));
}
/**
* Test that _x (blank with the space taken by "x")
* and *x (fill to the column width with "x"s) are
* correctly ignored by us.
*/
public void testPaddingSpaces() {
DataFormatter dfUS = new DataFormatter(Locale.US);
assertEquals("12.34", dfUS.formatRawCellContents(12.343, -1, "##.##_ "));
assertEquals("12.34", dfUS.formatRawCellContents(12.343, -1, "##.##_1"));
assertEquals("12.34", dfUS.formatRawCellContents(12.343, -1, "##.##_)"));
assertEquals("12.34", dfUS.formatRawCellContents(12.343, -1, "_-##.##"));
assertEquals("12.34", dfUS.formatRawCellContents(12.343, -1, "##.##* "));
assertEquals("12.34", dfUS.formatRawCellContents(12.343, -1, "##.##*1"));
assertEquals("12.34", dfUS.formatRawCellContents(12.343, -1, "##.##*)"));
assertEquals("12.34", dfUS.formatRawCellContents(12.343, -1, "*-##.##"));
}
/**
* DataFormatter is the CSV mode preserves spaces
*/
public void testPaddingSpacesCSV() {
DataFormatter dfUS = new DataFormatter(Locale.US, true);
assertEquals("12.34 ", dfUS.formatRawCellContents(12.343, -1, "##.##_ "));
assertEquals("-12.34 ", dfUS.formatRawCellContents(-12.343, -1, "##.##_ "));
assertEquals(". ", dfUS.formatRawCellContents(0.0, -1, "##.##_ "));
assertEquals("12.34 ", dfUS.formatRawCellContents(12.343, -1, "##.##_1"));
assertEquals("-12.34 ", dfUS.formatRawCellContents(-12.343, -1, "##.##_1"));
assertEquals(". ", dfUS.formatRawCellContents(0.0, -1, "##.##_1"));
assertEquals("12.34 ", dfUS.formatRawCellContents(12.343, -1, "##.##_)"));
assertEquals("-12.34 ", dfUS.formatRawCellContents(-12.343, -1, "##.##_)"));
assertEquals(". ", dfUS.formatRawCellContents(0.0, -1, "##.##_)"));
assertEquals(" 12.34", dfUS.formatRawCellContents(12.343, -1, "_-##.##"));
assertEquals("- 12.34", dfUS.formatRawCellContents(-12.343, -1, "_-##.##"));
assertEquals(" .", dfUS.formatRawCellContents(0.0, -1, "_-##.##"));
assertEquals("12.34", dfUS.formatRawCellContents(12.343, -1, "##.##* "));
assertEquals("-12.34", dfUS.formatRawCellContents(-12.343, -1, "##.##* "));
assertEquals(".", dfUS.formatRawCellContents(0.0, -1, "##.##* "));
assertEquals("12.34", dfUS.formatRawCellContents(12.343, -1, "##.##*1"));
assertEquals("-12.34", dfUS.formatRawCellContents(-12.343, -1, "##.##*1"));
assertEquals(".", dfUS.formatRawCellContents(0.0, -1, "##.##*1"));
assertEquals("12.34", dfUS.formatRawCellContents(12.343, -1, "##.##*)"));
assertEquals("-12.34", dfUS.formatRawCellContents(-12.343, -1, "##.##*)"));
assertEquals(".", dfUS.formatRawCellContents(0.0, -1, "##.##*)"));
assertEquals("12.34", dfUS.formatRawCellContents(12.343, -1, "*-##.##"));
assertEquals("-12.34", dfUS.formatRawCellContents(-12.343, -1, "*-##.##"));
assertEquals(".", dfUS.formatRawCellContents(0.0, -1, "*-##.##"));
}
/**
* Test that the special Excel month format MMMMM
* gets turned into the first letter of the month
*/
public void testMMMMM() {
DataFormatter dfUS = new DataFormatter(Locale.US);
Calendar c = Calendar.getInstance();
c.set(Calendar.MILLISECOND, 0);
c.set(2010, 5, 1, 2, 0, 0);
assertEquals("2010-J-1 2:00:00", dfUS.formatRawCellContents(
DateUtil.getExcelDate(c, false), -1, "YYYY-MMMMM-D h:mm:ss"
));
}
/**
* Tests that we do AM/PM handling properly
*/
public void testAMPM() {
DataFormatter dfUS = new DataFormatter(Locale.US);
assertEquals("06:00", dfUS.formatRawCellContents(0.25, -1, "hh:mm"));
assertEquals("18:00", dfUS.formatRawCellContents(0.75, -1, "hh:mm"));
assertEquals("06:00 AM", dfUS.formatRawCellContents(0.25, -1, "hh:mm AM/PM"));
assertEquals("06:00 PM", dfUS.formatRawCellContents(0.75, -1, "hh:mm AM/PM"));
assertEquals("1904-01-01 06:00:00 AM", dfUS.formatRawCellContents(0.25, -1, "yyyy-mm-dd hh:mm:ss AM/PM", true));
assertEquals("1904-01-01 06:00:00 PM", dfUS.formatRawCellContents(0.75, -1, "yyyy-mm-dd hh:mm:ss AM/PM", true));
}
/**
* Test that we can handle elapsed time,
* eg formatting 1 day 4 hours as 28 hours
*/
public void testElapsedTime() {
DataFormatter dfUS = new DataFormatter(Locale.US);
double hour = 1.0/24.0;
assertEquals("01:00", dfUS.formatRawCellContents(1*hour, -1, "hh:mm"));
assertEquals("05:00", dfUS.formatRawCellContents(5*hour, -1, "hh:mm"));
assertEquals("20:00", dfUS.formatRawCellContents(20*hour, -1, "hh:mm"));
assertEquals("23:00", dfUS.formatRawCellContents(23*hour, -1, "hh:mm"));
assertEquals("00:00", dfUS.formatRawCellContents(24*hour, -1, "hh:mm"));
assertEquals("02:00", dfUS.formatRawCellContents(26*hour, -1, "hh:mm"));
assertEquals("20:00", dfUS.formatRawCellContents(44*hour, -1, "hh:mm"));
assertEquals("02:00", dfUS.formatRawCellContents(50*hour, -1, "hh:mm"));
assertEquals("01:00", dfUS.formatRawCellContents(1*hour, -1, "[hh]:mm"));
assertEquals("05:00", dfUS.formatRawCellContents(5*hour, -1, "[hh]:mm"));
assertEquals("20:00", dfUS.formatRawCellContents(20*hour, -1, "[hh]:mm"));
assertEquals("23:00", dfUS.formatRawCellContents(23*hour, -1, "[hh]:mm"));
assertEquals("24:00", dfUS.formatRawCellContents(24*hour, -1, "[hh]:mm"));
assertEquals("26:00", dfUS.formatRawCellContents(26*hour, -1, "[hh]:mm"));
assertEquals("44:00", dfUS.formatRawCellContents(44*hour, -1, "[hh]:mm"));
assertEquals("50:00", dfUS.formatRawCellContents(50*hour, -1, "[hh]:mm"));
assertEquals("01", dfUS.formatRawCellContents(1*hour, -1, "[hh]"));
assertEquals("05", dfUS.formatRawCellContents(5*hour, -1, "[hh]"));
assertEquals("20", dfUS.formatRawCellContents(20*hour, -1, "[hh]"));
assertEquals("23", dfUS.formatRawCellContents(23*hour, -1, "[hh]"));
assertEquals("24", dfUS.formatRawCellContents(24*hour, -1, "[hh]"));
assertEquals("26", dfUS.formatRawCellContents(26*hour, -1, "[hh]"));
assertEquals("44", dfUS.formatRawCellContents(44*hour, -1, "[hh]"));
assertEquals("50", dfUS.formatRawCellContents(50*hour, -1, "[hh]"));
double minute = 1.0/24.0/60.0;
assertEquals("01:00", dfUS.formatRawCellContents(1*minute, -1, "[mm]:ss"));
assertEquals("05:00", dfUS.formatRawCellContents(5*minute, -1, "[mm]:ss"));
assertEquals("20:00", dfUS.formatRawCellContents(20*minute, -1, "[mm]:ss"));
assertEquals("23:00", dfUS.formatRawCellContents(23*minute, -1, "[mm]:ss"));
assertEquals("24:00", dfUS.formatRawCellContents(24*minute, -1, "[mm]:ss"));
assertEquals("26:00", dfUS.formatRawCellContents(26*minute, -1, "[mm]:ss"));
assertEquals("44:00", dfUS.formatRawCellContents(44*minute, -1, "[mm]:ss"));
assertEquals("50:00", dfUS.formatRawCellContents(50*minute, -1, "[mm]:ss"));
assertEquals("59:00", dfUS.formatRawCellContents(59*minute, -1, "[mm]:ss"));
assertEquals("60:00", dfUS.formatRawCellContents(60*minute, -1, "[mm]:ss"));
assertEquals("61:00", dfUS.formatRawCellContents(61*minute, -1, "[mm]:ss"));
assertEquals("119:00", dfUS.formatRawCellContents(119*minute, -1, "[mm]:ss"));
assertEquals("120:00", dfUS.formatRawCellContents(120*minute, -1, "[mm]:ss"));
assertEquals("121:00", dfUS.formatRawCellContents(121*minute, -1, "[mm]:ss"));
assertEquals("01", dfUS.formatRawCellContents(1*minute, -1, "[mm]"));
assertEquals("05", dfUS.formatRawCellContents(5*minute, -1, "[mm]"));
assertEquals("20", dfUS.formatRawCellContents(20*minute, -1, "[mm]"));
assertEquals("23", dfUS.formatRawCellContents(23*minute, -1, "[mm]"));
assertEquals("24", dfUS.formatRawCellContents(24*minute, -1, "[mm]"));
assertEquals("26", dfUS.formatRawCellContents(26*minute, -1, "[mm]"));
assertEquals("44", dfUS.formatRawCellContents(44*minute, -1, "[mm]"));
assertEquals("50", dfUS.formatRawCellContents(50*minute, -1, "[mm]"));
assertEquals("59", dfUS.formatRawCellContents(59*minute, -1, "[mm]"));
assertEquals("60", dfUS.formatRawCellContents(60*minute, -1, "[mm]"));
assertEquals("61", dfUS.formatRawCellContents(61*minute, -1, "[mm]"));
assertEquals("119", dfUS.formatRawCellContents(119*minute, -1, "[mm]"));
assertEquals("120", dfUS.formatRawCellContents(120*minute, -1, "[mm]"));
assertEquals("121", dfUS.formatRawCellContents(121*minute, -1, "[mm]"));
double second = 1.0/24.0/60.0/60.0;
assertEquals("86400", dfUS.formatRawCellContents(86400*second, -1, "[ss]"));
assertEquals("01", dfUS.formatRawCellContents(1*second, -1, "[ss]"));
assertEquals("05", dfUS.formatRawCellContents(5*second, -1, "[ss]"));
assertEquals("20", dfUS.formatRawCellContents(20*second, -1, "[ss]"));
assertEquals("23", dfUS.formatRawCellContents(23*second, -1, "[ss]"));
assertEquals("24", dfUS.formatRawCellContents(24*second, -1, "[ss]"));
assertEquals("26", dfUS.formatRawCellContents(26*second, -1, "[ss]"));
assertEquals("44", dfUS.formatRawCellContents(44*second, -1, "[ss]"));
assertEquals("50", dfUS.formatRawCellContents(50*second, -1, "[ss]"));
assertEquals("59", dfUS.formatRawCellContents(59*second, -1, "[ss]"));
assertEquals("60", dfUS.formatRawCellContents(60*second, -1, "[ss]"));
assertEquals("61", dfUS.formatRawCellContents(61*second, -1, "[ss]"));
assertEquals("119", dfUS.formatRawCellContents(119*second, -1, "[ss]"));
assertEquals("120", dfUS.formatRawCellContents(120*second, -1, "[ss]"));
assertEquals("121", dfUS.formatRawCellContents(121*second, -1, "[ss]"));
boolean jdk_1_5 = System.getProperty("java.vm.version").startsWith("1.5");
if(!jdk_1_5) {
// YK: the tests below were written under JDK 1.6 and assume that
// the rounding mode in the underlying decimal formatters is HALF_UP
// It is not so JDK 1.5 where the default rounding mode is HALV_EVEN and cannot be changed.
assertEquals("27:18:08", dfUS.formatRawCellContents(1.1376, -1, "[h]:mm:ss"));
assertEquals("28:48:00", dfUS.formatRawCellContents(1.2, -1, "[h]:mm:ss"));
assertEquals("29:31:12", dfUS.formatRawCellContents(1.23, -1, "[h]:mm:ss"));
assertEquals("31:26:24", dfUS.formatRawCellContents(1.31, -1, "[h]:mm:ss"));
assertEquals("27:18:08", dfUS.formatRawCellContents(1.1376, -1, "[hh]:mm:ss"));
assertEquals("28:48:00", dfUS.formatRawCellContents(1.2, -1, "[hh]:mm:ss"));
assertEquals("29:31:12", dfUS.formatRawCellContents(1.23, -1, "[hh]:mm:ss"));
assertEquals("31:26:24", dfUS.formatRawCellContents(1.31, -1, "[hh]:mm:ss"));
assertEquals("57:07.2", dfUS.formatRawCellContents(.123, -1, "mm:ss.0;@"));
assertEquals("57:41.8", dfUS.formatRawCellContents(.1234, -1, "mm:ss.0;@"));
assertEquals("57:41.76", dfUS.formatRawCellContents(.1234, -1, "mm:ss.00;@"));
assertEquals("57:41.760", dfUS.formatRawCellContents(.1234, -1, "mm:ss.000;@"));
assertEquals("24:00.0", dfUS.formatRawCellContents(123456.6, -1, "mm:ss.0"));
}
}
public void testDateWindowing() {
DataFormatter dfUS = new DataFormatter(Locale.US);
assertEquals("1899-12-31 00:00:00", dfUS.formatRawCellContents(0.0, -1, "yyyy-mm-dd hh:mm:ss"));
assertEquals("1899-12-31 00:00:00", dfUS.formatRawCellContents(0.0, -1, "yyyy-mm-dd hh:mm:ss", false));
assertEquals("1904-01-01 00:00:00", dfUS.formatRawCellContents(0.0, -1, "yyyy-mm-dd hh:mm:ss", true));
}
public void testScientificNotation() {
DataFormatter dfUS = new DataFormatter(Locale.US);
assertEquals("1.23E+01", dfUS.formatRawCellContents(12.343, -1, "0.00E+00"));
assertEquals("-1.23E+01", dfUS.formatRawCellContents(-12.343, -1, "0.00E+00"));
assertEquals("0.00E+00", dfUS.formatRawCellContents(0.0, -1, "0.00E+00"));
}
public void testInvalidDate() {
DataFormatter df1 = new DataFormatter(Locale.US);
assertEquals("-1.0", df1.formatRawCellContents(-1, -1, "mm/dd/yyyy"));
DataFormatter df2 = new DataFormatter(Locale.US, true);
assertEquals("###############################################################################################################################################################################################################################################################",
df2.formatRawCellContents(-1, -1, "mm/dd/yyyy"));
}
public void testEscapes() {
DataFormatter dfUS = new DataFormatter(Locale.US);
assertEquals("1901-01-01", dfUS.formatRawCellContents(367.0, -1, "yyyy-mm-dd"));
assertEquals("1901-01-01", dfUS.formatRawCellContents(367.0, -1, "yyyy\\-mm\\-dd"));
assertEquals("1901.01.01", dfUS.formatRawCellContents(367.0, -1, "yyyy.mm.dd"));
assertEquals("1901.01.01", dfUS.formatRawCellContents(367.0, -1, "yyyy\\.mm\\.dd"));
assertEquals("1901/01/01", dfUS.formatRawCellContents(367.0, -1, "yyyy/mm/dd"));
assertEquals("1901/01/01", dfUS.formatRawCellContents(367.0, -1, "yyyy\\/mm\\/dd"));
}
public void testOther() {
DataFormatter dfUS = new DataFormatter(Locale.US, true);
assertEquals(" 12.34 ", dfUS.formatRawCellContents(12.34, -1, "_-* #,##0.00_-;-* #,##0.00_-;_-* \"-\"??_-;_-@_-"));
assertEquals("-12.34 ", dfUS.formatRawCellContents(-12.34, -1, "_-* #,##0.00_-;-* #,##0.00_-;_-* \"-\"??_-;_-@_-"));
assertEquals(" - ", dfUS.formatRawCellContents(0.0, -1, "_-* #,##0.00_-;-* #,##0.00_-;_-* \"-\"??_-;_-@_-"));
assertEquals(" $- ", dfUS.formatRawCellContents(0.0, -1, "_-$* #,##0.00_-;-$* #,##0.00_-;_-$* \"-\"??_-;_-@_-"));
}
/**
* TODO Fix these so that they work
*/
public void DISABLEDtestCustomFormats() {
DataFormatter dfUS = new DataFormatter(Locale.US, true);
String fmt;
fmt = "\"At\" H:MM AM/PM \"on\" DDDD MMMM D\",\" YYYY";
assertEquals(
"At 4:20 AM on Thursday May 17, 2007",
dfUS.formatRawCellContents(39219.1805636921, -1, fmt)
);
fmt = "0 \"dollars and\" .00 \"cents\"";
assertEquals("19 dollars and .99 cents", dfUS.formatRawCellContents(19.99, -1, fmt));
}
}
|