Thanks to visit codestin.com
Credit goes to llvm.org

LLVM 22.0.0git
StringMapEntry.h
Go to the documentation of this file.
1//===- llvm/Testing/ADT/StringMapEntry.h ----------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_TESTING_ADT_STRINGMAPENTRY_H_
10#define LLVM_TESTING_ADT_STRINGMAPENTRY_H_
11
14#include "gmock/gmock.h"
15#include <ostream>
16#include <type_traits>
17
18namespace llvm {
19namespace detail {
20
21template <typename T>
23 decltype(std::declval<std::ostream &>() << std::declval<T>());
24
25} // namespace detail
26
27/// Support for printing to std::ostream, for use with e.g. producing more
28/// useful error messages with Google Test.
29template <typename T>
30std::ostream &operator<<(std::ostream &OS, const StringMapEntry<T> &E) {
31 OS << "{\"" << E.getKey().data() << "\": ";
33 decltype(E.getValue())>::value) {
34 OS << E.getValue();
35 } else {
36 OS << "non-printable value";
37 }
38 return OS << "}";
39}
40
41namespace detail {
42
43template <typename StringMapEntryT>
45 : public testing::MatcherInterface<StringMapEntryT> {
46public:
47 using ValueT = typename std::remove_reference_t<StringMapEntryT>::ValueType;
48
49 template <typename KeyMatcherT, typename ValueMatcherT>
50 StringMapEntryMatcherImpl(KeyMatcherT KeyMatcherArg,
51 ValueMatcherT ValueMatcherArg)
52 : KeyMatcher(
53 testing::SafeMatcherCast<const std::string &>(KeyMatcherArg)),
54 ValueMatcher(
55 testing::SafeMatcherCast<const ValueT &>(ValueMatcherArg)) {}
56
57 void DescribeTo(std::ostream *OS) const override {
58 *OS << "has a string key that ";
59 KeyMatcher.DescribeTo(OS);
60 *OS << ", and has a value that ";
61 ValueMatcher.DescribeTo(OS);
62 }
63
64 void DescribeNegationTo(std::ostream *OS) const override {
65 *OS << "has a string key that ";
66 KeyMatcher.DescribeNegationTo(OS);
67 *OS << ", or has a value that ";
68 ValueMatcher.DescribeNegationTo(OS);
69 }
70
71 bool
72 MatchAndExplain(StringMapEntryT Entry,
73 testing::MatchResultListener *ResultListener) const override {
74 testing::StringMatchResultListener KeyListener;
75 if (!KeyMatcher.MatchAndExplain(Entry.getKey().data(), &KeyListener)) {
76 *ResultListener << ("which has a string key " +
77 (KeyListener.str().empty() ? "that doesn't match"
78 : KeyListener.str()));
79 return false;
80 }
81 testing::StringMatchResultListener ValueListener;
82 if (!ValueMatcher.MatchAndExplain(Entry.getValue(), &ValueListener)) {
83 *ResultListener << ("which has a value " + (ValueListener.str().empty()
84 ? "that doesn't match"
85 : ValueListener.str()));
86 return false;
87 }
88 *ResultListener << "which is a match";
89 return true;
90 }
91
92private:
93 const testing::Matcher<const std::string &> KeyMatcher;
94 const testing::Matcher<const ValueT &> ValueMatcher;
95};
96
97template <typename KeyMatcherT, typename ValueMatcherT>
99public:
100 StringMapEntryMatcher(KeyMatcherT KMArg, ValueMatcherT VMArg)
101 : KM(std::move(KMArg)), VM(std::move(VMArg)) {}
102
103 template <typename StringMapEntryT>
104 operator testing::Matcher<StringMapEntryT>() const { // NOLINT
105 return testing::Matcher<StringMapEntryT>(
107 }
108
109private:
110 const KeyMatcherT KM;
111 const ValueMatcherT VM;
112};
113
114} // namespace detail
115
116/// Returns a gMock matcher that matches a `StringMapEntry` whose string key
117/// matches `KeyMatcher`, and whose value matches `ValueMatcher`.
118template <typename KeyMatcherT, typename ValueMatcherT>
119detail::StringMapEntryMatcher<KeyMatcherT, ValueMatcherT>
120IsStringMapEntry(KeyMatcherT KM, ValueMatcherT VM) {
122 std::move(KM), std::move(VM));
123}
124
125} // namespace llvm
126
127#endif
aarch64 promote const
This file defines the StringMapEntry class - it is intended to be a low dependency implementation det...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains library features backported from future STL versions.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringMapEntryMatcherImpl(KeyMatcherT KeyMatcherArg, ValueMatcherT ValueMatcherArg)
bool MatchAndExplain(StringMapEntryT Entry, testing::MatchResultListener *ResultListener) const override
void DescribeTo(std::ostream *OS) const override
void DescribeNegationTo(std::ostream *OS) const override
typename std::remove_reference_t< StringMapEntryT >::ValueType ValueT
StringMapEntryMatcher(KeyMatcherT KMArg, ValueMatcherT VMArg)
These are wrappers over isa* function that allow them to be used in generic algorithms such as llvm:a...
Definition ADL.h:123
decltype(std::declval< std::ostream & >()<< std::declval< T >()) check_ostream
This is an optimization pass for GlobalISel generic memory operations.
detail::StringMapEntryMatcher< KeyMatcherT, ValueMatcherT > IsStringMapEntry(KeyMatcherT KM, ValueMatcherT VM)
Returns a gMock matcher that matches a StringMapEntry whose string key matches KeyMatcher,...
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
typename detail::detector< void, Op, Args... >::value_t is_detected
Detects if a given trait holds for some set of arguments 'Args'.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1847
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:851