Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: added unit tests for the new mention for channel_mention, user_mention, role_mention and emoji_mention in utility the namespace #576

Merged
merged 4 commits into from
Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions src/dpp/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,19 +447,15 @@ namespace dpp {
}

std::string emoji_mention(const std::string &name, const snowflake &id, bool is_animated) {
static auto format = [=](){
return id ? ((is_animated ? "a:" : "") + name + ":" + std::to_string(id)) : name;
};
auto format = [=]() {
return id ? ((is_animated ? "a:" : ":") + name + ":" + std::to_string(id)) : name;
};

if (id) {
if (is_animated) {
return "<" + format() + ">";
if (id) {
return "<" + format() + ">";
} else {
return "<:" + format() + ">";
return ":" + format() + ":";
}
} else {
return ":" + format() + ":";
}
}

std::string role_mention(const snowflake &id) {
Expand Down
24 changes: 24 additions & 0 deletions src/unittest/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,30 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b
auto mention3 = dpp::utility::slashcommand_mention(123, "name", "group", "sub");
bool success = mention1 == "</name:123>" && mention2 == "</name sub:123>" && mention3 == "</name group sub:123>";
set_test("UTILITY.SLASHCOMMAND_MENTION", success);

set_test("UTILITY.CHANNEL_MENTION", false);
auto channel_mention = dpp::utility::channel_mention(123);
set_test("UTILITY.CHANNEL_MENTION", channel_mention == "<#123>");

set_test("UTILITY.USER_MENTION", false);
auto user_mention = dpp::utility::user_mention(123);
set_test("UTILITY.USER_MENTION", user_mention == "<@123>");

set_test("UTILITY.ROLE_MENTION", false);
auto role_mention = dpp::utility::role_mention(123);
set_test("UTILITY.ROLE_MENTION", role_mention == "<@&123>");

set_test("UTILITY.EMOJI_MENTION", false);
auto emoji_mention1 = dpp::utility::emoji_mention("role1", 123, false);
auto emoji_mention2 = dpp::utility::emoji_mention("role2", 234, true);
auto emoji_mention3 = dpp::utility::emoji_mention("white_check_mark", 0, false);
auto emoji_mention4 = dpp::utility::emoji_mention("white_check_mark", 0, true);
set_test("UTILITY.EMOJI_MENTION",
emoji_mention1 == "<:role1:123>" &&
emoji_mention2 == "<a:role2:234>" &&
emoji_mention3 == ":white_check_mark:" &&
emoji_mention4 == ":white_check_mark:"
);
}

#ifndef _WIN32
Expand Down
4 changes: 4 additions & 0 deletions src/unittest/unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ std::map<std::string, test_t> tests = {
{"UTILITY.TOKENIZE", {tt_offline, "utility::tokenize", false, false}},
{"UTILITY.URL_ENCODE", {tt_offline, "utility::url_encode", false, false}},
{"UTILITY.SLASHCOMMAND_MENTION", {tt_offline, "utility::slashcommand_mention", false, false}},
{"UTILITY.CHANNEL_MENTION", {tt_offline, "utility::channel_mention", false, false}},
{"UTILITY.USER_MENTION", {tt_offline, "utility::user_mention", false, false}},
{"UTILITY.ROLE_MENTION", {tt_offline, "utility::role_mention", false, false}},
{"UTILITY.EMOJI_MENTION", {tt_offline, "utility::emoji_mention", false, false}},
{"ROLE.COMPARE", {tt_offline, "role::operator<", false, false}},
{"ROLE_CREATE", {tt_online, "cluster::role_create", false, false}},
{"ROLE_EDIT", {tt_online, "cluster::role_edit", false, false}},
Expand Down