summaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/expression
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@oath.com>2018-09-06 10:01:49 +0000
committerTor Egge <Tor.Egge@oath.com>2018-09-06 10:01:49 +0000
commit68f14dea9838fc62be035d7b3e2d7319c7ea4c9b (patch)
tree4050dbb3b11446c861654857f173c1a15748febf /searchlib/src/tests/expression
parentbed4478f9776ae17dddfdb3eb3f1ceb5fcc88e43 (diff)
Extend AttributeNode test to also test AttributeKeyedNode.
Diffstat (limited to 'searchlib/src/tests/expression')
-rw-r--r--searchlib/src/tests/expression/attributenode/attribute_node_test.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/searchlib/src/tests/expression/attributenode/attribute_node_test.cpp b/searchlib/src/tests/expression/attributenode/attribute_node_test.cpp
index 79b16c1eaed..5a8a00fe384 100644
--- a/searchlib/src/tests/expression/attributenode/attribute_node_test.cpp
+++ b/searchlib/src/tests/expression/attributenode/attribute_node_test.cpp
@@ -10,6 +10,7 @@
#include <vespa/searchlib/attribute/integerbase.h>
#include <vespa/searchlib/attribute/stringbase.h>
#include <vespa/searchlib/expression/attributenode.h>
+#include <vespa/searchlib/expression/attribute_keyed_node.h>
#include <vespa/searchlib/expression/resultvector.h>
#include <vespa/vespalib/test/insertion_operators.h>
#include <vespa/vespalib/testkit/testapp.h>
@@ -30,6 +31,7 @@ using search::attribute::Config;
using search::attribute::IAttributeVector;
using search::attribute::getUndefined;
using search::expression::AttributeNode;
+using search::expression::AttributeKeyedNode;
using search::expression::EnumResultNode;
using search::expression::EnumResultNodeVector;
using search::expression::FloatResultNode;
@@ -212,7 +214,12 @@ Fixture::~Fixture() = default;
std::unique_ptr<AttributeNode>
Fixture::makeNode(const vespalib::string &attributeName, bool useEnumOptimization, bool preserveAccurateTypes)
{
- auto node = std::make_unique<AttributeNode>(attributeName);
+ std::unique_ptr<AttributeNode> node;
+ if (attributeName.find('{') == vespalib::string::npos) {
+ node = std::make_unique<AttributeNode>(attributeName);
+ } else {
+ node = std::make_unique<AttributeKeyedNode>(attributeName);
+ }
if (useEnumOptimization) {
node->useEnumOptimization();
}
@@ -383,6 +390,26 @@ TEST_F("Test array values", Fixture)
TEST_DO(f.assertStringArrays({{"n1.1", "n1.2"}, {"n2"}, {}}, "map.value"));
}
+TEST_F("test keyed values", Fixture)
+{
+ TEST_DO(f.assertStrings({"n1.1", "", ""}, "smap{\"k1.1\"}.name"));
+ TEST_DO(f.assertStrings({"n1.2", "", ""}, "smap{\"k1.2\"}.name"));
+ TEST_DO(f.assertStrings({"", "n2", ""}, "smap{\"k2\"}.name"));
+ TEST_DO(f.assertStrings({"", "", ""}, "smap{\"k5\"}.name"));
+ TEST_DO(f.assertFloats({ 110.0, getUndefined<double>(), getUndefined<double>()}, "smap{\"k1.1\"}.fval"));
+ TEST_DO(f.assertFloats({ getUndefined<double>(), getUndefined<double>(), getUndefined<double>()}, "smap{\"k1.2\"}.fval"));
+ TEST_DO(f.assertFloats({ getUndefined<double>(), 120.0, getUndefined<double>()}, "smap{\"k2\"}.fval"));
+ TEST_DO(f.assertFloats({ getUndefined<double>(), getUndefined<double>(), getUndefined<double>()}, "smap{\"k5\"}.fval"));
+ TEST_DO(f.assertInts({ 10, getUndefined<int8_t>(), getUndefined<int8_t>()}, "smap{\"k1.1\"}.val"));
+ TEST_DO(f.assertInts({ 11, getUndefined<int8_t>(), getUndefined<int8_t>()}, "smap{\"k1.2\"}.val"));
+ TEST_DO(f.assertInts({ getUndefined<int8_t>(), 20, getUndefined<int8_t>()}, "smap{\"k2\"}.val"));
+ TEST_DO(f.assertInts({ getUndefined<int8_t>(), getUndefined<int8_t>(), getUndefined<int8_t>()}, "smap{\"k5\"}.val"));
+ TEST_DO(f.assertStrings({"n1.1", "", ""}, "map{\"k1.1\"}"));
+ TEST_DO(f.assertStrings({"n1.2", "", ""}, "map{\"k1.2\"}"));
+ TEST_DO(f.assertStrings({"", "n2", ""}, "map{\"k2\"}"));
+ TEST_DO(f.assertStrings({"", "", ""}, "map{\"k5\"}"));
+}
+
}
TEST_MAIN() { TEST_RUN_ALL(); }