Fix test failures introduced by PR #113697 (#116941)
[llvm-project.git] / llvm / unittests / ADT / StringSetTest.cpp
bloba804c1f17d1ce2b4bc020fd2f6056d7e31e12427
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 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/StringSet.h"
10 #include "llvm/ADT/STLExtras.h"
11 #include "gtest/gtest.h"
12 using namespace llvm;
14 namespace {
16 // Test fixture
17 class StringSetTest : public testing::Test {};
19 TEST_F(StringSetTest, IterSetKeys) {
20 StringSet<> Set;
21 Set.insert("A");
22 Set.insert("B");
23 Set.insert("C");
24 Set.insert("D");
26 auto Keys = to_vector<4>(Set.keys());
27 llvm::sort(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).
36 StringSet<> Set;
37 StringMapEntry<StringRef> *Element =
38 StringMapEntry<StringRef>::create("A", Set.getAllocator());
39 Set.insert(*Element);
40 size_t Count = Set.count(*Element);
41 size_t Expected = 1;
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
48 StringSet<> Set;
49 size_t Count = Set.count("");
50 EXPECT_EQ(Count, 0UL);
52 Set.insert("");
53 Count = Set.count("");
54 EXPECT_EQ(Count, 1UL);
57 TEST_F(StringSetTest, Contains) {
58 StringSet<> Set;
59 EXPECT_FALSE(Set.contains(""));
60 EXPECT_FALSE(Set.contains("test"));
62 Set.insert("");
63 Set.insert("test");
64 EXPECT_TRUE(Set.contains(""));
65 EXPECT_TRUE(Set.contains("test"));
67 Set.insert("test");
68 EXPECT_TRUE(Set.contains(""));
69 EXPECT_TRUE(Set.contains("test"));
71 Set.erase("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"};
79 ASSERT_TRUE(A != B);
80 ASSERT_FALSE(A == B);
81 ASSERT_TRUE(A == A);
84 } // end anonymous namespace