Prevent user from entering incorrect characters in Live Notifications channels list (#3715)

Co-authored-by: Sidd <iProdigy@users.noreply.github.com>
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
kornes
2022-05-08 10:27:25 +00:00
committed by GitHub
parent fd44f30c7d
commit 07dd8c560b
11 changed files with 199 additions and 0 deletions
+105
View File
@@ -159,3 +159,108 @@ TEST(UtilTwitch, StripChannelName)
<< qUtf8Printable(expectedChannelName);
}
}
TEST(UtilTwitch, UserLoginRegexp)
{
struct TestCase {
QString inputUserLogin;
bool matches;
};
std::vector<TestCase> tests{
{
"pajlada",
true,
},
{
// Login names must not start with an underscore
"_pajlada",
false,
},
{
"@pajlada",
false,
},
{
"pajlada!",
false,
},
{
"pajlada,",
false,
},
{
// Login names must not contain capital letters
"Pajlada",
false,
},
{"k", true},
{"testaccount_420", true},
{"3v", true},
{"ron", true},
{"bits", true},
};
const auto &regexp = twitchUserLoginRegexp();
for (const auto &[inputUserLogin, expectedMatch] : tests)
{
const auto &match = regexp.match(inputUserLogin);
auto actual = regexp.match(inputUserLogin);
EXPECT_EQ(match.hasMatch(), expectedMatch)
<< qUtf8Printable(inputUserLogin) << " did not match as expected";
}
}
TEST(UtilTwitch, UserNameRegexp)
{
struct TestCase {
QString inputUserLogin;
bool matches;
};
std::vector<TestCase> tests{
{"PAJLADA", true},
{
// User names must not start with an underscore
"_pajlada",
false,
},
{
"@pajlada",
false,
},
{
"pajlada!",
false,
},
{
"pajlada,",
false,
},
{
"Pajlada",
true,
},
{"k", true},
{"testaccount_420", true},
{"3v", true},
{"ron", true},
{"bits", true},
{"3V", true},
{"Ron", true},
{"Bits", true},
};
const auto &regexp = twitchUserNameRegexp();
for (const auto &[inputUserLogin, expectedMatch] : tests)
{
const auto &match = regexp.match(inputUserLogin);
auto actual = regexp.match(inputUserLogin);
EXPECT_EQ(match.hasMatch(), expectedMatch)
<< qUtf8Printable(inputUserLogin) << " did not match as expected";
}
}