camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ond...@apache.org
Subject [1/2] camel git commit: CAMEL-11533 - note "-" sign doing binary comparison against negative value
Date Thu, 13 Jul 2017 11:05:10 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.19.x ab8381859 -> 72c9b60b3


CAMEL-11533 - note "-" sign doing binary comparison against negative value


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e34599d9
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e34599d9
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e34599d9

Branch: refs/heads/camel-2.19.x
Commit: e34599d9505e707e08082512421fe922c2858b26
Parents: ab83818
Author: onders86 <ondersezgin@gmail.com>
Authored: Wed Jul 12 07:40:16 2017 +0300
Committer: onders86 <ondersezgin@gmail.com>
Committed: Thu Jul 13 13:11:09 2017 +0300

----------------------------------------------------------------------
 .../language/simple/SimplePredicateParser.java  | 12 ++++-
 .../camel/language/simple/SimpleTokenizer.java  |  5 +++
 .../simple/types/BinaryOperatorType.java        |  6 ++-
 .../language/simple/types/SimpleTokenType.java  |  7 +++
 .../camel/language/simple/types/TokenType.java  |  2 +-
 .../language/simple/SimpleOperatorTest.java     | 46 ++++++++++++++++++++
 .../SimpleParserPredicateInvalidTest.java       |  4 +-
 7 files changed, 77 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e34599d9/camel-core/src/main/java/org/apache/camel/language/simple/SimplePredicateParser.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/language/simple/SimplePredicateParser.java
