SearchIterator * StringSearch::safeClone(void) const { UErrorCode status = U_ZERO_ERROR; StringSearch *result = new StringSearch(m_pattern_, m_text_, getCollator(), m_breakiterator_, status); /* test for NULL */ if (result == 0) { status = U_MEMORY_ALLOCATION_ERROR; return 0; } result->setOffset(getOffset(), status); result->setMatchStart(m_strsrch_->search->matchedIndex); result->setMatchLength(m_strsrch_->search->matchedLength); if (U_FAILURE(status)) { return NULL; } return result; }
ASSERT_TRUE(next.isAdvanced()); ASSERT_DOCUMENT_EQ(next.releaseDocument(), (Document{{"a", 1}, {"b", 1}})); // The rest should not match. ASSERT_TRUE(match->getNext().isEOF()); ASSERT_TRUE(match->getNext().isEOF()); ASSERT_TRUE(match->getNext().isEOF()); } DEATH_TEST_F(DocumentSourceMatchTest, ShouldFailToDescendExpressionOnPathThatIsNotACommonPrefix, "Invariant failure expression::isPathPrefixOf") { const auto expCtx = getExpCtx(); const auto matchSpec = BSON("a.b" << 1 << "b.c" << 1); const auto matchExpression = unittest::assertGet( MatchExpressionParser::parse(matchSpec, ExtensionsCallbackNoop(), expCtx->getCollator())); DocumentSourceMatch::descendMatchOnPath(matchExpression.get(), "a", expCtx); } DEATH_TEST_F(DocumentSourceMatchTest, ShouldFailToDescendExpressionOnPathThatContainsElemMatchWithObject, "Invariant failure node->matchType()") { const auto expCtx = getExpCtx(); const auto matchSpec = BSON("a" << BSON("$elemMatch" << BSON("a.b" << 1))); const auto matchExpression = unittest::assertGet( MatchExpressionParser::parse(matchSpec, ExtensionsCallbackNoop(), expCtx->getCollator())); BSONObjBuilder out; matchExpression->serialize(&out); DocumentSourceMatch::descendMatchOnPath(matchExpression.get(), "a", expCtx); }