From 6dd0b1a5ceb4992bd42c585f31b8fd6468786ac5 Mon Sep 17 00:00:00 2001 From: houmain Date: Sat, 7 Sep 2024 08:40:49 +0200 Subject: [PATCH] Allow to override keys with aliases --- src/config/ParseConfig.cpp | 2 -- src/test/test1_ParseConfig.cpp | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/config/ParseConfig.cpp b/src/config/ParseConfig.cpp index 0a082506..8d24b9d9 100644 --- a/src/config/ParseConfig.cpp +++ b/src/config/ParseConfig.cpp @@ -644,8 +644,6 @@ KeySequence ParseConfig::parse_output(It it, It end) { } void ParseConfig::parse_macro(std::string name, It it, It end) { - if (*get_key_by_name(name)) - error("Invalid macro name '" + name + "'"); if (m_system_filter_matched) m_macros[std::move(name)] = preprocess(it, end, false); } diff --git a/src/test/test1_ParseConfig.cpp b/src/test/test1_ParseConfig.cpp index 57e0e26c..fbf24e44 100644 --- a/src/test/test1_ParseConfig.cpp +++ b/src/test/test1_ParseConfig.cpp @@ -744,11 +744,22 @@ TEST_CASE("Macros", "[ParseConfig]") { CHECK(format_sequence(config.contexts[0].outputs[0]) == "+E -E +F -F !Any +A -A +B -B +E -E +F -F"); - // not allowed macro name + // allow to override key names string = R"( - Space = Enter + Alt{A} >> X + + Alt = AltRight + Alt{B} >> Y )"; - CHECK_THROWS(parse_config(string)); + REQUIRE_NOTHROW(config = parse_config(string)); + REQUIRE(config.contexts[0].inputs.size() == 3); + REQUIRE(config.contexts[0].outputs.size() == 2); + REQUIRE(config.contexts[0].command_outputs.size() == 0); + CHECK(format_sequence(config.contexts[0].inputs[0].input) == "+AltLeft +A ~A ~AltLeft"); + CHECK(format_sequence(config.contexts[0].inputs[1].input) == "+AltRight +A ~A ~AltRight"); + CHECK(format_sequence(config.contexts[0].inputs[2].input) == "+AltRight +B ~B ~AltRight"); + CHECK(format_sequence(config.contexts[0].outputs[0]) == "+X"); + CHECK(format_sequence(config.contexts[0].outputs[1]) == "+Y"); } //--------------------------------------------------------------------