Skip to content

Commit ad54e90

Browse files
Abseil Teamcopybara-github
Abseil Team
authored andcommitted
Refactor matrix verification into VerifyMatchMatrix.
PiperOrigin-RevId: 494786543 Change-Id: I7769558dd2ca046d8957bf352dc04cfb48ff7c3a
1 parent b0846aa commit ad54e90

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

googlemock/include/gmock/gmock-matchers.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3644,23 +3644,6 @@ class UnorderedElementsAreMatcherImpl
36443644
AnalyzeElements(stl_container.begin(), stl_container.end(),
36453645
&element_printouts, listener);
36463646

3647-
if (matrix.LhsSize() == 0 && matrix.RhsSize() == 0) {
3648-
return true;
3649-
}
3650-
3651-
if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
3652-
if (matrix.LhsSize() != matrix.RhsSize()) {
3653-
// The element count doesn't match. If the container is empty,
3654-
// there's no need to explain anything as Google Mock already
3655-
// prints the empty container. Otherwise we just need to show
3656-
// how many elements there actually are.
3657-
if (matrix.LhsSize() != 0 && listener->IsInterested()) {
3658-
*listener << "which has " << Elements(matrix.LhsSize());
3659-
}
3660-
return false;
3661-
}
3662-
}
3663-
36643647
return VerifyMatchMatrix(element_printouts, matrix, listener) &&
36653648
FindPairing(matrix, listener);
36663649
}

googlemock/src/gmock-matchers.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,23 @@ void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl(
370370
bool UnorderedElementsAreMatcherImplBase::VerifyMatchMatrix(
371371
const ::std::vector<std::string>& element_printouts,
372372
const MatchMatrix& matrix, MatchResultListener* listener) const {
373+
if (matrix.LhsSize() == 0 && matrix.RhsSize() == 0) {
374+
return true;
375+
}
376+
377+
if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
378+
if (matrix.LhsSize() != matrix.RhsSize()) {
379+
// The element count doesn't match. If the container is empty,
380+
// there's no need to explain anything as Google Mock already
381+
// prints the empty container. Otherwise we just need to show
382+
// how many elements there actually are.
383+
if (matrix.LhsSize() != 0 && listener->IsInterested()) {
384+
*listener << "which has " << Elements(matrix.LhsSize());
385+
}
386+
return false;
387+
}
388+
}
389+
373390
bool result = true;
374391
::std::vector<char> element_matched(matrix.LhsSize(), 0);
375392
::std::vector<char> matcher_matched(matrix.RhsSize(), 0);

0 commit comments

Comments
 (0)