From 4cac6717d1a7ce11fab6c88bccf51fe50c1c6d45 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Tue, 19 Sep 2017 14:27:19 +0000 Subject: [PATCH] bug fixes and unit tests git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/exprs@1116 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../jackcess/impl/expr/DefaultFunctions.java | 6 +++--- .../impl/expr/DefaultFunctionsTest.java | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 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 0b5b4ff..969c027 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctions.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctions.java @@ -378,7 +378,7 @@ public class DefaultFunctions } }); - // FIXME, CSTR, CVAR + // FIXME, CVAR public static final Function INSTR = registerFunc(new FuncVar("InStr", 2, 4) { @Override @@ -495,7 +495,7 @@ public class DefaultFunctions return param1; } String str = param1.getAsString(); - int len = (int)Math.max(str.length(), param2.getAsLong()); + int len = (int)Math.min(str.length(), param2.getAsLong()); return BuiltinOperators.toValue(str.substring(0, len)); } }); @@ -508,7 +508,7 @@ public class DefaultFunctions } String str = param1.getAsString(); int strLen = str.length(); - int len = (int)Math.max(strLen, param2.getAsLong()); + int len = (int)Math.min(strLen, param2.getAsLong()); return BuiltinOperators.toValue(str.substring(strLen - len, strLen)); } }); 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 493795f..d422b72 100644 --- a/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java @@ -65,7 +65,28 @@ public class DefaultFunctionsTest extends TestCase assertEquals(14L, eval("=CByte(\"13.7\")")); assertEquals(new BigDecimal("57.1235"), eval("=CCur(\"57.12346\")")); assertEquals(new Double("57.12345"), eval("=CDbl(\"57.12345\")")); + assertEquals(new BigDecimal("57.123456789"), eval("=CDec(\"57.123456789\")")); + assertEquals(513L, eval("=CInt(\"513\")")); + assertEquals(514L, eval("=CInt(\"513.7\")")); + assertEquals(345513L, eval("=CLng(\"345513\")")); + assertEquals(345514L, eval("=CLng(\"345513.7\")")); + assertEquals(new Float("57.12345").doubleValue(), + eval("=CSng(\"57.12345\")")); + assertEquals("9786", eval("=CStr(9786)")); + assertEquals("-42", eval("=CStr(-42)")); + // FIXME, instr, instrrev + + assertEquals("FOOO", eval("=UCase(\"fOoO\")")); + assertEquals("fooo", eval("=LCase(\"fOoO\")")); + + assertEquals("bl", eval("=Left(\"blah\", 2)")); + assertEquals("", eval("=Left(\"blah\", 0)")); + assertEquals("blah", eval("=Left(\"blah\", 17)")); + + assertEquals("ah", eval("=Right(\"blah\", 2)")); + assertEquals("", eval("=Right(\"blah\", 0)")); + assertEquals("blah", eval("=Right(\"blah\", 17)")); } } -- 2.39.5