abouttreesummaryrefslogcommitdiff
path: root/test/juloo.keyboard2/KeyValueParserTest.java
diff options
context:
space:
mode:
authorJules Aguillon2024-09-29 21:58:22 +0200
committerGitHub2024-09-29 21:58:22 +0200
commit9f22e53a3ba8f064e69e3a84c371a7f29ee9e05c (patch)
tree96735329102cdde5460818f22803e67dc42c6356 /test/juloo.keyboard2/KeyValueParserTest.java
parente309b76c0a8cb4c322b5fa902a080e19c2fe1f08 (diff)
downloadunexpected-keyboard-9f22e53a3ba8f064e69e3a84c371a7f29ee9e05c.tar.gz
unexpected-keyboard-9f22e53a3ba8f064e69e3a84c371a7f29ee9e05c.zip
Add complex keys (#774)
This allows to add new kinds of keys that need more data without making KeyValue's footprint bigger for common keys. This changes the [_symbol] field into [_payload], which holds the same as the previous field for more common keys but can hold bigger objects for keys of the new "Complex" kind. This also adds a complex key: String keys with a symbol different than the outputted string. Unit tests are added as the Java language is not helpful in making robust code.
Diffstat (limited to 'test/juloo.keyboard2/KeyValueParserTest.java')
-rw-r--r--test/juloo.keyboard2/KeyValueParserTest.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/juloo.keyboard2/KeyValueParserTest.java b/test/juloo.keyboard2/KeyValueParserTest.java
new file mode 100644
index 0000000..900ae3d
--- /dev/null
+++ b/test/juloo.keyboard2/KeyValueParserTest.java
@@ -0,0 +1,54 @@
+package juloo.keyboard2;
+
+import juloo.keyboard2.KeyValue;
+import juloo.keyboard2.KeyValueParser;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class KeyValueParserTest
+{
+ public KeyValueParserTest() {}
+
+ @Test
+ public void parse() throws Exception
+ {
+ Utils.parse(":str:'Foo'", KeyValue.makeStringKey("Foo"));
+ Utils.parse(":str flags='dim':'Foo'", KeyValue.makeStringKey("Foo", KeyValue.FLAG_SECONDARY));
+ Utils.parse(":str symbol='Symbol':'Foo'", KeyValue.makeStringKeyWithSymbol("Foo", "Symbol", 0));
+ Utils.parse(":str symbol='Symbol' flags='dim':'Foo'", KeyValue.makeStringKeyWithSymbol("Foo", "Symbol", KeyValue.FLAG_SECONDARY));
+ Utils.parse(":str flags='dim,small':'Foo'", KeyValue.makeStringKey("Foo", KeyValue.FLAG_SECONDARY | KeyValue.FLAG_SMALLER_FONT));
+ Utils.parse(":str flags=',,':'Foo'", KeyValue.makeStringKey("Foo")); // Unintentional
+ Utils.expect_error(":unknown:Foo"); // Unknown kind
+ Utils.expect_error(":str:Foo"); // Unquoted string
+ Utils.expect_error(":str flags:'Foo'"); // Malformed flags
+ Utils.expect_error(":str flags=dim:'Foo'"); // Unquoted flags
+ Utils.expect_error(":str unknown='foo':'Foo'"); // Unknown flags
+ // Unterminated
+ Utils.expect_error(":str");
+ Utils.expect_error(":str ");
+ Utils.expect_error(":str flags");
+ Utils.expect_error(":str flags=");
+ Utils.expect_error(":str flags='");
+ Utils.expect_error(":str flags='' ");
+ Utils.expect_error(":str flags='':");
+ Utils.expect_error(":str flags='':'");
+ }
+
+ /** JUnit removes these functions from stacktraces. */
+ static class Utils
+ {
+ static void parse(String key_descr, KeyValue ref) throws Exception
+ {
+ assertEquals(ref, KeyValueParser.parse(key_descr));
+ }
+
+ static void expect_error(String key_descr)
+ {
+ try
+ {
+ fail("Expected failure but got " + KeyValueParser.parse(key_descr));
+ }
+ catch (KeyValueParser.ParseError e) {}
+ }
+ }
+}