From b4140808f98ff09c43ca1ddaa8ff13bc47cd0089 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Tue, 8 Jun 2010 22:53:57 +0000 Subject: Replaces Python-style interpolation with arbitrary C++ string expression in MATCHER* descriptions. --- include/gmock/gmock-generated-matchers.h | 397 ++++++++++++++------------ include/gmock/gmock-generated-matchers.h.pump | 64 +++-- include/gmock/gmock-matchers.h | 42 +-- 3 files changed, 251 insertions(+), 252 deletions(-) (limited to 'include') diff --git a/include/gmock/gmock-generated-matchers.h b/include/gmock/gmock-generated-matchers.h index 2790e06c..2cc5746e 100644 --- a/include/gmock/gmock-generated-matchers.h +++ b/include/gmock/gmock-generated-matchers.h @@ -946,25 +946,29 @@ ElementsAreArray(const T (&array)[N]) { // Describing Parameterized Matchers // ================================= // -// When defining a parameterized matcher, you can use Python-style -// interpolations in the description string to refer to the parameter -// values. We support the following syntax currently: -// -// %% a single '%' character -// %(*)s all parameters of the matcher printed as a tuple -// %(foo)s value of the matcher parameter named 'foo' -// -// For example, -// -// MATCHER_P2(InClosedRange, low, hi, "is in range [%(low)s, %(hi)s]") { +// The last argument to MATCHER*() is a string-typed expression. The +// expression can reference all of the matcher's parameters and a +// special bool-typed variable named 'negation'. When 'negation' is +// false, the expression should evaluate to the matcher's description; +// otherwise it should evaluate to the description of the negation of +// the matcher. For example, +// +// using testing::PrintToString; +// +// MATCHER_P2(InClosedRange, low, hi, +// string(negation ? "is not" : "is") + " in range [" + +// PrintToString(low) + ", " + PrintToString(hi) + "]") { // return low <= arg && arg <= hi; // } // ... // EXPECT_THAT(3, InClosedRange(4, 6)); +// EXPECT_THAT(3, Not(InClosedRange(2, 4))); // -// would generate a failure that contains the message: +// would generate two failures that contain the text: // // Expected: is in range [4, 6] +// ... +// Expected: is not in range [2, 4] // // If you specify "" as the description, the failure message will // contain the sequence of words in the matcher name followed by the @@ -973,10 +977,13 @@ ElementsAreArray(const T (&array)[N]) { // MATCHER_P2(InClosedRange, low, hi, "") { ... } // ... // EXPECT_THAT(3, InClosedRange(4, 6)); +// EXPECT_THAT(3, Not(InClosedRange(2, 4))); // -// would generate a failure that contains the text: +// would generate two failures that contain the text: // // Expected: in closed range (4, 6) +// ... +// Expected: not (in closed range (2, 4)) // // Types of Matcher Parameters // =========================== @@ -1065,33 +1072,36 @@ ElementsAreArray(const T (&array)[N]) { template \ class gmock_Impl : public ::testing::MatcherInterface {\ public:\ - gmock_Impl(const ::testing::internal::Interpolations& gmock_interp)\ - : gmock_interp_(gmock_interp) {}\ + gmock_Impl()\ + {}\ virtual bool MatchAndExplain(\ arg_type arg, ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ - const ::testing::internal::Strings& gmock_printed_params = \ - ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ - ::std::tr1::tuple<>());\ - *gmock_os << ::testing::internal::FormatMatcherDescription(\ - #name, description, gmock_interp_, gmock_printed_params);\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ }\ - const ::testing::internal::Interpolations gmock_interp_;\ private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name,\ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple<>()));\ + }\ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ return ::testing::Matcher(\ - new gmock_Impl(gmock_interp_));\ + new gmock_Impl());\ }\ name##Matcher() {\ - const char* gmock_param_names[] = { NULL };\ - gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ - gmock_param_names, ("" description ""));\ }\ private:\ - ::testing::internal::Interpolations gmock_interp_;\ GTEST_DISALLOW_ASSIGN_(name##Matcher);\ };\ inline name##Matcher name() {\ @@ -1110,36 +1120,38 @@ ElementsAreArray(const T (&array)[N]) { template \ class gmock_Impl : public ::testing::MatcherInterface {\ public:\ - explicit gmock_Impl(p0##_type gmock_p0, \ - const ::testing::internal::Interpolations& gmock_interp)\ - : p0(gmock_p0), gmock_interp_(gmock_interp) {}\ + explicit gmock_Impl(p0##_type gmock_p0)\ + : p0(gmock_p0) {}\ virtual bool MatchAndExplain(\ arg_type arg, ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ - const ::testing::internal::Strings& gmock_printed_params = \ - ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ - ::std::tr1::tuple(p0));\ - *gmock_os << ::testing::internal::FormatMatcherDescription(\ - #name, description, gmock_interp_, gmock_printed_params);\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ }\ p0##_type p0;\ - const ::testing::internal::Interpolations gmock_interp_;\ private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name,\ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple(p0)));\ + }\ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ return ::testing::Matcher(\ - new gmock_Impl(p0, gmock_interp_));\ + new gmock_Impl(p0));\ }\ name##MatcherP(p0##_type gmock_p0) : p0(gmock_p0) {\ - const char* gmock_param_names[] = { #p0, NULL };\ - gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ - gmock_param_names, ("" description ""));\ }\ p0##_type p0;\ private:\ - ::testing::internal::Interpolations gmock_interp_;\ GTEST_DISALLOW_ASSIGN_(name##MatcherP);\ };\ template \ @@ -1160,39 +1172,41 @@ ElementsAreArray(const T (&array)[N]) { template \ class gmock_Impl : public ::testing::MatcherInterface {\ public:\ - gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \ - const ::testing::internal::Interpolations& gmock_interp)\ - : p0(gmock_p0), p1(gmock_p1), gmock_interp_(gmock_interp) {}\ + gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1)\ + : p0(gmock_p0), p1(gmock_p1) {}\ virtual bool MatchAndExplain(\ arg_type arg, ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ - const ::testing::internal::Strings& gmock_printed_params = \ - ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ - ::std::tr1::tuple(p0, p1));\ - *gmock_os << ::testing::internal::FormatMatcherDescription(\ - #name, description, gmock_interp_, gmock_printed_params);\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ }\ p0##_type p0;\ p1##_type p1;\ - const ::testing::internal::Interpolations gmock_interp_;\ private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name,\ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple(p0, p1)));\ + }\ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ return ::testing::Matcher(\ - new gmock_Impl(p0, p1, gmock_interp_));\ + new gmock_Impl(p0, p1));\ }\ name##MatcherP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \ p1(gmock_p1) {\ - const char* gmock_param_names[] = { #p0, #p1, NULL };\ - gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ - gmock_param_names, ("" description ""));\ }\ p0##_type p0;\ p1##_type p1;\ private:\ - ::testing::internal::Interpolations gmock_interp_;\ GTEST_DISALLOW_ASSIGN_(name##MatcherP2);\ };\ template \ @@ -1215,43 +1229,44 @@ ElementsAreArray(const T (&array)[N]) { template \ class gmock_Impl : public ::testing::MatcherInterface {\ public:\ - gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - const ::testing::internal::Interpolations& gmock_interp)\ - : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - gmock_interp_(gmock_interp) {}\ + gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2)\ + : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\ virtual bool MatchAndExplain(\ arg_type arg, ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ - const ::testing::internal::Strings& gmock_printed_params = \ - ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ - ::std::tr1::tuple(p0, p1, \ - p2));\ - *gmock_os << ::testing::internal::FormatMatcherDescription(\ - #name, description, gmock_interp_, gmock_printed_params);\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ }\ p0##_type p0;\ p1##_type p1;\ p2##_type p2;\ - const ::testing::internal::Interpolations gmock_interp_;\ private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name,\ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple(p0, p1, \ + p2)));\ + }\ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2, gmock_interp_));\ + new gmock_Impl(p0, p1, p2));\ }\ name##MatcherP3(p0##_type gmock_p0, p1##_type gmock_p1, \ p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {\ - const char* gmock_param_names[] = { #p0, #p1, #p2, NULL };\ - gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ - gmock_param_names, ("" description ""));\ }\ p0##_type p0;\ p1##_type p1;\ p2##_type p2;\ private:\ - ::testing::internal::Interpolations gmock_interp_;\ GTEST_DISALLOW_ASSIGN_(name##MatcherP3);\ };\ template \ @@ -1276,46 +1291,47 @@ ElementsAreArray(const T (&array)[N]) { class gmock_Impl : public ::testing::MatcherInterface {\ public:\ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3, \ - const ::testing::internal::Interpolations& gmock_interp)\ - : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ - gmock_interp_(gmock_interp) {}\ + p3##_type gmock_p3)\ + : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3) {}\ virtual bool MatchAndExplain(\ arg_type arg, ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ - const ::testing::internal::Strings& gmock_printed_params = \ - ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ - ::std::tr1::tuple(p0, p1, p2, p3));\ - *gmock_os << ::testing::internal::FormatMatcherDescription(\ - #name, description, gmock_interp_, gmock_printed_params);\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ }\ p0##_type p0;\ p1##_type p1;\ p2##_type p2;\ p3##_type p3;\ - const ::testing::internal::Interpolations gmock_interp_;\ private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name,\ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple(p0, p1, p2, p3)));\ + }\ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2, p3, gmock_interp_));\ + new gmock_Impl(p0, p1, p2, p3));\ }\ name##MatcherP4(p0##_type gmock_p0, p1##_type gmock_p1, \ p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \ p2(gmock_p2), p3(gmock_p3) {\ - const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, NULL };\ - gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ - gmock_param_names, ("" description ""));\ }\ p0##_type p0;\ p1##_type p1;\ p2##_type p2;\ p3##_type p3;\ private:\ - ::testing::internal::Interpolations gmock_interp_;\ GTEST_DISALLOW_ASSIGN_(name##MatcherP4);\ };\ template {\ public:\ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3, p4##_type gmock_p4, \ - const ::testing::internal::Interpolations& gmock_interp)\ + p3##_type gmock_p3, p4##_type gmock_p4)\ : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ - p4(gmock_p4), gmock_interp_(gmock_interp) {}\ + p4(gmock_p4) {}\ virtual bool MatchAndExplain(\ arg_type arg, ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ - const ::testing::internal::Strings& gmock_printed_params = \ - ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ - ::std::tr1::tuple(p0, p1, p2, p3, p4));\ - *gmock_os << ::testing::internal::FormatMatcherDescription(\ - #name, description, gmock_interp_, gmock_printed_params);\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ }\ p0##_type p0;\ p1##_type p1;\ p2##_type p2;\ p3##_type p3;\ p4##_type p4;\ - const ::testing::internal::Interpolations gmock_interp_;\ private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name,\ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple(p0, p1, p2, p3, p4)));\ + }\ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2, p3, p4, gmock_interp_));\ + new gmock_Impl(p0, p1, p2, p3, p4));\ }\ name##MatcherP5(p0##_type gmock_p0, p1##_type gmock_p1, \ p2##_type gmock_p2, p3##_type gmock_p3, \ p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ p3(gmock_p3), p4(gmock_p4) {\ - const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, NULL };\ - gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ - gmock_param_names, ("" description ""));\ }\ p0##_type p0;\ p1##_type p1;\ @@ -1386,7 +1405,6 @@ ElementsAreArray(const T (&array)[N]) { p3##_type p3;\ p4##_type p4;\ private:\ - ::testing::internal::Interpolations gmock_interp_;\ GTEST_DISALLOW_ASSIGN_(name##MatcherP5);\ };\ template {\ public:\ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ - const ::testing::internal::Interpolations& gmock_interp)\ + p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5)\ : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ - p4(gmock_p4), p5(gmock_p5), gmock_interp_(gmock_interp) {}\ + p4(gmock_p4), p5(gmock_p5) {}\ virtual bool MatchAndExplain(\ arg_type arg, ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ - const ::testing::internal::Strings& gmock_printed_params = \ - ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ - ::std::tr1::tuple(p0, p1, p2, p3, p4, p5));\ - *gmock_os << ::testing::internal::FormatMatcherDescription(\ - #name, description, gmock_interp_, gmock_printed_params);\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ }\ p0##_type p0;\ p1##_type p1;\ @@ -1435,22 +1450,28 @@ ElementsAreArray(const T (&array)[N]) { p3##_type p3;\ p4##_type p4;\ p5##_type p5;\ - const ::testing::internal::Interpolations gmock_interp_;\ private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name,\ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple(p0, p1, p2, p3, p4, p5)));\ + }\ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2, p3, p4, p5, gmock_interp_));\ + new gmock_Impl(p0, p1, p2, p3, p4, p5));\ }\ name##MatcherP6(p0##_type gmock_p0, p1##_type gmock_p1, \ p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {\ - const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, #p5, NULL };\ - gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ - gmock_param_names, ("" description ""));\ }\ p0##_type p0;\ p1##_type p1;\ @@ -1459,7 +1480,6 @@ ElementsAreArray(const T (&array)[N]) { p4##_type p4;\ p5##_type p5;\ private:\ - ::testing::internal::Interpolations gmock_interp_;\ GTEST_DISALLOW_ASSIGN_(name##MatcherP6);\ };\ template (p0, p1, p2, p3, p4, p5, \ - p6));\ - *gmock_os << ::testing::internal::FormatMatcherDescription(\ - #name, description, gmock_interp_, gmock_printed_params);\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ }\ p0##_type p0;\ p1##_type p1;\ @@ -1513,24 +1528,30 @@ ElementsAreArray(const T (&array)[N]) { p4##_type p4;\ p5##_type p5;\ p6##_type p6;\ - const ::testing::internal::Interpolations gmock_interp_;\ private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name,\ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple(p0, p1, p2, p3, p4, p5, \ + p6)));\ + }\ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2, p3, p4, p5, p6, gmock_interp_));\ + new gmock_Impl(p0, p1, p2, p3, p4, p5, p6));\ }\ name##MatcherP7(p0##_type gmock_p0, p1##_type gmock_p1, \ p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \ p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \ p6(gmock_p6) {\ - const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, #p5, #p6, \ - NULL };\ - gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ - gmock_param_names, ("" description ""));\ }\ p0##_type p0;\ p1##_type p1;\ @@ -1540,7 +1561,6 @@ ElementsAreArray(const T (&array)[N]) { p5##_type p5;\ p6##_type p6;\ private:\ - ::testing::internal::Interpolations gmock_interp_;\ GTEST_DISALLOW_ASSIGN_(name##MatcherP7);\ };\ template (p0, p1, p2, \ - p3, p4, p5, p6, p7));\ - *gmock_os << ::testing::internal::FormatMatcherDescription(\ - #name, description, gmock_interp_, gmock_printed_params);\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ }\ p0##_type p0;\ p1##_type p1;\ @@ -1598,15 +1613,24 @@ ElementsAreArray(const T (&array)[N]) { p5##_type p5;\ p6##_type p6;\ p7##_type p7;\ - const ::testing::internal::Interpolations gmock_interp_;\ private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name,\ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple(p0, p1, p2, \ + p3, p4, p5, p6, p7)));\ + }\ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2, p3, p4, p5, p6, p7, \ - gmock_interp_));\ + new gmock_Impl(p0, p1, p2, p3, p4, p5, p6, p7));\ }\ name##MatcherP8(p0##_type gmock_p0, p1##_type gmock_p1, \ p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ @@ -1614,10 +1638,6 @@ ElementsAreArray(const T (&array)[N]) { p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ p7(gmock_p7) {\ - const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, #p5, #p6, \ - #p7, NULL };\ - gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ - gmock_param_names, ("" description ""));\ }\ p0##_type p0;\ p1##_type p1;\ @@ -1628,7 +1648,6 @@ ElementsAreArray(const T (&array)[N]) { p6##_type p6;\ p7##_type p7;\ private:\ - ::testing::internal::Interpolations gmock_interp_;\ GTEST_DISALLOW_ASSIGN_(name##MatcherP8);\ };\ template (p0, p1, p2, p3, p4, p5, p6, p7, p8));\ - *gmock_os << ::testing::internal::FormatMatcherDescription(\ - #name, description, gmock_interp_, gmock_printed_params);\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ }\ p0##_type p0;\ p1##_type p1;\ @@ -1689,15 +1704,24 @@ ElementsAreArray(const T (&array)[N]) { p6##_type p6;\ p7##_type p7;\ p8##_type p8;\ - const ::testing::internal::Interpolations gmock_interp_;\ private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name,\ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple(p0, p1, p2, p3, p4, p5, p6, p7, p8)));\ + }\ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2, p3, p4, p5, p6, p7, p8, \ - gmock_interp_));\ + new gmock_Impl(p0, p1, p2, p3, p4, p5, p6, p7, p8));\ }\ name##MatcherP9(p0##_type gmock_p0, p1##_type gmock_p1, \ p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ @@ -1705,10 +1729,6 @@ ElementsAreArray(const T (&array)[N]) { p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ p8(gmock_p8) {\ - const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, #p5, #p6, \ - #p7, #p8, NULL };\ - gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ - gmock_param_names, ("" description ""));\ }\ p0##_type p0;\ p1##_type p1;\ @@ -1720,7 +1740,6 @@ ElementsAreArray(const T (&array)[N]) { p7##_type p7;\ p8##_type p8;\ private:\ - ::testing::internal::Interpolations gmock_interp_;\ GTEST_DISALLOW_ASSIGN_(name##MatcherP9);\ };\ template (p0, p1, p2, p3, p4, p5, p6, p7, p8, p9));\ - *gmock_os << ::testing::internal::FormatMatcherDescription(\ - #name, description, gmock_interp_, gmock_printed_params);\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ }\ p0##_type p0;\ p1##_type p1;\ @@ -1785,15 +1800,24 @@ ElementsAreArray(const T (&array)[N]) { p7##_type p7;\ p8##_type p8;\ p9##_type p9;\ - const ::testing::internal::Interpolations gmock_interp_;\ private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name,\ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)));\ + }\ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, \ - gmock_interp_));\ + new gmock_Impl(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9));\ }\ name##MatcherP10(p0##_type gmock_p0, p1##_type gmock_p1, \ p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ @@ -1801,10 +1825,6 @@ ElementsAreArray(const T (&array)[N]) { p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \ p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {\ - const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, #p5, #p6, \ - #p7, #p8, #p9, NULL };\ - gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ - gmock_param_names, ("" description ""));\ }\ p0##_type p0;\ p1##_type p1;\ @@ -1817,7 +1837,6 @@ ElementsAreArray(const T (&array)[N]) { p8##_type p8;\ p9##_type p9;\ private:\ - ::testing::internal::Interpolations gmock_interp_;\ GTEST_DISALLOW_ASSIGN_(name##MatcherP10);\ };\ template \ ]]]] $var ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]] -$var impl_ctor_param_list = [[$for j [[p$j##_type gmock_p$j, ]] -const ::testing::internal::Interpolations& gmock_interp]] -$var impl_inits = [[ : $for j [[p$j(gmock_p$j), ]]gmock_interp_(gmock_interp)]] +$var impl_ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]] +$var impl_inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(gmock_p$j)]]]]]] $var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(gmock_p$j)]]]]]] -$var params_and_interp = [[$for j [[p$j, ]]gmock_interp_]] $var params = [[$for j, [[p$j]]]] $var param_types = [[$if i==0 [[]] $else [[<$for j, [[p$j##_type]]>]]]] $var param_types_and_names = [[$for j, [[p$j##_type p$j]]]] @@ -559,28 +564,31 @@ $var param_field_decls2 = [[$for j virtual bool MatchAndExplain(\ arg_type arg, ::testing::MatchResultListener* result_listener) const;\ virtual void DescribeTo(::std::ostream* gmock_os) const {\ - const ::testing::internal::Strings& gmock_printed_params = \ - ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ - ::std::tr1::tuple<$for j, [[p$j##_type]]>($for j, [[p$j]]));\ - *gmock_os << ::testing::internal::FormatMatcherDescription(\ - #name, description, gmock_interp_, gmock_printed_params);\ + *gmock_os << FormatDescription(false);\ + }\ + virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ + *gmock_os << FormatDescription(true);\ }\$param_field_decls - const ::testing::internal::Interpolations gmock_interp_;\ private:\ + ::testing::internal::string FormatDescription(bool negation) const {\ + const ::testing::internal::string gmock_description = (description);\ + if (!gmock_description.empty())\ + return gmock_description;\ + return ::testing::internal::FormatMatcherDescription(\ + negation, #name,\ + ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ + ::std::tr1::tuple<$for j, [[p$j##_type]]>($for j, [[p$j]])));\ + }\ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ };\ template \ operator ::testing::Matcher() const {\ return ::testing::Matcher(\ - new gmock_Impl($params_and_interp));\ + new gmock_Impl($params));\ }\ $class_name($ctor_param_list)$inits {\ - const char* gmock_param_names[] = { $for j [[#p$j, ]]NULL };\ - gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ - gmock_param_names, ("" description ""));\ }\$param_field_decls2 private:\ - ::testing::internal::Interpolations gmock_interp_;\ GTEST_DISALLOW_ASSIGN_($class_name);\ };\$template inline $class_name$param_types name($param_types_and_names) {\ diff --git a/include/gmock/gmock-matchers.h b/include/gmock/gmock-matchers.h index 2a42bf94..315e1f56 100644 --- a/include/gmock/gmock-matchers.h +++ b/include/gmock/gmock-matchers.h @@ -2527,41 +2527,13 @@ class ElementsAreArrayMatcher { GTEST_DISALLOW_ASSIGN_(ElementsAreArrayMatcher); }; -// Constants denoting interpolations in a matcher description string. -const int kTupleInterpolation = -1; // "%(*)s" -const int kPercentInterpolation = -2; // "%%" -const int kInvalidInterpolation = -3; // "%" followed by invalid text - -// Records the location and content of an interpolation. -struct Interpolation { - Interpolation(const char* start, const char* end, int param) - : start_pos(start), end_pos(end), param_index(param) {} - - // Points to the start of the interpolation (the '%' character). - const char* start_pos; - // Points to the first character after the interpolation. - const char* end_pos; - // 0-based index of the interpolated matcher parameter; - // kTupleInterpolation for "%(*)s"; kPercentInterpolation for "%%". - int param_index; -}; - -typedef ::std::vector Interpolations; - -// Parses a matcher description string and returns a vector of -// interpolations that appear in the string; generates non-fatal -// failures iff 'description' is an invalid matcher description. -// 'param_names' is a NULL-terminated array of parameter names in the -// order they appear in the MATCHER_P*() parameter list. -Interpolations ValidateMatcherDescription( - const char* param_names[], const char* description); - -// Returns the actual matcher description, given the matcher name, -// user-supplied description template string, interpolations in the -// string, and the printed values of the matcher parameters. -string FormatMatcherDescription( - const char* matcher_name, const char* description, - const Interpolations& interp, const Strings& param_values); +// Returns the description for a matcher defined using the MATCHER*() +// macro where the user-supplied description string is "", if +// 'negation' is false; otherwise returns the description of the +// negation of the matcher. 'param_values' contains a list of strings +// that are the print-out of the matcher's parameters. +string FormatMatcherDescription(bool negation, const char* matcher_name, + const Strings& param_values); } // namespace internal -- cgit v1.2.3