1 //===-- UniqueCStringMapTest.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 //===----------------------------------------------------------------------===//
8
9 #include "lldb/Core/UniqueCStringMap.h"
10 #include "gmock/gmock.h"
11
12 using namespace lldb_private;
13
14 namespace {
15 struct NoDefault {
16 int x;
17
NoDefault__anon99c19b860111::NoDefault18 NoDefault(int x) : x(x) {}
19 NoDefault() = delete;
20
operator ==(NoDefault lhs,NoDefault rhs)21 friend bool operator==(NoDefault lhs, NoDefault rhs) {
22 return lhs.x == rhs.x;
23 }
24
operator <<(llvm::raw_ostream & OS,NoDefault x)25 friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
26 NoDefault x) {
27 return OS << "NoDefault{" << x.x << "}";
28 }
29 };
30 } // namespace
31
TEST(UniqueCStringMap,NoDefaultConstructor)32 TEST(UniqueCStringMap, NoDefaultConstructor) {
33 using MapT = UniqueCStringMap<NoDefault>;
34 using EntryT = MapT::Entry;
35
36 MapT Map;
37 ConstString Foo("foo"), Bar("bar");
38
39 Map.Append(Foo, NoDefault(42));
40 EXPECT_THAT(Map.Find(Foo, NoDefault(47)), NoDefault(42));
41 EXPECT_THAT(Map.Find(Bar, NoDefault(47)), NoDefault(47));
42 EXPECT_THAT(Map.FindFirstValueForName(Foo),
43 testing::Pointee(testing::Field(&EntryT::value, NoDefault(42))));
44 EXPECT_THAT(Map.FindFirstValueForName(Bar), nullptr);
45
46 std::vector<NoDefault> Values;
47 EXPECT_THAT(Map.GetValues(Foo, Values), 1);
48 EXPECT_THAT(Values, testing::ElementsAre(NoDefault(42)));
49
50 Values.clear();
51 EXPECT_THAT(Map.GetValues(Bar, Values), 0);
52 EXPECT_THAT(Values, testing::IsEmpty());
53 }
54