107 lines
2.3 KiB
C++
107 lines
2.3 KiB
C++
#include <catch2/catch.hpp>
|
|
#include "../src/core/Shortcut.hpp"
|
|
|
|
using namespace twq::core;
|
|
|
|
class ShortcutTest
|
|
{
|
|
public:
|
|
explicit ShortcutTest() {}
|
|
virtual ~ShortcutTest() {}
|
|
|
|
void test_to_string(std::string const& oracle,
|
|
std::vector<KeyMod> keymods)
|
|
{
|
|
Shortcut sc;
|
|
|
|
for (auto km: keymods)
|
|
{
|
|
sc.push(km);
|
|
}
|
|
|
|
INFO("Expected '" << oracle << "' got '" << sc.string() << "'");
|
|
REQUIRE(oracle == sc.string());
|
|
}
|
|
|
|
void test_from_string(std::string const& oracle,
|
|
std::string const& shortcut)
|
|
{
|
|
Shortcut sc { shortcut };
|
|
INFO("Expected '" << oracle << "' got '" << sc.string() << "'");
|
|
REQUIRE(oracle == sc.string());
|
|
}
|
|
|
|
protected:
|
|
};
|
|
|
|
TEST_CASE_METHOD(ShortcutTest, "Shortcut_string")
|
|
{
|
|
test_to_string("f", {KeyMod {'f'}});
|
|
|
|
test_to_string("a b c", {
|
|
KeyMod {'a'},
|
|
KeyMod {'b'},
|
|
KeyMod {'c'},
|
|
});
|
|
|
|
test_to_string("C-g", {KeyMod {'g', {MOD_LCTRL}}});
|
|
test_to_string("A-g", {KeyMod {'g', {MOD_ALT}}});
|
|
test_to_string("C-A-g", {KeyMod {'g', {MOD_LCTRL, MOD_ALT}}});
|
|
|
|
test_to_string("A-a C-A-b C-c d", {
|
|
KeyMod {'a', {MOD_ALT}},
|
|
KeyMod {'b', {MOD_LCTRL, MOD_ALT}},
|
|
KeyMod {'c', {MOD_LCTRL}},
|
|
KeyMod {'d'},
|
|
});
|
|
|
|
test_to_string("UP", {
|
|
KeyMod::key(KEY_UP)
|
|
});
|
|
|
|
test_to_string("DOWN", {
|
|
KeyMod::key(KEY_DOWN)
|
|
});
|
|
|
|
test_to_string("LEFT", {
|
|
KeyMod::key(KEY_LEFT)
|
|
});
|
|
|
|
test_to_string("RIGHT", {
|
|
KeyMod::key(KEY_RIGHT)
|
|
});
|
|
|
|
test_to_string("C-UP", {
|
|
KeyMod::key(KEY_UP, {MOD_LCTRL})
|
|
});
|
|
|
|
test_to_string("A-LEFT", {
|
|
KeyMod::key(KEY_LEFT, {MOD_ALT}),
|
|
});
|
|
|
|
test_to_string("C-A-RIGHT", {
|
|
KeyMod::key(KEY_RIGHT, {MOD_LCTRL, MOD_ALT}),
|
|
});
|
|
|
|
test_from_string("", "");
|
|
|
|
test_from_string("a", "a");
|
|
test_from_string("a", " a");
|
|
test_from_string("a", "a ");
|
|
|
|
test_from_string("C-a", "C-a");
|
|
test_from_string("C-a", " C-a ");
|
|
test_from_string("A-a", "A-a");
|
|
test_from_string("A-a", " A-a ");
|
|
|
|
test_from_string("C-A-a", " A-C-a ");
|
|
test_from_string("C-A-a", " C-A-a ");
|
|
|
|
test_from_string("C-A-a b C-c", " C-A-a b C-c");
|
|
|
|
test_from_string("C-A-LEFT RIGHT C-UP",
|
|
" C-A-LEFT RIGHT C-UP");
|
|
|
|
REQUIRE_THROWS_AS(Shortcut { "C-A-DUCK" }, invalid_shortcut_error);
|
|
}
|