Add input completion test suite (#4644)
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -193,7 +193,7 @@ void BttvEmotes::loadEmotes()
|
||||
{
|
||||
if (!Settings::instance().enableBTTVGlobalEmotes)
|
||||
{
|
||||
this->global_.set(EMPTY_EMOTE_MAP);
|
||||
this->setEmotes(EMPTY_EMOTE_MAP);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -203,13 +203,18 @@ void BttvEmotes::loadEmotes()
|
||||
auto emotes = this->global_.get();
|
||||
auto pair = parseGlobalEmotes(result.parseJsonArray(), *emotes);
|
||||
if (pair.first)
|
||||
this->global_.set(
|
||||
this->setEmotes(
|
||||
std::make_shared<EmoteMap>(std::move(pair.second)));
|
||||
return pair.first;
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
|
||||
void BttvEmotes::setEmotes(std::shared_ptr<const EmoteMap> emotes)
|
||||
{
|
||||
this->global_.set(std::move(emotes));
|
||||
}
|
||||
|
||||
void BttvEmotes::loadChannel(std::weak_ptr<Channel> channel,
|
||||
const QString &channelId,
|
||||
const QString &channelDisplayName,
|
||||
|
||||
@@ -29,6 +29,7 @@ public:
|
||||
std::shared_ptr<const EmoteMap> emotes() const;
|
||||
boost::optional<EmotePtr> emote(const EmoteName &name) const;
|
||||
void loadEmotes();
|
||||
void setEmotes(std::shared_ptr<const EmoteMap> emotes);
|
||||
static void loadChannel(std::weak_ptr<Channel> channel,
|
||||
const QString &channelId,
|
||||
const QString &channelDisplayName,
|
||||
|
||||
@@ -265,7 +265,7 @@ void Emojis::loadEmojiSet()
|
||||
}
|
||||
|
||||
std::vector<boost::variant<EmotePtr, QString>> Emojis::parse(
|
||||
const QString &text)
|
||||
const QString &text) const
|
||||
{
|
||||
auto result = std::vector<boost::variant<EmotePtr, QString>>();
|
||||
int lastParsedEmojiEndIndex = 0;
|
||||
@@ -359,7 +359,7 @@ std::vector<boost::variant<EmotePtr, QString>> Emojis::parse(
|
||||
return result;
|
||||
}
|
||||
|
||||
QString Emojis::replaceShortCodes(const QString &text)
|
||||
QString Emojis::replaceShortCodes(const QString &text) const
|
||||
{
|
||||
QString ret(text);
|
||||
auto it = this->findShortCodesRegex_.globalMatch(text);
|
||||
@@ -393,4 +393,14 @@ QString Emojis::replaceShortCodes(const QString &text)
|
||||
return ret;
|
||||
}
|
||||
|
||||
const EmojiMap &Emojis::getEmojis() const
|
||||
{
|
||||
return this->emojis;
|
||||
}
|
||||
|
||||
const std::vector<QString> &Emojis::getShortCodes() const
|
||||
{
|
||||
return this->shortCodes;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -37,16 +37,32 @@ struct EmojiData {
|
||||
|
||||
using EmojiMap = ConcurrentMap<QString, std::shared_ptr<EmojiData>>;
|
||||
|
||||
class Emojis
|
||||
class IEmojis
|
||||
{
|
||||
public:
|
||||
virtual ~IEmojis() = default;
|
||||
|
||||
virtual std::vector<boost::variant<EmotePtr, QString>> parse(
|
||||
const QString &text) const = 0;
|
||||
virtual const EmojiMap &getEmojis() const = 0;
|
||||
virtual const std::vector<QString> &getShortCodes() const = 0;
|
||||
virtual QString replaceShortCodes(const QString &text) const = 0;
|
||||
};
|
||||
|
||||
class Emojis : public IEmojis
|
||||
{
|
||||
public:
|
||||
void initialize();
|
||||
void load();
|
||||
std::vector<boost::variant<EmotePtr, QString>> parse(const QString &text);
|
||||
std::vector<boost::variant<EmotePtr, QString>> parse(
|
||||
const QString &text) const override;
|
||||
|
||||
EmojiMap emojis;
|
||||
std::vector<QString> shortCodes;
|
||||
QString replaceShortCodes(const QString &text);
|
||||
QString replaceShortCodes(const QString &text) const override;
|
||||
|
||||
const EmojiMap &getEmojis() const override;
|
||||
const std::vector<QString> &getShortCodes() const override;
|
||||
|
||||
private:
|
||||
void loadEmojis();
|
||||
|
||||
@@ -188,7 +188,7 @@ void FfzEmotes::loadEmotes()
|
||||
{
|
||||
if (!Settings::instance().enableFFZGlobalEmotes)
|
||||
{
|
||||
this->global_.set(EMPTY_EMOTE_MAP);
|
||||
this->setEmotes(EMPTY_EMOTE_MAP);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -199,13 +199,18 @@ void FfzEmotes::loadEmotes()
|
||||
.timeout(30000)
|
||||
.onSuccess([this](auto result) -> Outcome {
|
||||
auto parsedSet = parseGlobalEmotes(result.parseJson());
|
||||
this->global_.set(std::make_shared<EmoteMap>(std::move(parsedSet)));
|
||||
this->setEmotes(std::make_shared<EmoteMap>(std::move(parsedSet)));
|
||||
|
||||
return Success;
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
|
||||
void FfzEmotes::setEmotes(std::shared_ptr<const EmoteMap> emotes)
|
||||
{
|
||||
this->global_.set(std::move(emotes));
|
||||
}
|
||||
|
||||
void FfzEmotes::loadChannel(
|
||||
std::weak_ptr<Channel> channel, const QString &channelID,
|
||||
std::function<void(EmoteMap &&)> emoteCallback,
|
||||
|
||||
@@ -22,6 +22,7 @@ public:
|
||||
std::shared_ptr<const EmoteMap> emotes() const;
|
||||
boost::optional<EmotePtr> emote(const EmoteName &name) const;
|
||||
void loadEmotes();
|
||||
void setEmotes(std::shared_ptr<const EmoteMap> emotes);
|
||||
static void loadChannel(
|
||||
std::weak_ptr<Channel> channel, const QString &channelId,
|
||||
std::function<void(EmoteMap &&)> emoteCallback,
|
||||
|
||||
@@ -275,7 +275,7 @@ void SeventvEmotes::loadGlobalEmotes()
|
||||
{
|
||||
if (!Settings::instance().enableSevenTVGlobalEmotes)
|
||||
{
|
||||
this->global_.set(EMPTY_EMOTE_MAP);
|
||||
this->setGlobalEmotes(EMPTY_EMOTE_MAP);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -289,7 +289,8 @@ void SeventvEmotes::loadGlobalEmotes()
|
||||
auto emoteMap = parseEmotes(parsedEmotes, true);
|
||||
qCDebug(chatterinoSeventv)
|
||||
<< "Loaded" << emoteMap.size() << "7TV Global Emotes";
|
||||
this->global_.set(std::make_shared<EmoteMap>(std::move(emoteMap)));
|
||||
this->setGlobalEmotes(
|
||||
std::make_shared<EmoteMap>(std::move(emoteMap)));
|
||||
|
||||
return Success;
|
||||
})
|
||||
@@ -300,6 +301,11 @@ void SeventvEmotes::loadGlobalEmotes()
|
||||
.execute();
|
||||
}
|
||||
|
||||
void SeventvEmotes::setGlobalEmotes(std::shared_ptr<const EmoteMap> emotes)
|
||||
{
|
||||
this->global_.set(std::move(emotes));
|
||||
}
|
||||
|
||||
void SeventvEmotes::loadChannelEmotes(
|
||||
const std::weak_ptr<Channel> &channel, const QString &channelId,
|
||||
std::function<void(EmoteMap &&, ChannelInfo)> callback, bool manualRefresh)
|
||||
|
||||
@@ -75,6 +75,7 @@ public:
|
||||
std::shared_ptr<const EmoteMap> globalEmotes() const;
|
||||
boost::optional<EmotePtr> globalEmote(const EmoteName &name) const;
|
||||
void loadGlobalEmotes();
|
||||
void setGlobalEmotes(std::shared_ptr<const EmoteMap> emotes);
|
||||
static void loadChannelEmotes(
|
||||
const std::weak_ptr<Channel> &channel, const QString &channelId,
|
||||
std::function<void(EmoteMap &&, ChannelInfo)> callback,
|
||||
|
||||
@@ -23,7 +23,21 @@ class TwitchChannel;
|
||||
class BttvLiveUpdates;
|
||||
class SeventvEventAPI;
|
||||
|
||||
class TwitchIrcServer final : public AbstractIrcServer, public Singleton
|
||||
class ITwitchIrcServer
|
||||
{
|
||||
public:
|
||||
virtual ~ITwitchIrcServer() = default;
|
||||
|
||||
virtual const BttvEmotes &getBttvEmotes() const = 0;
|
||||
virtual const FfzEmotes &getFfzEmotes() const = 0;
|
||||
virtual const SeventvEmotes &getSeventvEmotes() const = 0;
|
||||
|
||||
// Update this interface with TwitchIrcServer methods as needed
|
||||
};
|
||||
|
||||
class TwitchIrcServer final : public AbstractIrcServer,
|
||||
public Singleton,
|
||||
public ITwitchIrcServer
|
||||
{
|
||||
public:
|
||||
TwitchIrcServer();
|
||||
@@ -70,9 +84,9 @@ public:
|
||||
std::unique_ptr<BttvLiveUpdates> bttvLiveUpdates;
|
||||
std::unique_ptr<SeventvEventAPI> seventvEventAPI;
|
||||
|
||||
const BttvEmotes &getBttvEmotes() const;
|
||||
const FfzEmotes &getFfzEmotes() const;
|
||||
const SeventvEmotes &getSeventvEmotes() const;
|
||||
const BttvEmotes &getBttvEmotes() const override;
|
||||
const FfzEmotes &getFfzEmotes() const override;
|
||||
const SeventvEmotes &getSeventvEmotes() const override;
|
||||
|
||||
protected:
|
||||
virtual void initializeConnection(IrcConnection *connection,
|
||||
|
||||
@@ -12,7 +12,7 @@ If you're adding support for a new endpoint, these are the things you should kno
|
||||
|
||||
1. Add a virtual function in the `IHelix` class. Naming should reflect the API name as best as possible.
|
||||
1. Override the virtual function in the `Helix` class.
|
||||
1. Mock the function in the `MockHelix` class in the `tests/src/HighlightController.cpp` file.
|
||||
1. Mock the function in the `mock::Helix` class in the `mocks/include/mocks/Helix.hpp` file.
|
||||
1. (Optional) Make a new error enum for the failure callback.
|
||||
|
||||
For a simple example, see the `updateUserChatColor` function and its error enum `HelixUpdateUserChatColorError`.
|
||||
|
||||
Reference in New Issue
Block a user