From fdeff8480b3b57f72a42659c30369b6d7a1a9299 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Fri, 18 Nov 2016 00:03:34 +0000 Subject: reorg of expression classes git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/exprs@1058 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../jackcess/impl/expr/ExpressionatorTest.java | 130 +++++++++++++++++++++ .../jackcess/util/ExpressionatorTest.java | 128 -------------------- 2 files changed, 130 insertions(+), 128 deletions(-) create mode 100644 src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java delete mode 100644 src/test/java/com/healthmarketscience/jackcess/util/ExpressionatorTest.java (limited to 'src/test') diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java new file mode 100644 index 0000000..c7d2edc --- /dev/null +++ b/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java @@ -0,0 +1,130 @@ +/* +Copyright (c) 2016 James Ahlborn + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package com.healthmarketscience.jackcess.impl.expr; + +import junit.framework.TestCase; + +import com.healthmarketscience.jackcess.expr.Expression; + +/** + * + * @author James Ahlborn + */ +public class ExpressionatorTest extends TestCase +{ + + public ExpressionatorTest(String name) { + super(name); + } + + + public void testParseSimpleExprs() throws Exception + { + validateExpr("\"A\"", "{\"A\"}"); + + validateExpr("13", "{13}"); + + validateExpr("-42", "{-42}"); + + doTestSimpleBinOp("EBinaryOp", "+", "-", "*", "/", "\\", "^", "&", "Mod"); + doTestSimpleBinOp("ECompOp", "<", "<=", ">", ">=", "=", "<>"); + doTestSimpleBinOp("ELogicalOp", "And", "Or", "Eqv", "Xor", "Imp"); + + for(String constStr : new String[]{"True", "False", "Null"}) { + validateExpr(constStr, "{" + constStr + "}"); + } + + validateExpr("[Field1]", "{[Field1]}"); + + validateExpr("[Table2].[Field3]", "{[Table2].[Field3]}"); + + validateExpr("Not \"A\"", "{Not {\"A\"}}"); + + validateExpr("-[Field1]", "{- {[Field1]}}"); + + validateExpr("\"A\" Is Null", "{{\"A\"} Is Null}"); + + validateExpr("\"A\" In (1,2,3)", "{{\"A\"} In ({1},{2},{3})}"); + + validateExpr("\"A\" Not Between 3 And 7", "{{\"A\"} Not Between {3} And {7}}"); + + validateExpr("(\"A\" Or \"B\")", "{({{\"A\"} Or {\"B\"}})}"); + + validateExpr("IIf(\"A\",42,False)", "{IIf({\"A\"},{42},{False})}"); + + validateExpr("\"A\" Like \"a*b\"", "{{\"A\"} Like \"a*b\"(a.*b)}"); + } + + private static void doTestSimpleBinOp(String opName, String... ops) throws Exception + { + for(String op : ops) { + validateExpr("\"A\" " + op + " \"B\"", + "<" + opName + ">{{\"A\"} " + op + + " {\"B\"}}"); + } + } + + public void testOrderOfOperations() throws Exception + { + validateExpr("\"A\" Eqv \"B\"", + "{{\"A\"} Eqv {\"B\"}}"); + + validateExpr("\"A\" Eqv \"B\" Xor \"C\"", + "{{\"A\"} Eqv {{\"B\"} Xor {\"C\"}}}"); + + validateExpr("\"A\" Eqv \"B\" Xor \"C\" Or \"D\"", + "{{\"A\"} Eqv {{\"B\"} Xor {{\"C\"} Or {\"D\"}}}}"); + + validateExpr("\"A\" Eqv \"B\" Xor \"C\" Or \"D\" And \"E\"", + "{{\"A\"} Eqv {{\"B\"} Xor {{\"C\"} Or {{\"D\"} And {\"E\"}}}}}"); + + validateExpr("\"A\" Or \"B\" Or \"C\"", + "{{{\"A\"} Or {\"B\"}} Or {\"C\"}}"); + + validateExpr("\"A\" & \"B\" Is Null", + "{{{\"A\"} & {\"B\"}} Is Null}"); + + validateExpr("\"A\" Or \"B\" Is Null", + "{{\"A\"} Or {{\"B\"} Is Null}}"); + + validateExpr("Not \"A\" & \"B\"", + "{Not {{\"A\"} & {\"B\"}}}"); + + validateExpr("Not \"A\" Or \"B\"", + "{{Not {\"A\"}} Or {\"B\"}}"); + + validateExpr("\"A\" + \"B\" Not Between 37 - 15 And 52 / 4", + "{{{\"A\"} + {\"B\"}} Not Between {{37} - {15}} And {{52} / {4}}}"); + + validateExpr("\"A\" + (\"B\" Not Between 37 - 15 And 52) / 4", + "{{\"A\"} + {{({{\"B\"} Not Between {{37} - {15}} And {52}})} / {4}}}"); + + + } + + private static void validateExpr(String exprStr, String debugStr) { + validateExpr(exprStr, debugStr, exprStr); + } + + private static void validateExpr(String exprStr, String debugStr, + String cleanStr) { + Expression expr = Expressionator.parse( + Expressionator.Type.FIELD_VALIDATOR, exprStr, null); + assertEquals(debugStr, expr.toDebugString()); + assertEquals(cleanStr, expr.toString()); + } +} diff --git a/src/test/java/com/healthmarketscience/jackcess/util/ExpressionatorTest.java b/src/test/java/com/healthmarketscience/jackcess/util/ExpressionatorTest.java deleted file mode 100644 index 8da921f..0000000 --- a/src/test/java/com/healthmarketscience/jackcess/util/ExpressionatorTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/* -Copyright (c) 2016 James Ahlborn - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package com.healthmarketscience.jackcess.util; - -import junit.framework.TestCase; - -/** - * - * @author James Ahlborn - */ -public class ExpressionatorTest extends TestCase -{ - - public ExpressionatorTest(String name) { - super(name); - } - - - public void testParseSimpleExprs() throws Exception - { - validateExpr("\"A\"", "{\"A\"}"); - - validateExpr("13", "{13}"); - - validateExpr("-42", "{-42}"); - - doTestSimpleBinOp("EBinaryOp", "+", "-", "*", "/", "\\", "^", "&", "Mod"); - doTestSimpleBinOp("ECompOp", "<", "<=", ">", ">=", "=", "<>"); - doTestSimpleBinOp("ELogicalOp", "And", "Or", "Eqv", "Xor", "Imp"); - - for(String constStr : new String[]{"True", "False", "Null"}) { - validateExpr(constStr, "{" + constStr + "}"); - } - - validateExpr("[Field1]", "{[Field1]}"); - - validateExpr("[Table2].[Field3]", "{[Table2].[Field3]}"); - - validateExpr("Not \"A\"", "{Not {\"A\"}}"); - - validateExpr("-[Field1]", "{- {[Field1]}}"); - - validateExpr("\"A\" Is Null", "{{\"A\"} Is Null}"); - - validateExpr("\"A\" In (1,2,3)", "{{\"A\"} In ({1},{2},{3})}"); - - validateExpr("\"A\" Not Between 3 And 7", "{{\"A\"} Not Between {3} And {7}}"); - - validateExpr("(\"A\" Or \"B\")", "{({{\"A\"} Or {\"B\"}})}"); - - validateExpr("IIf(\"A\",42,False)", "{IIf({\"A\"},{42},{False})}"); - - validateExpr("\"A\" Like \"a*b\"", "{{\"A\"} Like \"a*b\"(a.*b)}"); - } - - private static void doTestSimpleBinOp(String opName, String... ops) throws Exception - { - for(String op : ops) { - validateExpr("\"A\" " + op + " \"B\"", - "<" + opName + ">{{\"A\"} " + op + - " {\"B\"}}"); - } - } - - public void testOrderOfOperations() throws Exception - { - validateExpr("\"A\" Eqv \"B\"", - "{{\"A\"} Eqv {\"B\"}}"); - - validateExpr("\"A\" Eqv \"B\" Xor \"C\"", - "{{\"A\"} Eqv {{\"B\"} Xor {\"C\"}}}"); - - validateExpr("\"A\" Eqv \"B\" Xor \"C\" Or \"D\"", - "{{\"A\"} Eqv {{\"B\"} Xor {{\"C\"} Or {\"D\"}}}}"); - - validateExpr("\"A\" Eqv \"B\" Xor \"C\" Or \"D\" And \"E\"", - "{{\"A\"} Eqv {{\"B\"} Xor {{\"C\"} Or {{\"D\"} And {\"E\"}}}}}"); - - validateExpr("\"A\" Or \"B\" Or \"C\"", - "{{{\"A\"} Or {\"B\"}} Or {\"C\"}}"); - - validateExpr("\"A\" & \"B\" Is Null", - "{{{\"A\"} & {\"B\"}} Is Null}"); - - validateExpr("\"A\" Or \"B\" Is Null", - "{{\"A\"} Or {{\"B\"} Is Null}}"); - - validateExpr("Not \"A\" & \"B\"", - "{Not {{\"A\"} & {\"B\"}}}"); - - validateExpr("Not \"A\" Or \"B\"", - "{{Not {\"A\"}} Or {\"B\"}}"); - - validateExpr("\"A\" + \"B\" Not Between 37 - 15 And 52 / 4", - "{{{\"A\"} + {\"B\"}} Not Between {{37} - {15}} And {{52} / {4}}}"); - - validateExpr("\"A\" + (\"B\" Not Between 37 - 15 And 52) / 4", - "{{\"A\"} + {{({{\"B\"} Not Between {{37} - {15}} And {52}})} / {4}}}"); - - - } - - private static void validateExpr(String exprStr, String debugStr) { - validateExpr(exprStr, debugStr, exprStr); - } - - private static void validateExpr(String exprStr, String debugStr, - String cleanStr) { - Expression expr = Expressionator.parse( - Expressionator.Type.FIELD_VALIDATOR, exprStr, null); - assertEquals(debugStr, expr.toDebugString()); - assertEquals(cleanStr, expr.toString()); - } -} -- cgit v1.2.3