diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2019-01-29 03:32:55 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2019-01-29 03:32:55 +0000 |
commit | f3c8bb34a4aad19a5879d193dc54bfe862bd94b1 (patch) | |
tree | 3df6f452663cae1b9c9d5ce0a623248ce4de6d44 /src/test/java/com/healthmarketscience/jackcess/impl | |
parent | ded1c6e0a1ee8dc6f6e716af048386c55d4dd450 (diff) | |
download | jackcess-f3c8bb34a4aad19a5879d193dc54bfe862bd94b1.tar.gz jackcess-f3c8bb34a4aad19a5879d193dc54bfe862bd94b1.zip |
add unit tests, fix bugs in custom formats
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/jdk8@1269 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/test/java/com/healthmarketscience/jackcess/impl')
-rw-r--r-- | src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java | 194 |
1 files changed, 182 insertions, 12 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 b9a764d..24f3c5b 100644 --- a/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java @@ -21,6 +21,7 @@ import java.time.LocalDateTime; import java.util.Calendar; import com.healthmarketscience.jackcess.expr.EvalException; +import junit.framework.AssertionFailedError; import junit.framework.TestCase; import static com.healthmarketscience.jackcess.impl.expr.ExpressionatorTest.eval; import static com.healthmarketscience.jackcess.impl.expr.ExpressionatorTest.toBD; @@ -251,6 +252,7 @@ public class DefaultFunctionsTest extends TestCase assertEval("-.123%", "=FormatPercent(-0.0012345,3,False)"); assertEval("$12,345.00", "=FormatCurrency(12345)"); + assertEval("($12,345.00)", "=FormatCurrency(-12345)"); assertEval("-$12.34", "=FormatCurrency(-12.345,-1,True,False)"); assertEval("$12", "=FormatCurrency(12.345,0,True,True)"); assertEval("($.123)", "=FormatCurrency(-0.12345,3,False)"); @@ -317,6 +319,7 @@ public class DefaultFunctionsTest extends TestCase 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("", "=Format('', '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')"); @@ -340,22 +343,189 @@ public class DefaultFunctionsTest extends TestCase assertEval("4 7:13:00 AM ttt this 'is' \"text\"", "=Format(#7:13:00 AM#, \"q c ttt \"\"this 'is' \"\"\"\"text\"\"\"\"\"\"\")"); assertEval("12/29/1899", "=Format('true', 'c')"); - assertEval("Tuesday, 00 Jan 2, 21:36:00", - "=Format('3.9', 'dddd, yy mmm d, hh:nn:ss')"); - assertEval("Tuesday, 00 Jan 01 2, 09:36:00 PM", - "=Format('3.9', 'dddd, yy mmm mm d, hh:nn:ss AMPM')"); + assertEval("Tuesday, 00 Jan 2, 21:36:00 Y", + "=Format('3.9', '*~dddd, yy mmm d, hh:nn:ss \\Y[Yellow]')"); + assertEval("Tuesday, 00 Jan 01/2, 09:36:00 PM", + "=Format('3.9', 'dddd, yy mmm mm/d, hh:nn:ss AMPM')"); assertEval("foo", "=Format('foo', 'dddd, yy mmm mm d, hh:nn:ss AMPM')"); - assertEval("p13.00blah", - "=Format('13', '\"p\"#.00#\"blah\"')"); - assertEval("-p13.00blah", - "=Format('-13', '\"p\"#.00#\"blah\";(\"p\"#.00#\"blah\")')"); - // assertEval("-p13.00blah", - // "=Format('-13', '\"p\"#.00#\"blah\"')"); - - + assertEvalFormat("';\\y;\\n'", + "foo", "'foo'", + "", "''", + "y", "True", + "n", "'0'", + "", "Null"); + + assertEvalFormat("';\"y\";!\\n;*~\\z[Blue];'", + "foo", "'foo'", + "", "''", + "y", "True", + "n", "'0'", + "z", "Null"); + + assertEvalFormat("'\"p\"#.00#\"blah\"'", + "p13.00blah", "13", + "-p13.00blah", "-13", + "p.00blah", "0", + "", "''", + "", "Null"); + + assertEvalFormat("'\"p\"#.00#\"blah\";(\"p\"#.00#\"blah\")'", + "p13.00blah", "13", + "(p13.00blah)", "-13", + "p.00blah", "0", + "(p1.00blah)", "True", + "p.00blah", "'false'", + "p37623.292blah", "#01/02/2003 7:00:00 AM#", + "p37623.292blah", "'01/02/2003 7:00:00 AM'", + "NotANumber", "'NotANumber'", + "", "''", + "", "Null"); + + assertEvalFormat("'\"p\"#.00#\"blah\";!(\"p\"#.00#\"blah\")[Red];\"zero\"'", + "p13.00blah", "13", + "(p13.00blah)", "-13", + "zero", "0", + "", "''", + "", "Null"); + + assertEvalFormat("'\"p\"#.00#\"blah\";(\"p\"#.00#\"blah\");\"zero\";\"yuck\"'", + "p13.00blah", "13", + "(p13.00blah)", "-13", + "zero", "0", + "", "''", + "yuck", "Null"); + + assertEvalFormat("'0.##;(0.###);\"zero\";\"yuck\"'", + "0.03", "0.03", + "zero", "0.003", + "(0.003)", "-0.003", + "zero", "-0.0003"); + + // FIXME, need to handle rounding w/ negatives + // FIXME, need to handle dangling decimal + // assertEvalFormat("'0.##;(0.###E+0)'", + // "0.03", "0.03", + // "(0.003)", "-0.0003", + + assertEvalFormat("'0.'", + "13.", "13", + "0.", "0.003", + "-45.", "-45", + "0.", "-0.003", + "0.", "0" + ); + + assertEvalFormat("'0.#'", + "13.", "13", + "0.3", "0.3", + "0.", "0.003", + "-45.", "-45", + "0.", "-0.003", + "0.", "0" + ); + + assertEvalFormat("'0'", + "13", "13", + "0", "0.003", + "-45", "-45", + "0", "-0.003", + "0", "0" + ); + + assertEvalFormat("'#'", + "13", "13", + "0", "0.003", + "-45", "-45", + "0", "-0.003" + // FIXME + // "", "0" + ); + + assertEvalFormat("'$0.0#'", + "$213.0", "213"); + + assertEvalFormat("'@'", + "foo", "'foo'", + "-13", "-13", + "0", "0", + "", "''", + "", "Null"); + + assertEvalFormat("'>@'", + "FOO", "'foo'", + "-13", "-13", + "0", "0", + "", "''", + "", "Null"); + + assertEvalFormat("'<@'", + "foo", "'FOO'", + "-13", "-13", + "0", "0", + "", "''", + "", "Null"); + + assertEvalFormat("'!>@'", + "O", "'foo'", + "3", "-13", + "0", "0", + "", "''", + "", "Null"); + + assertEvalFormat("'!>@[Red];\"empty\"'", + "O", "'foo'", + "3", "-13", + "0", "0", + "empty", "''", + "empty", "Null"); + + assertEvalFormat("'><@'", + "fOo", "'fOo'"); + + assertEvalFormat("'\\x@@@&&&\\y'", + "x fy", "'f'", + "x fooy", "'foo'", + "x foobay", "'fooba'", + "xfoobarybaz", "'foobarbaz'" + ); + + assertEvalFormat("'!\\x@@@&&&\\y'", + "xf y", "'f'", + "xfooy", "'foo'", + "xfoobay", "'fooba'", + "xbarbazy", "'foobarbaz'" + ); + + assertEvalFormat("'\\x&&&@@@\\y'", + "x fy", "'f'", + "xfooy", "'foo'", + "xfoobay", "'fooba'", + "xfoobarybaz", "'foobarbaz'" + ); + + assertEvalFormat("'!\\x&&&@@@\\y'", + "xf y", "'f'", + "xfoo y", "'foo'", + "xfooba y", "'fooba'", + "xbarbazy", "'foobarbaz'" + ); + } + private static void assertEvalFormat(String fmtStr, String... testStrs) { + for(int i = 0; i < testStrs.length; i+=2) { + String expected = testStrs[i]; + String val = testStrs[i + 1]; + + try { + assertEval(expected, + "=Format(" + val + ", " + fmtStr + ")"); + } catch(AssertionFailedError afe) { + throw new AssertionFailedError("Input " + val + ": " + + afe.getMessage()); + } + } } public void testNumberFuncs() throws Exception |