diff options
author | Geir Storli <geirst@oath.com> | 2018-06-08 12:56:36 +0000 |
---|---|---|
committer | Geir Storli <geirst@oath.com> | 2018-06-08 12:56:36 +0000 |
commit | 29649971ad58d3c24f6393a06b063b346d1be96b (patch) | |
tree | 98248049c861e5a0e3e542eada86efd995d0fa79 /searchcore/src/tests/proton/attribute/document_field_extractor/document_field_extractor_test.cpp | |
parent | f923ea8a4b4c3a94a5beabef70f77e9f49bde407 (diff) |
Support handling map of primitive types in document field extractor.
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.cpp | 38 |
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(); |