[Workflow] Try to fix code-formatter failing to find changes in some cases.
[llvm-project.git] / lldb / unittests / Core / UniqueCStringMapTest.cpp
blobaa1cdbadc958ef00446e4a38934bbaf2529de8e2
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 //===----------------------------------------------------------------------===//
9 #include "lldb/Core/UniqueCStringMap.h"
10 #include "gmock/gmock.h"
12 using namespace lldb_private;
14 namespace {
15 struct NoDefault {
16 int x;
18 NoDefault(int x) : x(x) {}
19 NoDefault() = delete;
21 friend bool operator==(NoDefault lhs, NoDefault rhs) {
22 return lhs.x == rhs.x;
25 friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
26 NoDefault x) {
27 return OS << "NoDefault{" << x.x << "}";
30 } // namespace
32 TEST(UniqueCStringMap, NoDefaultConstructor) {
33 using MapT = UniqueCStringMap<NoDefault>;
34 using EntryT = MapT::Entry;
36 MapT Map;
37 ConstString Foo("foo"), Bar("bar");
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);
46 std::vector<NoDefault> Values;
47 EXPECT_THAT(Map.GetValues(Foo, Values), 1);
48 EXPECT_THAT(Values, testing::ElementsAre(NoDefault(42)));
50 Values.clear();
51 EXPECT_THAT(Map.GetValues(Bar, Values), 0);
52 EXPECT_THAT(Values, testing::IsEmpty());
55 TEST(UniqueCStringMap, ValueCompare) {
56 UniqueCStringMap<int> Map;
58 ConstString Foo("foo");
60 Map.Append(Foo, 0);
61 Map.Append(Foo, 5);
62 Map.Append(Foo, -5);
64 Map.Sort(std::less<int>());
65 std::vector<int> Values;
66 EXPECT_THAT(Map.GetValues(Foo, Values), 3);
67 EXPECT_THAT(Values, testing::ElementsAre(-5, 0, 5));