From ad54e90f57199b91ac40e1344eb0c75e8670b21b Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 12 Dec 2022 11:51:21 -0800 Subject: [PATCH] Refactor matrix verification into VerifyMatchMatrix. PiperOrigin-RevId: 494786543 Change-Id: I7769558dd2ca046d8957bf352dc04cfb48ff7c3a --- googlemock/include/gmock/gmock-matchers.h | 17 ----------------- googlemock/src/gmock-matchers.cc | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 901c109c..26fe8d2e 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -3644,23 +3644,6 @@ class UnorderedElementsAreMatcherImpl AnalyzeElements(stl_container.begin(), stl_container.end(), &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) && FindPairing(matrix, listener); } diff --git a/googlemock/src/gmock-matchers.cc b/googlemock/src/gmock-matchers.cc index a8d04a6d..5810b6aa 100644 --- a/googlemock/src/gmock-matchers.cc +++ b/googlemock/src/gmock-matchers.cc @@ -370,6 +370,23 @@ void UnorderedElementsAreMatcherImplBase::DescribeNegationToImpl( bool UnorderedElementsAreMatcherImplBase::VerifyMatchMatrix( const ::std::vector& element_printouts, 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; ::std::vector element_matched(matrix.LhsSize(), 0); ::std::vector matcher_matched(matrix.RhsSize(), 0);