Fix warnings and inconsistent indents
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1646163 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6168a7999c
commit
e27afd1332
@ -30,99 +30,92 @@ import org.apache.poi.ss.formula.eval.StringEval;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Test case for TEXT()
|
* Test case for TEXT()
|
||||||
*
|
|
||||||
* @author Stephen Wolke (smwolke at geistig.com)
|
|
||||||
*/
|
*/
|
||||||
public final class TestText extends TestCase {
|
public final class TestText extends TestCase {
|
||||||
private static final TextFunction T = null;
|
public void testTextWithStringFirstArg() {
|
||||||
|
ValueEval strArg = new StringEval("abc");
|
||||||
|
ValueEval formatArg = new StringEval("abc");
|
||||||
|
ValueEval[] args = { strArg, formatArg };
|
||||||
|
ValueEval result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
|
||||||
|
assertEquals(ErrorEval.VALUE_INVALID, result);
|
||||||
|
}
|
||||||
|
|
||||||
public void testTextWithStringFirstArg() {
|
public void testTextWithDeciamlFormatSecondArg() {
|
||||||
|
ValueEval numArg = new NumberEval(321321.321);
|
||||||
|
ValueEval formatArg = new StringEval("#,###.00000");
|
||||||
|
ValueEval[] args = { numArg, formatArg };
|
||||||
|
ValueEval result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
|
||||||
|
char groupSeparator = new DecimalFormatSymbols(Locale.getDefault()).getGroupingSeparator();
|
||||||
|
char decimalSeparator = new DecimalFormatSymbols(Locale.getDefault()).getDecimalSeparator();
|
||||||
|
ValueEval testResult = new StringEval("321" + groupSeparator + "321" + decimalSeparator + "32100");
|
||||||
|
assertEquals(testResult.toString(), result.toString());
|
||||||
|
numArg = new NumberEval(321.321);
|
||||||
|
formatArg = new StringEval("00000.00000");
|
||||||
|
args[0] = numArg;
|
||||||
|
args[1] = formatArg;
|
||||||
|
result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
|
||||||
|
testResult = new StringEval("00321" + decimalSeparator + "32100");
|
||||||
|
assertEquals(testResult.toString(), result.toString());
|
||||||
|
|
||||||
ValueEval strArg = new StringEval("abc");
|
formatArg = new StringEval("$#.#");
|
||||||
ValueEval formatArg = new StringEval("abc");
|
args[1] = formatArg;
|
||||||
ValueEval[] args = { strArg, formatArg };
|
result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
|
||||||
ValueEval result = T.TEXT.evaluate(args, -1, (short)-1);
|
testResult = new StringEval("$321" + decimalSeparator + "3");
|
||||||
assertEquals(ErrorEval.VALUE_INVALID, result);
|
assertEquals(testResult.toString(), result.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTextWithDeciamlFormatSecondArg() {
|
public void testTextWithFractionFormatSecondArg() {
|
||||||
|
ValueEval numArg = new NumberEval(321.321);
|
||||||
|
ValueEval formatArg = new StringEval("# #/#");
|
||||||
|
ValueEval[] args = { numArg, formatArg };
|
||||||
|
ValueEval result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
|
||||||
|
ValueEval testResult = new StringEval("321 1/3");
|
||||||
|
assertEquals(testResult.toString(), result.toString());
|
||||||
|
|
||||||
ValueEval numArg = new NumberEval(321321.321);
|
formatArg = new StringEval("# #/##");
|
||||||
ValueEval formatArg = new StringEval("#,###.00000");
|
args[1] = formatArg;
|
||||||
ValueEval[] args = { numArg, formatArg };
|
result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
|
||||||
ValueEval result = T.TEXT.evaluate(args, -1, (short)-1);
|
testResult = new StringEval("321 26/81");
|
||||||
char groupSeparator = new DecimalFormatSymbols(Locale.getDefault()).getGroupingSeparator();
|
assertEquals(testResult.toString(), result.toString());
|
||||||
char decimalSeparator = new DecimalFormatSymbols(Locale.getDefault()).getDecimalSeparator();
|
|
||||||
ValueEval testResult = new StringEval("321" + groupSeparator + "321" + decimalSeparator + "32100");
|
|
||||||
assertEquals(testResult.toString(), result.toString());
|
|
||||||
numArg = new NumberEval(321.321);
|
|
||||||
formatArg = new StringEval("00000.00000");
|
|
||||||
args[0] = numArg;
|
|
||||||
args[1] = formatArg;
|
|
||||||
result = T.TEXT.evaluate(args, -1, (short)-1);
|
|
||||||
testResult = new StringEval("00321" + decimalSeparator + "32100");
|
|
||||||
assertEquals(testResult.toString(), result.toString());
|
|
||||||
|
|
||||||
formatArg = new StringEval("$#.#");
|
formatArg = new StringEval("#/##");
|
||||||
args[1] = formatArg;
|
args[1] = formatArg;
|
||||||
result = T.TEXT.evaluate(args, -1, (short)-1);
|
result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
|
||||||
testResult = new StringEval("$321" + decimalSeparator + "3");
|
testResult = new StringEval("26027/81");
|
||||||
assertEquals(testResult.toString(), result.toString());
|
assertEquals(testResult.toString(), result.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTextWithFractionFormatSecondArg() {
|
public void testTextWithDateFormatSecondArg() {
|
||||||
|
// Test with Java style M=Month
|
||||||
|
ValueEval numArg = new NumberEval(321.321);
|
||||||
|
ValueEval formatArg = new StringEval("dd:MM:yyyy hh:mm:ss");
|
||||||
|
ValueEval[] args = { numArg, formatArg };
|
||||||
|
ValueEval result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
|
||||||
|
ValueEval testResult = new StringEval("16:11:1900 07:42:14");
|
||||||
|
assertEquals(testResult.toString(), result.toString());
|
||||||
|
|
||||||
ValueEval numArg = new NumberEval(321.321);
|
// Excel also supports "m before h is month"
|
||||||
ValueEval formatArg = new StringEval("# #/#");
|
formatArg = new StringEval("dd:mm:yyyy hh:mm:ss");
|
||||||
ValueEval[] args = { numArg, formatArg };
|
args[1] = formatArg;
|
||||||
ValueEval result = T.TEXT.evaluate(args, -1, (short)-1);
|
result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
|
||||||
ValueEval testResult = new StringEval("321 1/3");
|
testResult = new StringEval("16:11:1900 07:42:14");
|
||||||
assertEquals(testResult.toString(), result.toString());
|
assertEquals(testResult.toString(), result.toString());
|
||||||
|
|
||||||
formatArg = new StringEval("# #/##");
|
// this line is intended to compute how "November" would look like in the current locale
|
||||||
args[1] = formatArg;
|
String november = new SimpleDateFormat("MMMM").format(new GregorianCalendar(2010,10,15).getTime());
|
||||||
result = T.TEXT.evaluate(args, -1, (short)-1);
|
|
||||||
testResult = new StringEval("321 26/81");
|
|
||||||
assertEquals(testResult.toString(), result.toString());
|
|
||||||
|
|
||||||
formatArg = new StringEval("#/##");
|
// Again with Java style
|
||||||
args[1] = formatArg;
|
formatArg = new StringEval("MMMM dd, yyyy");
|
||||||
result = T.TEXT.evaluate(args, -1, (short)-1);
|
args[1] = formatArg;
|
||||||
testResult = new StringEval("26027/81");
|
result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
|
||||||
assertEquals(testResult.toString(), result.toString());
|
testResult = new StringEval(november + " 16, 1900");
|
||||||
}
|
assertEquals(testResult.toString(), result.toString());
|
||||||
|
|
||||||
public void testTextWithDateFormatSecondArg() {
|
// And Excel style
|
||||||
// Test with Java style M=Month
|
formatArg = new StringEval("mmmm dd, yyyy");
|
||||||
ValueEval numArg = new NumberEval(321.321);
|
args[1] = formatArg;
|
||||||
ValueEval formatArg = new StringEval("dd:MM:yyyy hh:mm:ss");
|
result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
|
||||||
ValueEval[] args = { numArg, formatArg };
|
testResult = new StringEval(november + " 16, 1900");
|
||||||
ValueEval result = T.TEXT.evaluate(args, -1, (short)-1);
|
assertEquals(testResult.toString(), result.toString());
|
||||||
ValueEval testResult = new StringEval("16:11:1900 07:42:14");
|
}
|
||||||
assertEquals(testResult.toString(), result.toString());
|
|
||||||
|
|
||||||
// Excel also supports "m before h is month"
|
|
||||||
formatArg = new StringEval("dd:mm:yyyy hh:mm:ss");
|
|
||||||
args[1] = formatArg;
|
|
||||||
result = T.TEXT.evaluate(args, -1, (short)-1);
|
|
||||||
testResult = new StringEval("16:11:1900 07:42:14");
|
|
||||||
assertEquals(testResult.toString(), result.toString());
|
|
||||||
|
|
||||||
// this line is intended to compute how "November" would look like in the current locale
|
|
||||||
String november = new SimpleDateFormat("MMMM").format(new GregorianCalendar(2010,10,15).getTime());
|
|
||||||
|
|
||||||
// Again with Java style
|
|
||||||
formatArg = new StringEval("MMMM dd, yyyy");
|
|
||||||
args[1] = formatArg;
|
|
||||||
result = T.TEXT.evaluate(args, -1, (short)-1);
|
|
||||||
testResult = new StringEval(november + " 16, 1900");
|
|
||||||
assertEquals(testResult.toString(), result.toString());
|
|
||||||
|
|
||||||
// And Excel style
|
|
||||||
formatArg = new StringEval("mmmm dd, yyyy");
|
|
||||||
args[1] = formatArg;
|
|
||||||
result = T.TEXT.evaluate(args, -1, (short)-1);
|
|
||||||
testResult = new StringEval(november + " 16, 1900");
|
|
||||||
assertEquals(testResult.toString(), result.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user