Repo created

This commit is contained in:
Fr4nz D13trich 2025-11-21 15:13:05 +01:00
parent f2d952b743
commit 3ecd57d1b2
475 changed files with 37130 additions and 2 deletions

View file

@ -0,0 +1,62 @@
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));
}
@Test
public void stringKeys() throws Exception
{
int state = ComposeKeyData.shift;
assertEquals(apply("𝕨", state), KeyValue.makeStringKey("𝕎"));
assertEquals(apply("𝕩", state), KeyValue.makeStringKey("𝕏"));
}
KeyValue apply(String seq)
{
return ComposeKey.apply(ComposeKeyData.compose, seq);
}
KeyValue apply(String seq, int state)
{
return ComposeKey.apply(state, seq);
}
}

View file

@ -0,0 +1,154 @@
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_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("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
/* Using the [symbol:..] syntax but not resulting in a macro. */
public void parse_non_macro() throws Exception
{
Utils.parse("a:b", KeyValue.makeCharKey('b', "a", 0));
Utils.parse("symbol:abc", KeyValue.makeStringKey("abc").withSymbol("symbol"));
}
@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("a:keyevent:85", KeyValue.keyeventKey("a", 85, 0));
Utils.parse("symbol:keyevent:85", KeyValue.keyeventKey("symbol", 85, KeyValue.FLAG_SMALLER_FONT));
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));
Utils.parse(":str symbol='Symbol':'Foo'", KeyValue.makeStringKey("Foo").withSymbol("Symbol"));
Utils.parse(":str symbol='Symbol' flags='dim':'f'", KeyValue.makeStringKey("f").withSymbol("Symbol").withFlags(KeyValue.FLAG_SECONDARY | KeyValue.FLAG_SMALLER_FONT));
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='':'");
// Char
Utils.parse(":char symbol='a':b", KeyValue.makeCharKey('b', "a", 0));
Utils.parse(":char:b", KeyValue.makeCharKey('b', "b", 0));
}
/** JUnit removes these functions from stacktraces. */
static class Utils
{
static void parse(String key_descr, KeyValue ref) throws Exception
{
assertEquals(ref, KeyValue.getKeyByName(key_descr));
}
static void expect_error(String key_descr)
{
try
{
fail("Expected failure but got " + KeyValueParser.parse(key_descr));
}
catch (KeyValueParser.ParseError e) {}
}
}
}

View file

@ -0,0 +1,44 @@
package juloo.keyboard2;
import android.view.KeyEvent;
import juloo.keyboard2.KeyValue;
import org.junit.Test;
import static org.junit.Assert.*;
public class KeyValueTest
{
public KeyValueTest() {}
@Test
public void equals()
{
assertEquals(KeyValue.makeStringKey("Foo").withSymbol("Symbol"),
KeyValue.makeMacro("Symbol", new KeyValue[] { KeyValue.makeStringKey("Foo") }, 0));
assertEquals(KeyValue.getSpecialKeyByName("tab"),
KeyValue.keyeventKey(0xE00F, KeyEvent.KEYCODE_TAB, KeyValue.FLAG_KEY_FONT | KeyValue.FLAG_SMALLER_FONT));
assertEquals(KeyValue.getSpecialKeyByName("tab").withSymbol("t"),
KeyValue.keyeventKey("t", KeyEvent.KEYCODE_TAB, 0));
assertEquals(KeyValue.getSpecialKeyByName("tab").withSymbol("tab"),
KeyValue.keyeventKey("tab", KeyEvent.KEYCODE_TAB, KeyValue.FLAG_SMALLER_FONT));
}
@Test
public void numpad_script()
{
assertEquals(apply_numpad_script("hindu-arabic"), "٠١٢٣٤٥٦٧٨٩");
assertEquals(apply_numpad_script("bengali"), "০১২৩৪৫৬৭৮৯");
assertEquals(apply_numpad_script("devanagari"), "०१२३४५६७८९");
assertEquals(apply_numpad_script("persian"), "۰۱۲۳۴۵۶۷۸۹");
assertEquals(apply_numpad_script("gujarati"), "૦૧૨૩૪૫૬૭૮૯");
assertEquals(apply_numpad_script("kannada"), "೦೧೨೩೪೫೬೭೮೯");
assertEquals(apply_numpad_script("tamil"), "௦௧௨௩௪௫௬௭௮௯");
}
String apply_numpad_script(String script)
{
StringBuilder b = new StringBuilder();
int map = KeyModifier.modify_numpad_script(script);
for (char c : "0123456789".toCharArray())
b.append(ComposeKey.apply(map, c).getChar());
return b.toString();
}
}

View file

@ -0,0 +1,47 @@
package juloo.keyboard2;
import android.view.KeyEvent;
import juloo.keyboard2.*;
import org.junit.Test;
import static org.junit.Assert.*;
public class ModmapTest
{
public ModmapTest() {}
@Test
public void test()
{
Modmap mm = new Modmap();
mm.add(Modmap.M.Shift, KeyValue.getKeyByName("a"), KeyValue.getKeyByName("b"));
mm.add(Modmap.M.Fn, KeyValue.getKeyByName("c"), KeyValue.getKeyByName("d"));
Utils.apply(mm, "a", KeyValue.Modifier.SHIFT, "b");
Utils.apply(mm, "a", KeyValue.Modifier.FN, "æ");
Utils.apply(mm, "c", KeyValue.Modifier.FN, "d");
}
@Test
public void keyevent_mappings()
{
Modmap mm = new Modmap();
mm.add(Modmap.M.Ctrl, KeyValue.getKeyByName("љ"), KeyValue.getKeyByName("љ:q"));
Utils.apply(mm, "a", KeyValue.Modifier.CTRL, KeyValue.getKeyByName("a").withKeyevent(29));
Utils.apply(mm, "љ", KeyValue.Modifier.CTRL, KeyValue.getKeyByName("љ").withKeyevent(45));
}
static class Utils
{
static void apply(Modmap mm, String a, KeyValue.Modifier mod, String expected)
{
apply(mm, a, mod, KeyValue.getKeyByName(expected));
}
static void apply(Modmap mm, String a, KeyValue.Modifier mod, KeyValue expected)
{
KeyModifier.set_modmap(mm);
KeyValue b = KeyModifier.modify(KeyValue.getKeyByName(a), mod);
KeyModifier.set_modmap(null);
assertEquals(b, expected);
}
}
}