From 8b200e765e3c370e549856e7d66f3b22edf38dfd Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Wed, 11 Oct 2023 00:07:32 +0200 Subject: [PATCH] add filter test making sure the context map is the correct length --- tests/src/Filters.cpp | 115 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/tests/src/Filters.cpp b/tests/src/Filters.cpp index 97763dc1dce..87f95c7860a 100644 --- a/tests/src/Filters.cpp +++ b/tests/src/Filters.cpp @@ -1,5 +1,17 @@ +#include "controllers/accounts/AccountController.hpp" #include "controllers/filters/lang/Filter.hpp" #include "controllers/filters/lang/Types.hpp" +#include "controllers/highlights/HighlightController.hpp" +#include "mocks/Channel.hpp" +#include "mocks/EmptyApplication.hpp" +#include "mocks/TwitchIrcServer.hpp" +#include "mocks/UserData.hpp" +#include "providers/chatterino/ChatterinoBadges.hpp" +#include "providers/ffz/FfzBadges.hpp" +#include "providers/seventv/SeventvBadges.hpp" +#include "providers/twitch/TwitchBadge.hpp" +#include "providers/twitch/TwitchMessageBuilder.hpp" +#include "singletons/Emotes.hpp" #include #include @@ -7,9 +19,83 @@ using namespace chatterino; using namespace chatterino::filters; +using chatterino::mock::MockChannel; TypingContext typingContext = MESSAGE_TYPING_CONTEXT; +namespace { + +class MockApplication : mock::EmptyApplication +{ +public: + IEmotes *getEmotes() override + { + return &this->emotes; + } + + IUserDataController *getUserData() override + { + return &this->userData; + } + + AccountController *getAccounts() override + { + return &this->accounts; + } + + ITwitchIrcServer *getTwitch() override + { + return &this->twitch; + } + + ChatterinoBadges *getChatterinoBadges() override + { + return &this->chatterinoBadges; + } + + FfzBadges *getFfzBadges() override + { + return &this->ffzBadges; + } + + SeventvBadges *getSeventvBadges() override + { + return &this->seventvBadges; + } + + HighlightController *getHighlights() override + { + return &this->highlights; + } + + AccountController accounts; + Emotes emotes; + mock::UserDataController userData; + mock::MockTwitchIrcServer twitch; + ChatterinoBadges chatterinoBadges; + FfzBadges ffzBadges; + SeventvBadges seventvBadges; + HighlightController highlights; +}; + +class FiltersF : public ::testing::Test +{ +protected: + void SetUp() override + { + this->mockApplication = std::make_unique(); + } + + void TearDown() override + { + this->mockApplication.reset(); + } + + std::unique_ptr mockApplication; +}; + +} // namespace + namespace chatterino::filters { std::ostream &operator<<(std::ostream &os, Type t) @@ -170,3 +256,32 @@ TEST(Filters, Evaluation) << qUtf8Printable(filter.debugString(typingContext)); } } + +TEST_F(FiltersF, TypingContextChecks) +{ + MockChannel channel("pajlada"); + + QByteArray message = + R"(@badge-info=subscriber/80;badges=broadcaster/1,subscriber/3072,partner/1;color=#CC44FF;display-name=pajlada;emote-only=1;emotes=25:0-4;first-msg=0;flags=;id=90ef1e46-8baa-4bf2-9c54-272f39d6fa11;mod=0;returning-chatter=0;room-id=11148817;subscriber=1;tmi-sent-ts=1662206235860;turbo=0;user-id=11148817;user-type= :pajlada!pajlada@pajlada.tmi.twitch.tv PRIVMSG #pajlada :ACTION Kappa)"; + + struct TestCase { + QByteArray input; + }; + + auto *privmsg = dynamic_cast( + Communi::IrcPrivateMessage::fromData(message, nullptr)); + EXPECT_NE(privmsg, nullptr); + + QString originalMessage = privmsg->content(); + + TwitchMessageBuilder builder(&channel, privmsg, MessageParseArgs{}); + + auto msg = builder.build(); + EXPECT_NE(msg.get(), nullptr); + + auto contextMap = buildContextMap(msg, &channel); + + EXPECT_EQ(contextMap.size(), MESSAGE_TYPING_CONTEXT.size()); + + delete privmsg; +}