aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2018-11-08 23:09:28 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2018-11-08 23:09:28 +0000
commitfedeb0bc35e48304f17031c8e3f42490fed41fd6 (patch)
tree295bd8b1fd855aabb08b96f758bf9eb6d850d9f4
parenta2a57f1c3ca0efa319270ad3bcac00d269f611dc (diff)
downloadjackcess-fedeb0bc35e48304f17031c8e3f42490fed41fd6.tar.gz
jackcess-fedeb0bc35e48304f17031c8e3f42490fed41fd6.zip
fill out remaining tests for FormatNumber
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1219 f203690c-595d-4dc9-a70b-905162fa7fd2
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctions.java7
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java13
2 files changed, 18 insertions, 2 deletions
diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctions.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctions.java
index 2f71718..132daeb 100644
--- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctions.java
+++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctions.java
@@ -310,9 +310,12 @@ public class DefaultFunctions
}
if(negParens) {
- fmt.append(";(#)");
+ // the javadocs claim the second pattern does not need to be fully
+ // defined, but it doesn't seem to work that way
+ String mainPat = fmt.toString();
+ fmt.append(";(").append(mainPat).append(")");
}
-
+
// Note, DecimalFormat rounding mode uses HALF_EVEN by default
DecimalFormat df = new DecimalFormat(
fmt.toString(), cfg.getDecimalFormatSymbols());
diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java
index d02aa15..163f0f2 100644
--- a/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java
+++ b/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java
@@ -225,12 +225,24 @@ public class DefaultFunctionsTest extends TestCase
assertEval("12,345.00", "=FormatNumber(12345)");
assertEval("0.12", "=FormatNumber(0.12345)");
assertEval("12.34", "=FormatNumber(12.345)");
+ assertEval("-12,345.00", "=FormatNumber(-12345)");
+ assertEval("-0.12", "=FormatNumber(-0.12345)");
+ assertEval("-12.34", "=FormatNumber(-12.345)");
assertEval("12,345.000", "=FormatNumber(12345,3)");
assertEval("0.123", "=FormatNumber(0.12345,3)");
assertEval("12.345", "=FormatNumber(12.345,3)");
assertEval("12,345", "=FormatNumber(12345,0)");
assertEval("0", "=FormatNumber(0.12345,0)");
assertEval("12", "=FormatNumber(12.345,0)");
+ assertEval("0.123", "=FormatNumber(0.12345,3,True)");
+ assertEval(".123", "=FormatNumber(0.12345,3,False)");
+ assertEval("-0.123", "=FormatNumber(-0.12345,3,True)");
+ assertEval("-.123", "=FormatNumber(-0.12345,3,False)");
+ assertEval("-12.34", "=FormatNumber(-12.345,-1,True,False)");
+ assertEval("(12.34)", "=FormatNumber(-12.345,-1,True,True)");
+ assertEval("(12)", "=FormatNumber(-12.345,0,True,True)");
+ assertEval("12,345.00", "=FormatNumber(12345,-1,-2,-2,True)");
+ assertEval("12345.00", "=FormatNumber(12345,-1,-2,-2,False)");
}
public void testNumberFuncs() throws Exception
@@ -508,6 +520,7 @@ public class DefaultFunctionsTest extends TestCase
try {
assertEquals(expected, eval(exprStr));
} catch(Error e) {
+ // Convenience for adding new tests
// System.err.println("[ERROR] " + e);
throw e;
}