33std::ostream &operator<<(std::ostream &OS, const StringMapEntry<T> &E) {
34 OS << "{\"" << E.getKey().data() << "\": ";
35 if constexpr (detail::CanOutputToOStream<decltype(E.getValue())>::value) {
38 OS << "non-printable value";
46class StringMapEntryMatcherImpl
47 : public testing::MatcherInterface<StringMapEntryT> {
49 using ValueT = typename std::remove_reference_t<StringMapEntryT>::ValueType;
51 template <typename KeyMatcherT, typename ValueMatcherT>
52 StringMapEntryMatcherImpl(KeyMatcherT KeyMatcherArg,
53 ValueMatcherT ValueMatcherArg)
55 testing::SafeMatcherCast<const std::string &>(KeyMatcherArg)),
57 testing::SafeMatcherCast<const ValueT &>(ValueMatcherArg)) {}
59 void DescribeTo(std::ostream *OS) const override {
60 *OS << "has a string key that ";
61 KeyMatcher.DescribeTo(OS);
62 *OS << ", and has a value that ";
63 ValueMatcher.DescribeTo(OS);
66 void DescribeNegationTo(std::ostream *OS) const override {
67 *OS << "has a string key that ";
68 KeyMatcher.DescribeNegationTo(OS);
69 *OS << ", or has a value that ";
70 ValueMatcher.DescribeNegationTo(OS);
74 MatchAndExplain(StringMapEntryT Entry,
75 testing::MatchResultListener *ResultListener) const override {
76 testing::StringMatchResultListener KeyListener;
77 if (!KeyMatcher.MatchAndExplain(Entry.getKey().data(), &KeyListener)) {
78 *ResultListener << ("which has a string key " +
79 (KeyListener.str().empty() ? "that doesn't match"
80 : KeyListener.str()));
83 testing::StringMatchResultListener ValueListener;
84 if (!ValueMatcher.MatchAndExplain(Entry.getValue(), &ValueListener)) {
85 *ResultListener << ("which has a value " + (ValueListener.str().empty()
86 ? "that doesn't match"
87 : ValueListener.str()));
90 *ResultListener << "which is a match";
95 const testing::Matcher<const std::string &> KeyMatcher;
96 const testing::Matcher<const ValueT &> ValueMatcher;
122IsStringMapEntry(KeyMatcherT KM, ValueMatcherT VM) {
123 return detail::StringMapEntryMatcher<KeyMatcherT, ValueMatcherT>(
124 std::move(KM), std::move(VM));
This file defines the StringMapEntry class - it is intended to be a low dependency implementation det...