Googletest export
Deduplicate testing::ReferenceWrapper with std::reference_wrapper. Minor cleanups in matchers_test. PiperOrigin-RevId: 229022872
This commit is contained in:
committed by
Gennadiy Civil
parent
0599a7b841
commit
097407fd3c
@@ -637,8 +637,7 @@ inline void PrintTo(std::nullptr_t, ::std::ostream* os) { *os << "(nullptr)"; }
|
||||
|
||||
template <typename T>
|
||||
void PrintTo(std::reference_wrapper<T> ref, ::std::ostream* os) {
|
||||
// Delegate to wrapped value.
|
||||
PrintTo(ref.get(), os);
|
||||
UniversalPrinter<T&>::Print(ref.get(), os);
|
||||
}
|
||||
|
||||
// Helper function for printing a tuple. T must be instantiated with
|
||||
|
||||
@@ -1023,16 +1023,20 @@ TEST(PrintNullptrT, Basic) {
|
||||
|
||||
TEST(PrintReferenceWrapper, Printable) {
|
||||
int x = 5;
|
||||
EXPECT_EQ("5", Print(std::ref(x)));
|
||||
EXPECT_EQ("5", Print(std::cref(x)));
|
||||
EXPECT_EQ("@" + PrintPointer(&x) + " 5", Print(std::ref(x)));
|
||||
EXPECT_EQ("@" + PrintPointer(&x) + " 5", Print(std::cref(x)));
|
||||
}
|
||||
|
||||
TEST(PrintReferenceWrapper, Unprintable) {
|
||||
::foo::UnprintableInFoo up;
|
||||
EXPECT_EQ("16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
|
||||
Print(std::ref(up)));
|
||||
EXPECT_EQ("16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
|
||||
Print(std::cref(up)));
|
||||
EXPECT_EQ(
|
||||
"@" + PrintPointer(&up) +
|
||||
" 16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
|
||||
Print(std::ref(up)));
|
||||
EXPECT_EQ(
|
||||
"@" + PrintPointer(&up) +
|
||||
" 16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
|
||||
Print(std::cref(up)));
|
||||
}
|
||||
|
||||
// Tests printing user-defined unprintable types.
|
||||
|
||||
Reference in New Issue
Block a user