diff options
| author | Jules Aguillon | 2025-02-23 12:12:29 +0100 |
|---|---|---|
| committer | GitHub | 2025-02-23 12:12:29 +0100 |
| commit | 68be82a4f92f47300b9960cf9cf65040c96f17ed (patch) | |
| tree | ce79243fe3c1fff7b799af2040a7a76377e4ad5f /test/juloo.keyboard2 | |
| parent | 581b31bf99bf7a4088ef12ea7e03fbc75d5acfed (diff) | |
| download | unexpected-keyboard-68be82a4f92f47300b9960cf9cf65040c96f17ed.tar.gz unexpected-keyboard-68be82a4f92f47300b9960cf9cf65040c96f17ed.zip | |
Macro keys (#878)
Add "macro" keys that behave as if a sequence of keys is typed.
Macro can be added to custom layouts or through the "Add keys to the
keyboard option". The syntax is:
symbol:key1,key2,..
The symbol cannot contain a : character. 'key1', 'key2', etc.. are:
- 'String with \' escaping'
The key will generate the specified string.
- keyevent:123
The key will send a keyevent.
- The name of any special key
Diffstat (limited to 'test/juloo.keyboard2')
| -rw-r--r-- | test/juloo.keyboard2/KeyValueParserTest.java | 103 |
1 files changed, 96 insertions, 7 deletions
diff --git a/test/juloo.keyboard2/KeyValueParserTest.java b/test/juloo.keyboard2/KeyValueParserTest.java index a636ebf..a041e8a 100644 --- a/test/juloo.keyboard2/KeyValueParserTest.java +++ b/test/juloo.keyboard2/KeyValueParserTest.java @@ -10,7 +10,100 @@ public class KeyValueParserTest public KeyValueParserTest() {} @Test - public void parseStr() throws Exception + public void parse_key_value() throws Exception + { + Utils.parse("'", KeyValue.makeStringKey("'")); + Utils.parse("\\'", KeyValue.makeStringKey("\\'")); + Utils.parse("\\,", KeyValue.makeStringKey("\\,")); + Utils.parse("a\\'b", KeyValue.makeStringKey("a\\'b")); + Utils.parse("a\\,b", KeyValue.makeStringKey("a\\,b")); + Utils.parse("a", KeyValue.makeStringKey("a")); + Utils.parse("abc", KeyValue.makeStringKey("abc")); + Utils.parse("shift", KeyValue.getSpecialKeyByName("shift")); + Utils.parse("'a", KeyValue.makeStringKey("'a")); + } + + @Test + public void parse_macro() throws Exception + { + Utils.parse("symbol:abc", KeyValue.makeMacro("symbol", new KeyValue[]{ + KeyValue.makeStringKey("abc") + }, 0)); + Utils.parse("copy:ctrl,a,ctrl,c", KeyValue.makeMacro("copy", new KeyValue[]{ + KeyValue.getSpecialKeyByName("ctrl"), + KeyValue.makeStringKey("a"), + KeyValue.getSpecialKeyByName("ctrl"), + KeyValue.makeStringKey("c") + }, 0)); + Utils.parse("macro:abc,\\'", KeyValue.makeMacro("macro", new KeyValue[]{ + KeyValue.makeStringKey("abc"), + KeyValue.makeStringKey("'") + }, 0)); + Utils.parse("macro:abc,\\,", KeyValue.makeMacro("macro", new KeyValue[]{ + KeyValue.makeStringKey("abc"), + KeyValue.makeStringKey(",") + }, 0)); + Utils.parse("<2:ctrl,backspace", KeyValue.makeMacro("<2", new KeyValue[]{ + KeyValue.getSpecialKeyByName("ctrl"), + KeyValue.getSpecialKeyByName("backspace") + }, 0)); + Utils.expect_error("symbol:"); + Utils.expect_error("unterminated_string:'"); + Utils.expect_error("unterminated_string:abc,'"); + Utils.expect_error("unexpected_quote:abc,,"); + Utils.expect_error("unexpected_quote:,"); + } + + @Test + public void parse_string_key() throws Exception + { + Utils.parse("symbol:'str'", KeyValue.makeMacro("symbol", new KeyValue[]{ + KeyValue.makeStringKey("str") + }, 0)); + Utils.parse("symbol:'str\\''", KeyValue.makeMacro("symbol", new KeyValue[]{ + KeyValue.makeStringKey("str'") + }, 0)); + Utils.parse("macro:'str',abc", KeyValue.makeMacro("macro", new KeyValue[]{ + KeyValue.makeStringKey("str"), + KeyValue.makeStringKey("abc") + }, 0)); + Utils.parse("macro:abc,'str'", KeyValue.makeMacro("macro", new KeyValue[]{ + KeyValue.makeStringKey("abc"), + KeyValue.makeStringKey("str") + }, 0)); + Utils.parse("macro:\\',\\,", KeyValue.makeMacro("macro", new KeyValue[]{ + KeyValue.makeStringKey("'"), + KeyValue.makeStringKey(","), + }, 0)); + Utils.parse("macro:a\\'b,a\\,b,a\\xb", KeyValue.makeMacro("macro", new KeyValue[]{ + KeyValue.makeStringKey("a'b"), + KeyValue.makeStringKey("a,b"), + KeyValue.makeStringKey("axb") + }, 0)); + Utils.expect_error("symbol:'"); + Utils.expect_error("symbol:'foo"); + } + + @Test + public void parse_key_event() throws Exception + { + Utils.parse("symbol:keyevent:85", KeyValue.makeMacro("symbol", new KeyValue[]{ + KeyValue.keyeventKey("", 85, 0) + }, 0)); + Utils.parse("macro:keyevent:85,abc", KeyValue.makeMacro("macro", new KeyValue[]{ + KeyValue.keyeventKey("", 85, 0), + KeyValue.makeStringKey("abc") + }, 0)); + Utils.parse("macro:abc,keyevent:85", KeyValue.makeMacro("macro", new KeyValue[]{ + KeyValue.makeStringKey("abc"), + KeyValue.keyeventKey("", 85, 0) + }, 0)); + Utils.expect_error("symbol:keyevent:"); + Utils.expect_error("symbol:keyevent:85a"); + } + + @Test + public void parse_old_syntax() throws Exception { Utils.parse(":str:'Foo'", KeyValue.makeStringKey("Foo")); Utils.parse(":str flags='dim':'Foo'", KeyValue.makeStringKey("Foo", KeyValue.FLAG_SECONDARY)); @@ -32,11 +125,7 @@ public class KeyValueParserTest Utils.expect_error(":str flags='' "); Utils.expect_error(":str flags='':"); Utils.expect_error(":str flags='':'"); - } - - @Test - public void parseChar() throws Exception - { + // Char Utils.parse(":char symbol='a':b", KeyValue.makeCharKey('b', "a", 0)); Utils.parse(":char:b", KeyValue.makeCharKey('b', "b", 0)); } @@ -46,7 +135,7 @@ public class KeyValueParserTest { static void parse(String key_descr, KeyValue ref) throws Exception { - assertEquals(ref, KeyValueParser.parse(key_descr)); + assertEquals(ref, KeyValue.getKeyByName(key_descr)); } static void expect_error(String key_descr) |
