summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-08-15 20:16:55 +0200
committerGitHub <noreply@github.com>2019-08-15 20:16:55 +0200
commit7626ef4e275cc4f8ad81e5e31a56aad2f7c62593 (patch)
tree3d9539f25f5bdb2d967d50438e260c71ac0285d0 /document
parent840aacbbae61a4d0162d2decb534a6fe5fae030a (diff)
parent465db7ae35b062ecd181058e1ef2750bbd4efe8f (diff)
Merge branch 'master' into balder/prepare-remove-visitor-ordering
Diffstat (limited to 'document')
-rw-r--r--document/src/main/java/com/yahoo/document/select/rule/ArithmeticNode.java2
-rw-r--r--document/src/test/java/com/yahoo/document/select/ArithmeticNodeTestCase.java24
-rw-r--r--document/src/test/java/com/yahoo/document/select/LogicalNodeTestCase.java1
3 files changed, 26 insertions, 1 deletions
diff --git a/document/src/main/java/com/yahoo/document/select/rule/ArithmeticNode.java b/document/src/main/java/com/yahoo/document/select/rule/ArithmeticNode.java
index 921f412096e..c14957c94a4 100644
--- a/document/src/main/java/com/yahoo/document/select/rule/ArithmeticNode.java
+++ b/document/src/main/java/com/yahoo/document/select/rule/ArithmeticNode.java
@@ -87,6 +87,8 @@ public class ArithmeticNode implements ExpressionNode {
}
buf.push(new ValueItem(item.operator, (Number)val));
continue;
+ } else if (val == Result.INVALID) {
+ return val;
}
throw new IllegalStateException("Term '" + item.node + " with class " + val.getClass() + "' does not evaluate to a number.");
}
diff --git a/document/src/test/java/com/yahoo/document/select/ArithmeticNodeTestCase.java b/document/src/test/java/com/yahoo/document/select/ArithmeticNodeTestCase.java
new file mode 100644
index 00000000000..20b0e2034cc
--- /dev/null
+++ b/document/src/test/java/com/yahoo/document/select/ArithmeticNodeTestCase.java
@@ -0,0 +1,24 @@
+package com.yahoo.document.select;
+
+import com.yahoo.document.select.rule.ArithmeticNode;
+import com.yahoo.document.select.rule.LiteralNode;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class ArithmeticNodeTestCase {
+
+ private void verify(Object expect, String operator, Object arg2) {
+ assertEquals(expect,
+ new ArithmeticNode().add(null, new LiteralNode(10)).add(operator, new LiteralNode(arg2)).evaluate(new Context(null)));
+ assertEquals(Result.INVALID,
+ new ArithmeticNode().add(null, new LiteralNode(10)).add(operator, new LiteralNode(Result.INVALID)).evaluate(new Context(null)));
+ }
+ @Test
+ public void testThatInvalidPropagates() {
+ verify(12.0, "+", 2);
+ verify(8.0, "-", 2);
+ verify(30.0, "*", 3);
+ verify(5.0, "/", 2);
+ }
+}
diff --git a/document/src/test/java/com/yahoo/document/select/LogicalNodeTestCase.java b/document/src/test/java/com/yahoo/document/select/LogicalNodeTestCase.java
index 5e06085b8c9..90cde23bf30 100644
--- a/document/src/test/java/com/yahoo/document/select/LogicalNodeTestCase.java
+++ b/document/src/test/java/com/yahoo/document/select/LogicalNodeTestCase.java
@@ -11,7 +11,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
public class LogicalNodeTestCase {
private static class TracedNode implements ExpressionNode {