[AArch64] Add fpext and fpround costs (#119292)
[llvm-project.git] / llvm / unittests / Testing / ADT / StringMapEntryTest.cpp
blob4bc77410ea70c2e6a355847763869b9adce85bc1
1 //===- StringMapEntryTest.cpp ---------------------------------------------===//
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 //===----------------------------------------------------------------------===//
9 #include "llvm/Testing/ADT/StringMapEntry.h"
10 #include "llvm/ADT/StringMap.h"
12 #include "gtest/gtest.h"
13 #include <sstream>
15 namespace llvm {
16 namespace {
18 using testing::Gt;
19 using testing::Matcher;
20 using testing::StrCaseEq;
21 using testing::StringMatchResultListener;
22 using testing::UnorderedElementsAre;
24 template <typename T> std::string Describe(const Matcher<T> &M, bool Match) {
25 std::stringstream SS;
26 if (Match) {
27 M.DescribeTo(&SS);
28 } else {
29 M.DescribeNegationTo(&SS);
31 return SS.str();
34 template <typename T, typename V>
35 std::string ExplainMatch(const Matcher<T> &Matcher, const V &Value) {
36 StringMatchResultListener Listener;
37 Matcher.MatchAndExplain(Value, &Listener);
38 return Listener.str();
41 TEST(IsStringMapEntryTest, InnerMatchersAreExactValues) {
42 llvm::StringMap<int> Map = {{"A", 1}};
43 EXPECT_THAT(*Map.find("A"), IsStringMapEntry("A", 1));
46 TEST(IsStringMapEntryTest, InnerMatchersAreOtherMatchers) {
47 llvm::StringMap<int> Map = {{"A", 1}};
48 EXPECT_THAT(*Map.find("A"), IsStringMapEntry(StrCaseEq("a"), Gt(0)));
51 TEST(IsStringMapEntryTest, UseAsInnerMatcher) {
52 llvm::StringMap<int> Map = {{"A", 1}, {"B", 2}};
53 EXPECT_THAT(Map, UnorderedElementsAre(IsStringMapEntry("A", 1),
54 IsStringMapEntry("B", 2)));
57 TEST(IsStringMapEntryTest, DescribeSelf) {
58 Matcher<llvm::StringMapEntry<int>> M = IsStringMapEntry("A", 1);
59 EXPECT_EQ(
60 R"(has a string key that is equal to "A", and has a value that is equal to 1)",
61 Describe(M, true));
62 EXPECT_EQ(
63 R"(has a string key that isn't equal to "A", or has a value that isn't equal to 1)",
64 Describe(M, false));
67 TEST(IsStringMapEntryTest, ExplainSelfMatchSuccess) {
68 llvm::StringMap<int> Map = {{"A", 1}};
69 Matcher<llvm::StringMapEntry<int>> M = IsStringMapEntry("A", 1);
70 EXPECT_EQ(R"(which is a match)", ExplainMatch(M, *Map.find("A")));
73 TEST(IsStringMapEntryTest, ExplainSelfMatchFailsOnKey) {
74 llvm::StringMap<int> Map = {{"B", 1}};
75 Matcher<llvm::StringMapEntry<int>> M = IsStringMapEntry("A", 1);
76 EXPECT_EQ(R"(which has a string key that doesn't match)",
77 ExplainMatch(M, *Map.find("B")));
80 TEST(IsStringMapEntryTest, ExplainSelfMatchFailsOnValue) {
81 llvm::StringMap<int> Map = {{"A", 2}};
82 Matcher<llvm::StringMapEntry<int>> M = IsStringMapEntry("A", 1);
83 EXPECT_EQ(R"(which has a value that doesn't match)",
84 ExplainMatch(M, *Map.find("A")));
87 } // namespace
88 } // namespace llvm