1 //===- llvm/unittest/ADT/StringSetTest.cpp - StringSet unit tests ---------===//
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 "llvm/ADT/StringSet.h"
10 #include "llvm/ADT/STLExtras.h"
11 #include "gtest/gtest.h"
17 class StringSetTest
: public testing::Test
{};
19 TEST_F(StringSetTest
, IterSetKeys
) {
26 auto Keys
= to_vector
<4>(Set
.keys());
29 SmallVector
<StringRef
, 4> Expected
= {"A", "B", "C", "D"};
30 EXPECT_EQ(Expected
, Keys
);
33 TEST_F(StringSetTest
, InsertAndCountStringMapEntry
) {
34 // Test insert(StringMapEntry) and count(StringMapEntry)
35 // which are required for set_difference(StringSet, StringSet).
37 StringMapEntry
<StringRef
> *Element
=
38 StringMapEntry
<StringRef
>::create("A", Set
.getAllocator());
40 size_t Count
= Set
.count(*Element
);
42 EXPECT_EQ(Expected
, Count
);
43 Element
->Destroy(Set
.getAllocator());
46 TEST_F(StringSetTest
, EmptyString
) {
47 // Verify that the empty string can by successfully inserted
49 size_t Count
= Set
.count("");
50 EXPECT_EQ(Count
, 0UL);
53 Count
= Set
.count("");
54 EXPECT_EQ(Count
, 1UL);
57 TEST_F(StringSetTest
, Contains
) {
59 EXPECT_FALSE(Set
.contains(""));
60 EXPECT_FALSE(Set
.contains("test"));
64 EXPECT_TRUE(Set
.contains(""));
65 EXPECT_TRUE(Set
.contains("test"));
68 EXPECT_TRUE(Set
.contains(""));
69 EXPECT_TRUE(Set
.contains("test"));
72 EXPECT_TRUE(Set
.contains(""));
73 EXPECT_FALSE(Set
.contains("test"));
76 TEST_F(StringSetTest
, Equal
) {
77 StringSet
<> A
= {"A"};
78 StringSet
<> B
= {"B"};
84 } // end anonymous namespace