xref: /llvm-project/llvm/unittests/ADT/StringSetTest.cpp (revision 0bddef79019a23ab14fcdb27028e55e484674c88)
1 //===- llvm/unittest/ADT/StringSetTest.cpp - StringSet unit tests ----------===//
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 "llvm/ADT/StringSet.h"
10 #include "gtest/gtest.h"
11 using namespace llvm;
12 
13 namespace {
14 
15 // Test fixture
16 class StringSetTest : public testing::Test {};
17 
18 TEST_F(StringSetTest, IterSetKeys) {
19   StringSet<> Set;
20   Set.insert("A");
21   Set.insert("B");
22   Set.insert("C");
23   Set.insert("D");
24 
25   auto Keys = to_vector<4>(Set.keys());
26   llvm::sort(Keys);
27 
28   SmallVector<StringRef, 4> Expected = {"A", "B", "C", "D"};
29   EXPECT_EQ(Expected, Keys);
30 }
31 
32 TEST_F(StringSetTest, InsertAndCountStringMapEntry) {
33   // Test insert(StringMapEntry) and count(StringMapEntry)
34   // which are required for set_difference(StringSet, StringSet).
35   StringSet<> Set;
36   StringMapEntry<StringRef> Element(1, "A");
37   Set.insert(Element);
38   size_t Count = Set.count(Element);
39   size_t Expected = 1;
40   EXPECT_EQ(Expected, Count);
41 }
42 
43 } // end anonymous namespace
44