#include #include "../src/core/Shortcut.hpp" using namespace twq::core; class ShortcutTest { public: explicit ShortcutTest() {} virtual ~ShortcutTest() {} void test_to_string(std::wstring const& oracle, std::vector keymods) { Shortcut sc; for (auto km: keymods) { sc.push(km); } REQUIRE(oracle == sc.wstring()); } void test_from_string(std::wstring const& oracle, std::wstring const& shortcut) { Shortcut sc { shortcut }; REQUIRE(oracle == sc.wstring()); } protected: }; TEST_CASE_METHOD(ShortcutTest, "Shortcut_string") { test_to_string(L"f", {KeyMod {'f'}}); test_to_string(L"a b c", { KeyMod {L'a'}, KeyMod {L'b'}, KeyMod {L'c'}, }); 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}}}); 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'}, }); test_to_string(L"UP", { KeyMod::key(KM_KEY_UP) }); test_to_string(L"DOWN", { KeyMod::key(KM_KEY_DOWN) }); test_to_string(L"LEFT", { KeyMod::key(KM_KEY_LEFT) }); test_to_string(L"RIGHT", { KeyMod::key(KM_KEY_RIGHT) }); test_to_string(L"C-UP", { KeyMod::key(KM_KEY_UP, {KM_MOD_LCTRL}) }); test_to_string(L"A-LEFT", { KeyMod::key(KM_KEY_LEFT, {KM_MOD_ALT}), }); test_to_string(L"C-A-RIGHT", { KeyMod::key(KM_KEY_RIGHT, {KM_MOD_LCTRL, KM_MOD_ALT}), }); test_from_string(L"", L""); test_from_string(L"a", L"a"); test_from_string(L"a", L" a"); test_from_string(L"a", L"a "); 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 "); test_from_string(L"C-A-a", L" A-C-a "); test_from_string(L"C-A-a", L" C-A-a "); test_from_string(L"C-A-a b C-c", L" C-A-a b C-c"); test_from_string(L"C-A-LEFT RIGHT C-UP", L" C-A-LEFT RIGHT C-UP"); REQUIRE_THROWS_AS(Shortcut { L"C-A-DUCK" }, invalid_shortcut_error); }