summaryrefslogtreecommitdiffstats
path: root/searchcore/src/tests/proton/attribute/document_field_extractor/document_field_extractor_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'searchcore/src/tests/proton/attribute/document_field_extractor/document_field_extractor_test.cpp')
-rw-r--r--searchcore/src/tests/proton/attribute/document_field_extractor/document_field_extractor_test.cpp38
1 files changed, 36 insertions, 2 deletions
diff --git a/searchcore/src/tests/proton/attribute/document_field_extractor/document_field_extractor_test.cpp b/searchcore/src/tests/proton/attribute/document_field_extractor/document_field_extractor_test.cpp
index bad27938d4b..33a3de0c5b6 100644
--- a/searchcore/src/tests/proton/attribute/document_field_extractor/document_field_extractor_test.cpp
+++ b/searchcore/src/tests/proton/attribute/document_field_extractor/document_field_extractor_test.cpp
@@ -36,8 +36,7 @@ using document::FieldValue;
using document::FieldNotFoundException;
using proton::DocumentFieldExtractor;
-namespace
-{
+namespace {
const ArrayDataType arrayTypeInt(*DataType::INT);
const ArrayDataType arrayTypeString(*DataType::STRING);
@@ -335,6 +334,41 @@ TEST_F("require that struct map field gives array values", StructMapFixture)
TEST_DO(f.assertExtracted("s.value.name", makeStringArray({ "name10", noString, "name12", noString })));
}
+struct PrimitiveMapFixture : public FixtureBase
+{
+ MapDataType mapFieldType;
+ Field mapField;
+ using MapVector = std::vector<std::pair<vespalib::string, int>>;
+
+ PrimitiveMapFixture()
+ : FixtureBase(false),
+ mapFieldType(nameField.getDataType(), weightField.getDataType()),
+ mapField("map", mapFieldType, true)
+ {
+ type.addField(mapField);
+ }
+
+ std::unique_ptr<MapFieldValue> makeMap(const MapVector &input) {
+ auto result = std::make_unique<MapFieldValue>(mapFieldType);
+ for (const auto &elem : input) {
+ result->put(StringFieldValue(elem.first), IntFieldValue(elem.second));
+ }
+ return result;
+ }
+
+ void makeDoc(const MapVector &input) {
+ FixtureBase::makeDoc()->setValue(mapField, *makeMap(input));
+ }
+
+};
+
+TEST_F("require that primitive map field gives array values", PrimitiveMapFixture)
+{
+ f.makeDoc({ {"foo", 10}, {"", 20}, {"bar", noInt} });
+ TEST_DO(f.assertExtracted("map.key", makeStringArray({ "foo", "", "bar" })));
+ TEST_DO(f.assertExtracted("map.value", makeIntArray({ 10, 20, noInt })));
+}
+
TEST_F("require that unknown field gives null value", FixtureBase(false))
{
f.makeDoc();