Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormjk <mjk@disroot.org>2022-10-19 03:23:33 +0300
committerPhilipp Hörist <philipp@hoerist.com>2022-10-28 17:16:13 +0300
commite1ad8fa75d8a0739281877d9b7774e293da3e4b0 (patch)
treef94cb1f9844e15a3e8092a9a89c2e1af20efe359 /test
parentca574844a9595125cc9373eb6d00259c01c0da8d (diff)
fix: Avatar placeholders: Correctly use the first grapheme as the "letter"
Diffstat (limited to 'test')
-rw-r--r--test/no_gui/__init__.py1
-rw-r--r--test/no_gui/test_gtk_util.py71
2 files changed, 72 insertions, 0 deletions
diff --git a/test/no_gui/__init__.py b/test/no_gui/__init__.py
index 1513837b3..1a26b1822 100644
--- a/test/no_gui/__init__.py
+++ b/test/no_gui/__init__.py
@@ -5,6 +5,7 @@ def require_versions():
'GLib': '2.0',
'Gio': '2.0',
'Gtk': '3.0',
+ 'GtkSource': '4',
'GObject': '2.0',
'Pango': '1.0'})
diff --git a/test/no_gui/test_gtk_util.py b/test/no_gui/test_gtk_util.py
new file mode 100644
index 000000000..3c57d3265
--- /dev/null
+++ b/test/no_gui/test_gtk_util.py
@@ -0,0 +1,71 @@
+import unittest
+
+from gajim import gui
+gui.init('gtk')
+
+from gajim.gtk.util import get_first_grapheme
+
+
+class Test(unittest.TestCase):
+ def test_get_first_grapheme(self):
+ self.assertEqual(
+ get_first_grapheme(''), '', '<empty string>')
+ self.assertEqual(
+ get_first_grapheme('a'), 'a', 'a')
+ self.assertEqual(
+ get_first_grapheme('ab'), 'a', 'ab -> a')
+
+ über = 'u\u0308ber'
+ self.assertEqual(
+ get_first_grapheme(über), 'u\u0308', über + ' -> ü')
+
+ woman = '\U0001F469'
+ zwj = '\u200D'
+ vs16 = '\uFE0F'
+ fitz4 = '\U0001F3FD'
+
+ farmeress = f'{woman}{zwj}\U0001F33E{vs16}'
+ self.assertEqual(
+ get_first_grapheme(farmeress), farmeress, '👩‍🌾️')
+
+ longass = f'{woman}{fitz4}{zwj}\u2764{vs16}{zwj}\U0001F468{fitz4}'
+ self.assertEqual(
+ get_first_grapheme(longass), longass, '👩🏽‍❤️‍👨🏽')
+
+ # The following are from
+ # https://www.unicode.org/reports/tr29/#Table_Sample_Grapheme_Clusters
+
+ hangul_gag = '\u1100\u1161\u11A8'
+ self.assertEqual(
+ get_first_grapheme(hangul_gag), hangul_gag, '각')
+
+ tamil_ni = '\u0BA8\u0BBF'
+ self.assertEqual(
+ get_first_grapheme(tamil_ni), tamil_ni, 'நி')
+
+ # Fails 🤷 (returns the first char)
+ #thai_kam = '\u0E01\u0E33'
+ #self.assertEqual(
+ # get_first_grapheme(thai_kam), thai_kam, 'กำ')
+
+ devanagari_ssi = '\u0937\u093F'
+ self.assertEqual(
+ get_first_grapheme(devanagari_ssi), devanagari_ssi, 'षि')
+
+ # Only in some locales (e.g., Slovak):
+ #self.assertEqual(
+ # get_first_grapheme('ch'), 'ch', 'ch -> ch')
+ # Actually, Gtk.TextIter.forward_cursor_position() doesn't seem to use
+ # tailored algorithms anyway, so even with LANG=sk_SK.UTF-8 this
+ # returns 'c', not 'ch'.
+
+ # In most locales (say, any western one):
+ devanagari_kshi = '\u0915\u094D' + devanagari_ssi
+ self.assertEqual(
+ get_first_grapheme(devanagari_kshi), '\u0915\u094D', 'क्षि -> क् ')
+ # This probably won't fail on *any* locale, ever, again because the
+ # implementaion doesn't seem locale-specific.
+
+
+if __name__ == '__main__':
+ unittest.main()