mirror-chatterino2/tests/src/Hotkeys.cpp
Mm2PL 703f3717e2
Add custom hotkeys. (#2340)
Co-authored-by: LosFarmosCTL <80157503+LosFarmosCTL@users.noreply.github.com>
Co-authored-by: Paweł <zneix@zneix.eu>
Co-authored-by: Felanbird <41973452+Felanbird@users.noreply.github.com>
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
2021-11-21 17:46:21 +00:00

86 lines
1.9 KiB
C++

#include "controllers/hotkeys/HotkeyHelpers.hpp"
#include <gtest/gtest.h>
#include <vector>
using namespace chatterino;
struct argumentTest {
const char *label;
QString input;
std::vector<QString> expected;
};
TEST(HotkeyHelpers, parseHotkeyArguments)
{
std::vector<argumentTest> tests{
{
"Empty input must result in an empty vector",
"",
{},
},
{
"Leading and trailing newlines/spaces are removed",
"\n",
{},
},
{
"Single argument",
"foo",
{"foo"},
},
{
"Single argument with trailing space trims the space",
"foo ",
{"foo"},
},
{
"Single argument with trailing newline trims the newline",
"foo\n",
{"foo"},
},
{
"Multiple arguments with leading and trailing spaces trims them",
" foo \n bar \n baz ",
{"foo", "bar", "baz"},
},
{
"Multiple trailing newlines are trimmed",
"foo\n\n",
{"foo"},
},
{
"Leading newline is trimmed",
"\nfoo",
{"foo"},
},
{
"Leading newline + space trimmed",
"\n foo",
{"foo"},
},
{
"Multiple leading newline trimmed",
"\n\nfoo",
{"foo"},
},
{
"2 rows results in 2 vectors",
"foo\nbar",
{"foo", "bar"},
},
{
"Multiple newlines in the middle are not trimmed",
"foo\n\nbar",
{"foo", "", "bar"},
},
};
for (const auto &[label, input, expected] : tests)
{
auto output = parseHotkeyArguments(input);
EXPECT_EQ(output, expected) << label;
}
}