[LVI] Add trunc to i1 handling. (#124480)
[llvm-project.git] / compiler-rt / lib / orc / tests / unit / string_pool_test.cpp
blob456a1d4d7b29a00aa2a516b6c42d74871ee2169c
1 //===---------- string_pool_test.cpp - Unit tests for StringPool ----------===//
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 "string_pool.h"
10 #include "gtest/gtest.h"
12 using namespace orc_rt;
14 namespace {
16 TEST(StringPool, UniquingAndComparisons) {
17 StringPool SP;
18 auto P1 = SP.intern("hello");
20 std::string S("hel");
21 S += "lo";
22 auto P2 = SP.intern(S);
24 auto P3 = SP.intern("goodbye");
26 EXPECT_EQ(P1, P2) << "Failed to unique entries";
27 EXPECT_NE(P1, P3) << "Unequal pooled strings comparing equal";
29 // We want to test that less-than comparison of PooledStringPtrs compiles,
30 // however we can't test the actual result as this is a pointer comparison and
31 // PooledStringPtr doesn't expose the underlying address of the string.
32 (void)(P1 < P3);
35 TEST(StringPool, Dereference) {
36 StringPool SP;
37 auto Foo = SP.intern("foo");
38 EXPECT_EQ(*Foo, "foo") << "Equality on dereferenced string failed";
41 TEST(StringPool, ClearDeadEntries) {
42 StringPool SP;
44 auto P1 = SP.intern("s1");
45 SP.clearDeadEntries();
46 EXPECT_FALSE(SP.empty()) << "\"s1\" entry in pool should still be retained";
48 SP.clearDeadEntries();
49 EXPECT_TRUE(SP.empty()) << "pool should be empty";
52 TEST(StringPool, NullPtr) {
53 // Make sure that we can default construct and then destroy a null
54 // PooledStringPtr.
55 PooledStringPtr Null;
58 TEST(StringPool, Hashable) {
59 StringPool SP;
60 PooledStringPtr P1 = SP.intern("s1");
61 PooledStringPtr Null;
62 EXPECT_NE(std::hash<PooledStringPtr>()(P1),
63 std::hash<PooledStringPtr>()(Null));
66 } // end anonymous namespace