#include "string_pool.h"
#include "gtest/gtest.h"
using namespace __orc_rt;
namespace {
TEST(StringPool, UniquingAndComparisons) {
StringPool SP;
auto P1 = SP.intern("hello");
std::string S("hel");
S += "lo";
auto P2 = SP.intern(S);
auto P3 = SP.intern("goodbye");
EXPECT_EQ(P1, P2) << "Failed to unique entries";
EXPECT_NE(P1, P3) << "Unequal pooled strings comparing equal";
(void)(P1 < P3);
}
TEST(StringPool, Dereference) {
StringPool SP;
auto Foo = SP.intern("foo");
EXPECT_EQ(*Foo, "foo") << "Equality on dereferenced string failed";
}
TEST(StringPool, ClearDeadEntries) {
StringPool SP;
{
auto P1 = SP.intern("s1");
SP.clearDeadEntries();
EXPECT_FALSE(SP.empty()) << "\"s1\" entry in pool should still be retained";
}
SP.clearDeadEntries();
EXPECT_TRUE(SP.empty()) << "pool should be empty";
}
TEST(StringPool, NullPtr) {
PooledStringPtr Null;
}
TEST(StringPool, Hashable) {
StringPool SP;
PooledStringPtr P1 = SP.intern("s1");
PooledStringPtr Null;
EXPECT_NE(std::hash<PooledStringPtr>()(P1),
std::hash<PooledStringPtr>()(Null));
}
}