aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/com/healthmarketscience/jackcess
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2018-11-20 02:01:46 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2018-11-20 02:01:46 +0000
commitd209a57058e44ab587cc3b1c7c3f77dd64ec49ec (patch)
tree1174391e67d174f8768bf7d41d57389fc36cece7 /src/test/java/com/healthmarketscience/jackcess
parent8c64c96af69182bfb64f98cebebfe73e3b1c111d (diff)
downloadjackcess-d209a57058e44ab587cc3b1c7c3f77dd64ec49ec.tar.gz
jackcess-d209a57058e44ab587cc3b1c7c3f77dd64ec49ec.zip
implement Format with predefined formats
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1226 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/test/java/com/healthmarketscience/jackcess')
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java59
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java4
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/impl/expr/NumberFormatterTest.java (renamed from src/test/java/com/healthmarketscience/jackcess/impl/NumberFormatterTest.java)2
3 files changed, 62 insertions, 3 deletions
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 8c015d8..132b788 100644
--- a/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java
+++ b/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java
@@ -263,6 +263,65 @@ public class DefaultFunctionsTest extends TestCase
assertEval("13:37", "=FormatDateTime(#1/1/1973 1:37:25 PM#,4)");
}
+ public void testFormat() throws Exception
+ {
+ assertEval("12345.6789", "=Format(12345.6789, 'General Number')");
+ assertEval("0.12345", "=Format(0.12345, 'General Number')");
+ assertEval("-12345.6789", "=Format(-12345.6789, 'General Number')");
+ assertEval("-0.12345", "=Format(-0.12345, 'General Number')");
+ assertEval("12345.6789", "=Format('12345.6789', 'General Number')");
+ assertEval("1678.9", "=Format('1.6789E+3', 'General Number')");
+ assertEval("37623.2916666667", "=Format(#01/02/2003 7:00:00 AM#, 'General Number')");
+ assertEval("foo", "=Format('foo', 'General Number')");
+
+ assertEval("12,345.68", "=Format(12345.6789, 'Standard')");
+ assertEval("0.12", "=Format(0.12345, 'Standard')");
+ assertEval("-12,345.68", "=Format(-12345.6789, 'Standard')");
+ assertEval("-0.12", "=Format(-0.12345, 'Standard')");
+
+ assertEval("12345.68", "=Format(12345.6789, 'Fixed')");
+ assertEval("0.12", "=Format(0.12345, 'Fixed')");
+ assertEval("-12345.68", "=Format(-12345.6789, 'Fixed')");
+ assertEval("-0.12", "=Format(-0.12345, 'Fixed')");
+
+ assertEval("$12,345.68", "=Format(12345.6789, 'Currency')");
+ assertEval("$0.12", "=Format(0.12345, 'Currency')");
+ assertEval("($12,345.68)", "=Format(-12345.6789, 'Currency')");
+ assertEval("($0.12)", "=Format(-0.12345, 'Currency')");
+
+ assertEval("1234567.89%", "=Format(12345.6789, 'Percent')");
+ assertEval("12.34%", "=Format(0.12345, 'Percent')");
+ assertEval("-1234567.89%", "=Format(-12345.6789, 'Percent')");
+ assertEval("-12.34%", "=Format(-0.12345, 'Percent')");
+
+ assertEval("1.23E+4", "=Format(12345.6789, 'Scientific')");
+ assertEval("1.23E-1", "=Format(0.12345, 'Scientific')");
+ assertEval("-1.23E+4", "=Format(-12345.6789, 'Scientific')");
+ assertEval("-1.23E-1", "=Format(-0.12345, 'Scientific')");
+
+ assertEval("Yes", "=Format(True, 'Yes/No')");
+ assertEval("No", "=Format(False, 'Yes/No')");
+ assertEval("True", "=Format(True, 'True/False')");
+ assertEval("False", "=Format(False, 'True/False')");
+ assertEval("On", "=Format(True, 'On/Off')");
+ assertEval("Off", "=Format(False, 'On/Off')");
+
+ assertEval("1/2/2003 7:00:00 AM", "=Format(#01/02/2003 7:00:00 AM#, 'General Date')");
+ assertEval("1/2/2003", "=Format(#01/02/2003#, 'General Date')");
+ assertEval("7:00:00 AM", "=Format(#7:00:00 AM#, 'General Date')");
+ assertEval("1/2/2003 7:00:00 AM", "=Format('37623.2916666667', 'General Date')");
+ assertEval("foo", "=Format('foo', 'General Date')");
+
+ assertEval("Thursday, January 02, 2003", "=Format(#01/02/2003 7:00:00 AM#, 'Long Date')");
+ assertEval("02-Jan-03", "=Format(#01/02/2003 7:00:00 AM#, 'Medium Date')");
+ assertEval("1/2/2003", "=Format(#01/02/2003 7:00:00 AM#, 'Short Date')");
+ assertEval("7:00:00 AM", "=Format(#01/02/2003 7:00:00 AM#, 'Long Time')");
+ assertEval("07:00 AM", "=Format(#01/02/2003 7:00:00 AM#, 'Medium Time')");
+ assertEval("07:00", "=Format(#01/02/2003 7:00:00 AM#, 'Short Time')");
+ assertEval("19:00", "=Format(#01/02/2003 7:00:00 PM#, 'Short Time')");
+
+ }
+
public void testNumberFuncs() throws Exception
{
assertEval(1, "=Abs(1)");
diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java
index 17ad3d7..c67dfe7 100644
--- a/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java
+++ b/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java
@@ -38,7 +38,7 @@ import com.healthmarketscience.jackcess.expr.ParseException;
import com.healthmarketscience.jackcess.expr.TemporalConfig;
import com.healthmarketscience.jackcess.expr.Value;
import com.healthmarketscience.jackcess.impl.BaseEvalContext;
-import com.healthmarketscience.jackcess.impl.NumberFormatter;
+import com.healthmarketscience.jackcess.impl.expr.NumberFormatter;
import junit.framework.TestCase;
/**
@@ -609,7 +609,7 @@ public class ExpressionatorTest extends TestCase
return new DecimalFormat(
formatStr, NumericConfig.US_NUMERIC_CONFIG.getDecimalFormatSymbols());
}
-
+
public FunctionLookup getFunctionLookup() {
return DefaultFunctions.LOOKUP;
}
diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/NumberFormatterTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/expr/NumberFormatterTest.java
index f69dca1..4d26c1b 100644
--- a/src/test/java/com/healthmarketscience/jackcess/impl/NumberFormatterTest.java
+++ b/src/test/java/com/healthmarketscience/jackcess/impl/expr/NumberFormatterTest.java
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package com.healthmarketscience.jackcess.impl;
+package com.healthmarketscience.jackcess.impl.expr;
import java.math.BigDecimal;