1 //===-- UniqueCStringMapTest.cpp ------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Core/UniqueCStringMap.h"
10 #include "gmock/gmock.h"
12 using namespace lldb_private
;
18 NoDefault(int x
) : x(x
) {}
21 friend bool operator==(NoDefault lhs
, NoDefault rhs
) {
22 return lhs
.x
== rhs
.x
;
25 friend llvm::raw_ostream
&operator<<(llvm::raw_ostream
&OS
,
27 return OS
<< "NoDefault{" << x
.x
<< "}";
32 TEST(UniqueCStringMap
, NoDefaultConstructor
) {
33 using MapT
= UniqueCStringMap
<NoDefault
>;
34 using EntryT
= MapT::Entry
;
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)));
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");
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));