9#ifndef LLVM_TESTING_ADT_STRINGMAPENTRY_H_
10#define LLVM_TESTING_ADT_STRINGMAPENTRY_H_
13#include "gmock/gmock.h"
20template <
typename T,
typename = std::
void_t<>>
25 << std::declval<T>())>>
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";
45template <typename StringMapEntryT>
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;
99template <typename KeyMatcherT, typename ValueMatcherT>
100class StringMapEntryMatcher {
102 StringMapEntryMatcher(KeyMatcherT KMArg, ValueMatcherT VMArg)
103 : KM(std::move(KMArg)), VM(std::move(VMArg)) {}
105 template <typename StringMapEntryT>
106 operator testing::Matcher<StringMapEntryT>() const {
107 return testing::Matcher<StringMapEntryT>(
108 new StringMapEntryMatcherImpl<const StringMapEntryT &>(KM, VM));
112 const KeyMatcherT KM;
113 const ValueMatcherT VM;
120template <typename KeyMatcherT, typename ValueMatcherT>
121detail::StringMapEntryMatcher<KeyMatcherT, ValueMatcherT>
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...
This is an optimization pass for GlobalISel generic memory operations.
Implement std::hash so that hash_code can be used in STL containers.