2021-05-24 12:13:59 +02:00
|
|
|
#include "common/ChatterSet.hpp"
|
|
|
|
|
2024-05-05 15:01:07 +02:00
|
|
|
#include "Test.hpp"
|
|
|
|
|
2021-05-24 12:13:59 +02:00
|
|
|
#include <QStringList>
|
|
|
|
|
2024-08-25 15:33:07 +02:00
|
|
|
using namespace chatterino;
|
|
|
|
|
2021-05-24 12:13:59 +02:00
|
|
|
TEST(ChatterSet, insert)
|
|
|
|
{
|
2024-08-25 15:33:07 +02:00
|
|
|
ChatterSet set;
|
2021-05-24 12:13:59 +02:00
|
|
|
|
|
|
|
EXPECT_FALSE(set.contains("pajlada"));
|
|
|
|
EXPECT_FALSE(set.contains("Pajlada"));
|
|
|
|
|
|
|
|
set.addRecentChatter("pajlada");
|
|
|
|
EXPECT_TRUE(set.contains("pajlada"));
|
|
|
|
EXPECT_TRUE(set.contains("Pajlada"));
|
|
|
|
|
|
|
|
set.addRecentChatter("pajlada");
|
|
|
|
EXPECT_TRUE(set.contains("pajlada"));
|
|
|
|
EXPECT_TRUE(set.contains("Pajlada"));
|
|
|
|
|
|
|
|
set.addRecentChatter("PAJLADA");
|
|
|
|
EXPECT_TRUE(set.contains("pajlada"));
|
|
|
|
EXPECT_TRUE(set.contains("Pajlada"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ChatterSet, MaxSize)
|
|
|
|
{
|
2024-08-25 15:33:07 +02:00
|
|
|
ChatterSet set;
|
2021-05-24 12:13:59 +02:00
|
|
|
|
|
|
|
EXPECT_FALSE(set.contains("pajlada"));
|
|
|
|
EXPECT_FALSE(set.contains("Pajlada"));
|
|
|
|
|
|
|
|
set.addRecentChatter("pajlada");
|
|
|
|
EXPECT_TRUE(set.contains("pajlada"));
|
|
|
|
EXPECT_TRUE(set.contains("Pajlada"));
|
|
|
|
|
|
|
|
// After adding CHATTER_LIMIT-1 additional chatters, pajlada should still be in the set
|
2024-08-25 15:33:07 +02:00
|
|
|
for (auto i = 0; i < ChatterSet::CHATTER_LIMIT - 1; ++i)
|
2021-05-24 12:13:59 +02:00
|
|
|
{
|
|
|
|
set.addRecentChatter(QString("%1").arg(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_TRUE(set.contains("pajlada"));
|
|
|
|
EXPECT_TRUE(set.contains("Pajlada"));
|
|
|
|
|
|
|
|
// But adding one more chatter should bump pajlada out of the set
|
|
|
|
set.addRecentChatter("notpajlada");
|
|
|
|
|
|
|
|
EXPECT_FALSE(set.contains("pajlada"));
|
|
|
|
EXPECT_FALSE(set.contains("Pajlada"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ChatterSet, MaxSizeLastUsed)
|
|
|
|
{
|
2024-08-25 15:33:07 +02:00
|
|
|
ChatterSet set;
|
2021-05-24 12:13:59 +02:00
|
|
|
|
|
|
|
EXPECT_FALSE(set.contains("pajlada"));
|
|
|
|
EXPECT_FALSE(set.contains("Pajlada"));
|
|
|
|
|
|
|
|
set.addRecentChatter("pajlada");
|
|
|
|
EXPECT_TRUE(set.contains("pajlada"));
|
|
|
|
EXPECT_TRUE(set.contains("Pajlada"));
|
|
|
|
|
|
|
|
// After adding CHATTER_LIMIT-1 additional chatters, pajlada should still be in the set
|
2024-08-25 15:33:07 +02:00
|
|
|
for (auto i = 0; i < ChatterSet::CHATTER_LIMIT - 1; ++i)
|
2021-05-24 12:13:59 +02:00
|
|
|
{
|
|
|
|
set.addRecentChatter(QString("%1").arg(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_TRUE(set.contains("pajlada"));
|
|
|
|
EXPECT_TRUE(set.contains("Pajlada"));
|
|
|
|
|
|
|
|
// Bump pajlada as a recent chatter
|
|
|
|
set.addRecentChatter("pajlada");
|
|
|
|
|
|
|
|
// After another CHATTER_LIMIT-1 additional chatters, pajlada should still be there
|
2024-08-25 15:33:07 +02:00
|
|
|
for (auto i = 0; i < ChatterSet::CHATTER_LIMIT - 1; ++i)
|
2021-05-24 12:13:59 +02:00
|
|
|
{
|
|
|
|
set.addRecentChatter(QString("new-%1").arg(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_TRUE(set.contains("pajlada"));
|
|
|
|
EXPECT_TRUE(set.contains("Pajlada"));
|
|
|
|
}
|