2023-10-03 17:28:47 +00:00
|
|
|
#include <catch2/catch.hpp>
|
|
|
|
#include "../src/core/Shortcut.hpp"
|
|
|
|
|
|
|
|
using namespace twq::core;
|
|
|
|
|
|
|
|
class ShortcutTest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit ShortcutTest() {}
|
|
|
|
virtual ~ShortcutTest() {}
|
|
|
|
|
2023-10-04 14:56:06 +00:00
|
|
|
void test_to_string(std::wstring const& oracle,
|
|
|
|
std::vector<KeyMod> keymods)
|
2023-10-03 17:28:47 +00:00
|
|
|
{
|
|
|
|
Shortcut sc;
|
|
|
|
|
|
|
|
for (auto km: keymods)
|
|
|
|
{
|
|
|
|
sc.push(km);
|
|
|
|
}
|
|
|
|
|
2023-10-04 14:56:06 +00:00
|
|
|
REQUIRE(oracle == sc.wstring());
|
2023-10-03 17:28:47 +00:00
|
|
|
}
|
|
|
|
|
2023-10-04 14:56:06 +00:00
|
|
|
void test_from_string(std::wstring const& oracle,
|
|
|
|
std::wstring const& shortcut)
|
2023-10-03 17:28:47 +00:00
|
|
|
{
|
|
|
|
Shortcut sc { shortcut };
|
2023-10-04 14:56:06 +00:00
|
|
|
|
|
|
|
REQUIRE(oracle == sc.wstring());
|
2023-10-03 17:28:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_CASE_METHOD(ShortcutTest, "Shortcut_string")
|
|
|
|
{
|
2023-10-04 14:56:06 +00:00
|
|
|
test_to_string(L"f", {KeyMod {'f'}});
|
2023-10-03 17:28:47 +00:00
|
|
|
|
2023-10-04 14:56:06 +00:00
|
|
|
test_to_string(L"a b c", {
|
|
|
|
KeyMod {L'a'},
|
|
|
|
KeyMod {L'b'},
|
|
|
|
KeyMod {L'c'},
|
2023-10-03 17:28:47 +00:00
|
|
|
});
|
|
|
|
|
2023-10-04 14:56:06 +00:00
|
|
|
test_to_string(L"C-g", {KeyMod {L'g', {KM_MOD_LCTRL}}});
|
|
|
|
test_to_string(L"A-g", {KeyMod {L'g', {KM_MOD_ALT}}});
|
|
|
|
test_to_string(L"C-A-g", {KeyMod {L'g', {KM_MOD_LCTRL, KM_MOD_ALT}}});
|
2023-10-03 17:28:47 +00:00
|
|
|
|
2023-10-04 14:56:06 +00:00
|
|
|
test_to_string(L"A-a C-A-b C-c d", {
|
|
|
|
KeyMod {L'a', {KM_MOD_ALT}},
|
|
|
|
KeyMod {L'b', {KM_MOD_LCTRL, KM_MOD_ALT}},
|
|
|
|
KeyMod {L'c', {KM_MOD_LCTRL}},
|
|
|
|
KeyMod {L'd'},
|
2023-10-03 17:28:47 +00:00
|
|
|
});
|
|
|
|
|
2023-10-04 14:56:06 +00:00
|
|
|
test_to_string(L"UP", {
|
|
|
|
KeyMod::key(KM_KEY_UP)
|
2023-10-03 17:28:47 +00:00
|
|
|
});
|
|
|
|
|
2023-10-04 14:56:06 +00:00
|
|
|
test_to_string(L"DOWN", {
|
|
|
|
KeyMod::key(KM_KEY_DOWN)
|
2023-10-03 17:28:47 +00:00
|
|
|
});
|
|
|
|
|
2023-10-04 14:56:06 +00:00
|
|
|
test_to_string(L"LEFT", {
|
|
|
|
KeyMod::key(KM_KEY_LEFT)
|
2023-10-03 17:28:47 +00:00
|
|
|
});
|
|
|
|
|
2023-10-04 14:56:06 +00:00
|
|
|
test_to_string(L"RIGHT", {
|
|
|
|
KeyMod::key(KM_KEY_RIGHT)
|
2023-10-03 17:28:47 +00:00
|
|
|
});
|
|
|
|
|
2023-10-04 14:56:06 +00:00
|
|
|
test_to_string(L"C-UP", {
|
|
|
|
KeyMod::key(KM_KEY_UP, {KM_MOD_LCTRL})
|
2023-10-03 17:28:47 +00:00
|
|
|
});
|
|
|
|
|
2023-10-04 14:56:06 +00:00
|
|
|
test_to_string(L"A-LEFT", {
|
|
|
|
KeyMod::key(KM_KEY_LEFT, {KM_MOD_ALT}),
|
2023-10-03 17:28:47 +00:00
|
|
|
});
|
|
|
|
|
2023-10-04 14:56:06 +00:00
|
|
|
test_to_string(L"C-A-RIGHT", {
|
|
|
|
KeyMod::key(KM_KEY_RIGHT, {KM_MOD_LCTRL, KM_MOD_ALT}),
|
2023-10-03 17:28:47 +00:00
|
|
|
});
|
|
|
|
|
2023-10-04 14:56:06 +00:00
|
|
|
test_from_string(L"", L"");
|
2023-10-03 17:28:47 +00:00
|
|
|
|
2023-10-04 14:56:06 +00:00
|
|
|
test_from_string(L"a", L"a");
|
|
|
|
test_from_string(L"a", L" a");
|
|
|
|
test_from_string(L"a", L"a ");
|
2023-10-03 17:28:47 +00:00
|
|
|
|
2023-10-04 14:56:06 +00:00
|
|
|
test_from_string(L"C-a", L"C-a");
|
|
|
|
test_from_string(L"C-a", L" C-a ");
|
|
|
|
test_from_string(L"A-a", L"A-a");
|
|
|
|
test_from_string(L"A-a", L" A-a ");
|
2023-10-03 17:28:47 +00:00
|
|
|
|
2023-10-04 14:56:06 +00:00
|
|
|
test_from_string(L"C-A-a", L" A-C-a ");
|
|
|
|
test_from_string(L"C-A-a", L" C-A-a ");
|
2023-10-03 17:28:47 +00:00
|
|
|
|
2023-10-04 14:56:06 +00:00
|
|
|
test_from_string(L"C-A-a b C-c", L" C-A-a b C-c");
|
2023-10-03 17:28:47 +00:00
|
|
|
|
2023-10-04 14:56:06 +00:00
|
|
|
test_from_string(L"C-A-LEFT RIGHT C-UP",
|
|
|
|
L" C-A-LEFT RIGHT C-UP");
|
2023-10-03 17:28:47 +00:00
|
|
|
|
2023-10-04 14:56:06 +00:00
|
|
|
REQUIRE_THROWS_AS(Shortcut { L"C-A-DUCK" }, invalid_shortcut_error);
|
2023-10-03 17:28:47 +00:00
|
|
|
}
|