Refactor matrix verification into VerifyMatchMatrix.

PiperOrigin-RevId: 494786543
Change-Id: I7769558dd2ca046d8957bf352dc04cfb48ff7c3a
This commit is contained in:
Abseil Team 2022-12-12 11:51:21 -08:00 committed by Copybara-Service
parent b0846aaf37
commit ad54e90f57
2 changed files with 17 additions and 17 deletions

View File

@ -3644,23 +3644,6 @@ class UnorderedElementsAreMatcherImpl
AnalyzeElements(stl_container.begin(), stl_container.end(), AnalyzeElements(stl_container.begin(), stl_container.end(),
&element_printouts, listener); &element_printouts, listener);
if (matrix.LhsSize() == 0 && matrix.RhsSize() == 0) {
return true;
}
if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
if (matrix.LhsSize() != matrix.RhsSize()) {
// The element count doesn't match. If the container is empty,
// there's no need to explain anything as Google Mock already
// prints the empty container. Otherwise we just need to show
// how many elements there actually are.
if (matrix.LhsSize() != 0 && listener->IsInterested()) {
*listener << "which has " << Elements(matrix.LhsSize());
}
return false;
}
}
return VerifyMatchMatrix(element_printouts, matrix, listener) && return VerifyMatchMatrix(element_printouts, matrix, listener) &&
FindPairing(matrix, listener); FindPairing(matrix, listener);
} }

View File

@ -370,6 +370,23 @@ void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(
bool UnorderedElementsAreMatcherImplBase::VerifyMatchMatrix( bool UnorderedElementsAreMatcherImplBase::VerifyMatchMatrix(
const ::std::vector<std::string>& element_printouts, const ::std::vector<std::string>& element_printouts,
const MatchMatrix& matrix, MatchResultListener* listener) const { const MatchMatrix& matrix, MatchResultListener* listener) const {
if (matrix.LhsSize() == 0 && matrix.RhsSize() == 0) {
return true;
}
if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
if (matrix.LhsSize() != matrix.RhsSize()) {
// The element count doesn't match. If the container is empty,
// there's no need to explain anything as Google Mock already
// prints the empty container. Otherwise we just need to show
// how many elements there actually are.
if (matrix.LhsSize() != 0 && listener->IsInterested()) {
*listener << "which has " << Elements(matrix.LhsSize());
}
return false;
}
}
bool result = true; bool result = true;
::std::vector<char> element_matched(matrix.LhsSize(), 0); ::std::vector<char> element_matched(matrix.LhsSize(), 0);
::std::vector<char> matcher_matched(matrix.RhsSize(), 0); ::std::vector<char> matcher_matched(matrix.RhsSize(), 0);