Browse Source

Add configuration and tests for double caps.

scossu 1 year ago
parent
commit
67e11e8f3d

+ 12 - 0
scriptshifter/tables/__init__.py

@@ -120,6 +120,10 @@ def load_table(tname):
     parents = tdata.get("general", {}).get("parents", [])
 
     if "script_to_roman" in tdata:
+        if "double_cap" in tdata["script_to_roman"]:
+            tdata["script_to_roman"]["double_cap"] = tuple(
+                    tdata["script_to_roman"]["double_cap"])
+
         tokens = {}
         for parent in parents:
             parent_tdata = load_table(parent)
@@ -129,6 +133,14 @@ def load_table(tname):
                 Token(k): v for k, v in parent_tdata.get(
                         "script_to_roman", {}).get("map", {})
             }
+            # Merge and/or remove double cap rules.
+            tdata["script_to_roman"]["double_cap"] = tuple((
+                set(parent_tdata["script_to_roman"].get("double_cap", {})) |
+                set(tdata["script_to_roman"].get("double_cap", {}))
+            ) - set(tdata["script_to_roman"].get("no_double_cap", {})))
+        if "no_double_cap" in tdata["script_to_roman"]:
+            del tdata["script_to_roman"]["no_double_cap"]
+
         tokens |= {
                 Token(k): v
                 for k, v in tdata["script_to_roman"].get("map", {}).items()}

+ 18 - 0
tests/data/cap_base1.yml

@@ -0,0 +1,18 @@
+# Test double capitalization.
+general:
+  name: Test ligature capitalization base 1
+
+script_to_roman:
+  double_cap:
+    # This capitalizes ligated z︠h︡
+    - "z\uFE20h\uFE21"
+  map:
+    # From Belarusian
+    "\u0433": "h"
+    "\u0436": "z\uFE20h\uFE21" # ж → z︠h︡
+    "\u0437": "z"
+    "\u043E": "o"
+    "\u0451": "i\uFE20o\uFE21" # ё → i︠o︡
+    "\u0456": "i"
+    "\u045E": "u\u0306"
+    "\u0491": "g"

+ 11 - 0
tests/data/cap_base2.yml

@@ -0,0 +1,11 @@
+# Test double capitalization.
+general:
+  name: Test ligature capitalization base 2
+  parents:
+    - cap_base1
+
+script_to_roman:
+  double_cap:
+    # This capitalizes ligated i︠o︡
+    - "i\uFE20o\uFE21"
+

+ 11 - 0
tests/data/cap_inherited.yml

@@ -0,0 +1,11 @@
+# Test double capitalization.
+general:
+  name: Test ligature capitalization working file
+  parents:
+    - cap_base2
+
+script_to_roman:
+  no_double_cap:
+    # Remove ligated i︠o︡ capitalization.
+    - "i\uFE20o\uFE21"
+

+ 27 - 0
tests/test01_cfg.py

@@ -116,3 +116,30 @@ class TestHooks(TestCase):
                         (scriptshifter.hooks.test.rotate, {"n": -3})
                     ]
                 })
+
+
+class TestDoubleCaps(TestCase):
+    """ Test double capitalization configuration. """
+    def setUp(self):
+        environ["TXL_CONFIG_TABLE_DIR"] = TEST_DATA_DIR
+        self.tables = reload_tables()
+
+    def test_dcaps_base1(self):
+        cap_base1 = self.tables.load_table("cap_base1")
+        assert "z︠h︡" in cap_base1["script_to_roman"]["double_cap"]
+
+    def test_dcaps_base2(self):
+        cap_base2 = self.tables.load_table("cap_base2")
+        dcap = cap_base2["script_to_roman"]["double_cap"]
+
+        assert len(dcap) == 2
+        assert "z︠h︡" in dcap
+        assert "i︠o︡" in dcap
+
+    def test_dcaps_inherited(self):
+        cap_inherited = self.tables.load_table("cap_inherited")
+        dcap = cap_inherited["script_to_roman"]["double_cap"]
+
+        assert len(dcap) == 1
+        assert "z︠h︡" in dcap
+        assert "i︠o︡" not in dcap

+ 20 - 0
tests/test03_capitalization.py

@@ -0,0 +1,20 @@
+from os import environ
+from unittest import TestCase
+
+from tests import TEST_DATA_DIR, reload_tables
+
+
+class TestCapitalization(TestCase):
+    """
+    Test capitalization.
+    """
+
+    def setUp(self):
+        environ["TXL_CONFIG_TABLE_DIR"] = TEST_DATA_DIR
+        reload_tables()
+
+    def test_cap(self):
+        pass
+
+    def test_cap_ligatures(self):
+        pass

+ 0 - 0
tests/test03_rest_api.py → tests/test04_rest_api.py