aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/tests
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@oath.com>2018-08-15 12:14:30 +0000
committerTor Egge <Tor.Egge@oath.com>2018-08-15 12:14:30 +0000
commit72d56adf3f4b89480659be393d0178dbdc18ce84 (patch)
tree2c6ffe07cd65b63936f479339d16efcaa449dd84 /document/src/tests
parent23204afafb060c5fca6b7e1d632af394e72eb234 (diff)
Reverse iteration over selection result in an attempt to
avoid stale array indexes being used as part of applying a remove field path update. This change assumes that variables stored in result list have increasing values. Add unit test for removal of multiple array elements using remove field path update.
Diffstat (limited to 'document/src/tests')
-rw-r--r--document/src/tests/fieldpathupdatetestcase.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/document/src/tests/fieldpathupdatetestcase.cpp b/document/src/tests/fieldpathupdatetestcase.cpp
index f5db5831912..35b851ca895 100644
--- a/document/src/tests/fieldpathupdatetestcase.cpp
+++ b/document/src/tests/fieldpathupdatetestcase.cpp
@@ -38,6 +38,7 @@ struct FieldPathUpdateTestCase : public CppUnit::TestFixture {
void testRemoveField();
void testApplyRemoveEntireListField();
void testApplyRemoveMultiList();
+ void testApplyRemoveMultiList2();
void testApplyRemoveMultiWset();
void testApplyAssignSingle();
void testApplyAssignMath();
@@ -79,6 +80,7 @@ struct FieldPathUpdateTestCase : public CppUnit::TestFixture {
CPPUNIT_TEST(testRemoveField);
CPPUNIT_TEST(testApplyRemoveEntireListField);
CPPUNIT_TEST(testApplyRemoveMultiList);
+ CPPUNIT_TEST(testApplyRemoveMultiList2);
CPPUNIT_TEST(testApplyRemoveMultiWset);
CPPUNIT_TEST(testApplyAssignSingle);
CPPUNIT_TEST(testApplyAssignMath);
@@ -420,6 +422,32 @@ FieldPathUpdateTestCase::testApplyRemoveMultiList()
}
void
+FieldPathUpdateTestCase::testApplyRemoveMultiList2()
+{
+ Document::UP doc(new Document(_foobar_type, DocumentId("doc:things:thangs")));
+ doc->setRepo(*_repo);
+ CPPUNIT_ASSERT(doc->hasValue("strarray") == false);
+ {
+ ArrayFieldValue strArray(doc->getType().getField("strarray").getDataType());
+ strArray.add(StringFieldValue("remove val 1"));
+ strArray.add(StringFieldValue("remove val 1"));
+ strArray.add(StringFieldValue("hello hello"));
+ doc->setValue("strarray", strArray);
+ }
+ CPPUNIT_ASSERT(doc->hasValue("strarray"));
+ //doc->print(std::cerr, true, "");
+ DocumentUpdate docUp(*_repo, _foobar_type, DocumentId("doc:barbar:foofoo"));
+ docUp.addFieldPathUpdate(FieldPathUpdate::CP(
+ new RemoveFieldPathUpdate("strarray[$x]", "foobar.strarray[$x] == \"remove val 1\"")));
+ docUp.applyTo(*doc);
+ {
+ std::unique_ptr<ArrayFieldValue> strArray = doc->getAs<ArrayFieldValue>(doc->getField("strarray"));
+ CPPUNIT_ASSERT_EQUAL(std::size_t(1), strArray->size());
+ CPPUNIT_ASSERT_EQUAL(vespalib::string("hello hello"), (*strArray)[0].getAsString());
+ }
+}
+
+void
FieldPathUpdateTestCase::testApplyRemoveEntireListField()
{
Document::UP doc(new Document(_foobar_type, DocumentId("doc:things:thangs")));