abouttreesummaryrefslogcommitdiff
path: root/test
diff options
context:
space:
mode:
authorJules Aguillon2025-01-03 11:38:39 +0100
committerJules Aguillon2025-01-03 11:43:38 +0100
commite8c20bf52167e944bf811ce3684ee6334ff113fa (patch)
tree8f67ee14260ed67dc1235f179b614f501df7d9fe /test
parent56c62a005d0afde3f525da9beb47c2ac834cb7df (diff)
downloadunexpected-keyboard-e8c20bf52167e944bf811ce3684ee6334ff113fa.tar.gz
unexpected-keyboard-e8c20bf52167e944bf811ce3684ee6334ff113fa.zip
test: Add ComposeKeyTest
Diffstat (limited to 'test')
-rw-r--r--test/juloo.keyboard2/ComposeKeyTest.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/test/juloo.keyboard2/ComposeKeyTest.java b/test/juloo.keyboard2/ComposeKeyTest.java
new file mode 100644
index 0000000..3d0b371
--- /dev/null
+++ b/test/juloo.keyboard2/ComposeKeyTest.java
@@ -0,0 +1,63 @@
+package juloo.keyboard2;
+
+import juloo.keyboard2.ComposeKey;
+import juloo.keyboard2.ComposeKeyData;
+import juloo.keyboard2.KeyValue;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class ComposeKeyTest
+{
+ public ComposeKeyTest() {}
+
+ @Test
+ public void composeEquals() throws Exception
+ {
+ // From Compose.pre
+ assertEquals(apply("'e"), KeyValue.makeStringKey("é"));
+ assertEquals(apply("e'"), KeyValue.makeStringKey("é"));
+ // From extra.json
+ assertEquals(apply("Vc"), KeyValue.makeStringKey("Č"));
+ assertEquals(apply("\\n"), KeyValue.getKeyByName("\\n"));
+ // From arabic.json
+ assertEquals(apply("اا"), KeyValue.getKeyByName("combining_alef_above"));
+ assertEquals(apply("ل۷"), KeyValue.makeStringKey("ڵ"));
+ assertEquals(apply("۷ل"), KeyValue.makeStringKey("ڵ"));
+ // From cyrillic.json
+ assertEquals(apply(",г"), KeyValue.makeStringKey("ӻ"));
+ assertEquals(apply("г,"), KeyValue.makeStringKey("ӻ"));
+ assertEquals(apply("ач"), KeyValue.getKeyByName("combining_aigu"));
+ }
+
+ @Test
+ public void fnEquals() throws Exception
+ {
+ int state = ComposeKeyData.fn;
+ assertEquals(apply("<", state), KeyValue.makeStringKey("«"));
+ assertEquals(apply("{", state), KeyValue.makeStringKey("‹"));
+ // Named key
+ assertEquals(apply("1", state), KeyValue.getKeyByName("f1"));
+ assertEquals(apply(" ", state), KeyValue.getKeyByName("nbsp"));
+ // Named 1-char key
+ assertEquals(apply("ய", state), KeyValue.makeStringKey("௰", KeyValue.FLAG_SMALLER_FONT));
+ }
+
+ KeyValue apply(String seq) throws Exception
+ {
+ return apply(seq, ComposeKeyData.compose);
+ }
+
+ KeyValue apply(String seq, int state) throws Exception
+ {
+ KeyValue r = null;
+ for (int i = 0; i < seq.length(); i++)
+ {
+ r = ComposeKey.apply(state, seq.charAt(i));
+ if (r.getKind() == KeyValue.Kind.Compose_pending)
+ state = r.getPendingCompose();
+ else if (i + 1 < seq.length())
+ throw new Exception("Sequence too long: " + seq);
+ }
+ return r;
+ }
+}