Googletest export
Deduce SizeType for SizeIs() from the return value of the size() member function PiperOrigin-RevId: 223835674
This commit is contained in:
parent
3fd66989bb
commit
3d71ab4c37
@ -1955,9 +1955,7 @@ class SizeIsMatcher {
|
|||||||
template <typename Container>
|
template <typename Container>
|
||||||
class Impl : public MatcherInterface<Container> {
|
class Impl : public MatcherInterface<Container> {
|
||||||
public:
|
public:
|
||||||
typedef internal::StlContainerView<
|
using SizeType = decltype(std::declval<Container>().size());
|
||||||
GTEST_REMOVE_REFERENCE_AND_CONST_(Container)> ContainerView;
|
|
||||||
typedef typename ContainerView::type::size_type SizeType;
|
|
||||||
explicit Impl(const SizeMatcher& size_matcher)
|
explicit Impl(const SizeMatcher& size_matcher)
|
||||||
: size_matcher_(MatcherCast<SizeType>(size_matcher)) {}
|
: size_matcher_(MatcherCast<SizeType>(size_matcher)) {}
|
||||||
|
|
||||||
|
@ -4821,6 +4821,17 @@ TEST(SizeIsTest, WorksWithReferences) {
|
|||||||
EXPECT_THAT(container, m);
|
EXPECT_THAT(container, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SizeIs should work for any type that provides a size() member function.
|
||||||
|
// For example, a size_type member type should not need to be provided.
|
||||||
|
struct MinimalistCustomType {
|
||||||
|
int size() const { return 1; }
|
||||||
|
};
|
||||||
|
TEST(SizeIsTest, WorksWithMinimalistCustomType) {
|
||||||
|
MinimalistCustomType container;
|
||||||
|
EXPECT_THAT(container, SizeIs(1));
|
||||||
|
EXPECT_THAT(container, Not(SizeIs(0)));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(SizeIsTest, CanDescribeSelf) {
|
TEST(SizeIsTest, CanDescribeSelf) {
|
||||||
Matcher<vector<int> > m = SizeIs(2);
|
Matcher<vector<int> > m = SizeIs(2);
|
||||||
EXPECT_EQ("size is equal to 2", Describe(m));
|
EXPECT_EQ("size is equal to 2", Describe(m));
|
||||||
|
Loading…
Reference in New Issue
Block a user