File: test_util.py

package info (click to toggle)
gajim 2.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,320 kB
  • sloc: python: 79,114; sh: 387; xml: 67; makefile: 6
file content (66 lines) | stat: -rw-r--r-- 2,379 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# This file is part of Gajim.
#
# SPDX-License-Identifier: GPL-3.0-or-later

import unittest

from gajim.gtk.util.misc import get_first_grapheme


class Test(unittest.TestCase):
    def disabled_test_get_first_grapheme(self):
        # This test fails on some machines

        self.assertEqual(get_first_grapheme(""), "", "<empty string>")
        self.assertEqual(get_first_grapheme("a"), "a", "a")
        self.assertEqual(get_first_grapheme("ab"), "a", "ab -> a")

        ueber = "u\u0308ber"
        self.assertEqual(get_first_grapheme(ueber), "u\u0308", ueber + " -> ü")

        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
        # implementation doesn't seem locale-specific.


if __name__ == "__main__":
    unittest.main()