b/camel-core/src/main/java/org/apache/camel/language/simple/SimplePredicateParser.java
index 56e28da..7b73dd0 100644
--- a/camel-core/src/main/java/org/apache/camel/language/simple/SimplePredicateParser.java
+++ b/camel-core/src/main/java/org/apache/camel/language/simple/SimplePredicateParser.java
@@ -571,6 +571,7 @@ public class SimplePredicateParser extends BaseSimpleParser {
             boolean numericSupported = false;
             boolean booleanSupported = false;
             boolean nullSupported = false;
+            boolean minusSupported = false;
             if (types == null || types.length == 0) {
                 literalWithFunctionsSupported = true;
                 // favor literal with functions over literals without functions
@@ -579,6 +580,7 @@ public class SimplePredicateParser extends BaseSimpleParser {
                 numericSupported = true;
                 booleanSupported = true;
                 nullSupported = true;
+                minusSupported = true;
             } else {
                 for (BinaryOperatorType.ParameterType parameterType : types) {
                     literalSupported |= parameterType.isLiteralSupported();
@@ -587,6 +589,7 @@ public class SimplePredicateParser extends BaseSimpleParser {
                     nullSupported |= parameterType.isNumericValueSupported();
                     booleanSupported |= parameterType.isBooleanValueSupported();
                     nullSupported |= parameterType.isNullValueSupported();
+                    minusSupported |= parameterType.isMinusValueSupported();
                 }
             }
 
@@ -599,7 +602,8 @@ public class SimplePredicateParser extends BaseSimpleParser {
                     || (functionSupported && functionText())
                     || (numericSupported && numericValue())
                     || (booleanSupported && booleanValue())
-                    || (nullSupported && nullValue())) {
+                    || (nullSupported && nullValue())
+                    || (minusSupported && minusValue())) {
                 // then after the right hand side value, there should be a whitespace if
there is more tokens
                 nextToken();
                 if (!token.getType().isEol()) {
@@ -657,5 +661,11 @@ public class SimplePredicateParser extends BaseSimpleParser {
         return accept(TokenType.nullValue);
         // no other tokens to check so do not use nextToken
     }
+    
+    protected boolean minusValue() {
+        nextToken();
+        return accept(TokenType.numericValue);
+        // no other tokens to check so do not use nextToken
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/e34599d9/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java
b/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java
index 7c3aa1b..ae2a0cd 100644
--- a/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java
+++ b/camel-core/src/main/java/org/apache/camel/language/simple/SimpleTokenizer.java
@@ -79,6 +79,11 @@ public final class SimpleTokenizer {
         // TODO: @deprecated logical operators, to be removed in Camel 3.0
         KNOWN_TOKENS.add(new SimpleTokenType(TokenType.logicalOperator, "and"));
         KNOWN_TOKENS.add(new SimpleTokenType(TokenType.logicalOperator, "or"));
+        
+        //binary operator 
+        // it is added as the last item because unary -- has the priority
+        // if unary not found it is highly possible - operator is run into.
+        KNOWN_TOKENS.add(new SimpleTokenType(TokenType.minusValue, "-"));
     }
 
     private SimpleTokenizer() {

http://git-wip-us.apache.org/repos/asf/camel/blob/e34599d9/camel-core/src/main/java/org/apache/camel/language/simple/types/BinaryOperatorType.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/language/simple/types/BinaryOperatorType.java
b/camel-core/src/main/java/org/apache/camel/language/simple/types/BinaryOperatorType.java
index 5a7751b..ab9585d 100644
--- a/camel-core/src/main/java/org/apache/camel/language/simple/types/BinaryOperatorType.java
+++ b/camel-core/src/main/java/org/apache/camel/language/simple/types/BinaryOperatorType.java
@@ -122,7 +122,7 @@ public enum BinaryOperatorType {
      * </ul>
      */
     public enum ParameterType {
-        Literal, LiteralWithFunction, Function, NumericValue, BooleanValue, NullValue;
+        Literal, LiteralWithFunction, Function, NumericValue, BooleanValue, NullValue, MinusValue;
 
         public boolean isLiteralSupported() {
             return this == Literal;
@@ -147,6 +147,10 @@ public enum BinaryOperatorType {
         public boolean isNullValueSupported() {
             return this == NullValue;
         }
+        
+        public boolean isMinusValueSupported() {
+            return this == MinusValue;
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/camel/blob/e34599d9/camel-core/src/main/java/org/apache/camel/language/simple/types/SimpleTokenType.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/language/simple/types/SimpleTokenType.java
b/camel-core/src/main/java/org/apache/camel/language/simple/types/SimpleTokenType.java
index f74e12e..cc68328 100644
--- a/camel-core/src/main/java/org/apache/camel/language/simple/types/SimpleTokenType.java
+++ b/camel-core/src/main/java/org/apache/camel/language/simple/types/SimpleTokenType.java
@@ -123,6 +123,13 @@ public class SimpleTokenType {
     public boolean isNullValue() {
         return type == TokenType.nullValue;
     }
+    
+    /**
+     * Whether the type is a minus operator
+     */
+    public boolean isMinusValue() {
+        return type == TokenType.minusValue;
+    }
 
     @Override
     public String toString() {

http://git-wip-us.apache.org/repos/asf/camel/blob/e34599d9/camel-core/src/main/java/org/apache/camel/language/simple/types/TokenType.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/language/simple/types/TokenType.java
b/camel-core/src/main/java/org/apache/camel/language/simple/types/TokenType.java
index ff1a5d7..da95427 100644
--- a/camel-core/src/main/java/org/apache/camel/language/simple/types/TokenType.java
+++ b/camel-core/src/main/java/org/apache/camel/language/simple/types/TokenType.java
@@ -23,7 +23,7 @@ public enum TokenType {
 
     whiteSpace, character,
     booleanValue, numericValue, nullValue,
-    singleQuote, doubleQuote,
+    singleQuote, doubleQuote, minusValue,
     escape,
     functionStart, functionEnd,
     binaryOperator, unaryOperator, logicalOperator,

http://git-wip-us.apache.org/repos/asf/camel/blob/e34599d9/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
b/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
index e40154f..81a6966 100644
--- a/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
+++ b/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
@@ -276,6 +276,52 @@ public class SimpleOperatorTest extends LanguageTestSupport {
         assertPredicate("${in.header.bar} < 123", false);
         assertPredicate("${in.header.bar} < '200'", true);
     }
+    
+    public void testAgainstNegativeValue() throws Exception {
+        assertPredicate("${in.header.bar} == 123", true);
+        assertPredicate("${in.header.bar} == -123", false);
+        assertPredicate("${in.header.bar} =~ 123", true);
+        assertPredicate("${in.header.bar} =~ -123", false);
+        assertPredicate("${in.header.bar} > -123", true);
+        assertPredicate("${in.header.bar} >= -123", true);
+        assertPredicate("${in.header.bar} > 123", false);
+        assertPredicate("${in.header.bar} >= 123", true);
+        assertPredicate("${in.header.bar} < -123", false);
+        assertPredicate("${in.header.bar} <= -123", false);
+        assertPredicate("${in.header.bar} < 123", false);
+        assertPredicate("${in.header.bar} <= 123", true);
+
+        exchange.getIn().setHeader("strNum", "123");
+        assertPredicate("${in.header.strNum} contains '123'", true);
+        assertPredicate("${in.header.strNum} not contains '123'", false);
+        assertPredicate("${in.header.strNum} contains '-123'", false);
+        assertPredicate("${in.header.strNum} not contains '-123'", true);
+        assertPredicate("${in.header.strNum} ~~ '123'", true);
+        assertPredicate("${in.header.strNum} ~~ '-123'", false);
+    
+        exchange.getIn().setHeader("num", -123);
+        assertPredicate("${in.header.num} == -123", true);
+        assertPredicate("${in.header.num} == 123", false);
+        assertPredicate("${in.header.num} =~ -123", true);
+        assertPredicate("${in.header.num} =~ 123", false);
+        assertPredicate("${in.header.num} > -123", false);
+        assertPredicate("${in.header.num} >= -123", true);
+        assertPredicate("${in.header.num} > 123", false);
+        assertPredicate("${in.header.num} >= 123", false);
+        assertPredicate("${in.header.num} < -123", false);
+        assertPredicate("${in.header.num} <= -123", true);
+        assertPredicate("${in.header.num} < 123", true);
+        assertPredicate("${in.header.num} <= 123", true);
+    
+        exchange.getIn().setHeader("strNumNegative", "-123");
+        assertPredicate("${in.header.strNumNegative} contains '123'", true);
+        assertPredicate("${in.header.strNumNegative} not contains '123'", false);
+        assertPredicate("${in.header.strNumNegative} contains '-123'", true);
+        assertPredicate("${in.header.strNumNegative} not contains '-123'", false);
+        assertPredicate("${in.header.strNumNegative} ~~ '123'", true);
+        assertPredicate("${in.header.strNumNegative} ~~ '-123'", true);
+
+    }
 
     public void testLessThanOrEqualOperator() throws Exception {
         // string to string comparison

http://git-wip-us.apache.org/repos/asf/camel/blob/e34599d9/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateInvalidTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateInvalidTest.java
b/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateInvalidTest.java
index 10ee394..d622100 100644
--- a/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateInvalidTest.java
+++ b/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateInvalidTest.java
@@ -33,7 +33,7 @@ public class SimpleParserPredicateInvalidTest extends ExchangeTestSupport
{
             parser.parsePredicate();
             fail("Should thrown exception");
         } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(18, e.getIndex());
+            assertEquals(19, e.getIndex());
         }
     }
 
@@ -106,7 +106,7 @@ public class SimpleParserPredicateInvalidTest extends ExchangeTestSupport
{
             parser.parsePredicate();
             fail("Should thrown exception");
         } catch (SimpleIllegalSyntaxException e) {
-            assertEquals(11, e.getIndex());
+            assertEquals(13, e.getIndex());
         }
     }
 


Mime
View raw message