File: unicode_data_test.py

package info (click to toggle)
nototools 0.2.17-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 10,940 kB
  • sloc: python: 26,065; xml: 653; sh: 222; javascript: 217; ansic: 127; makefile: 84
file content (154 lines) | stat: -rwxr-xr-x 6,809 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env python
#
# Copyright 2014 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for unicode_data.py."""

__author__ = "roozbeh@google.com (Roozbeh Pournader)"

import unittest

from nototools import unicode_data


class UnicodeDataTest(unittest.TestCase):
    """Tests for unicode_data module."""

    def test_name(self):
        """Tests the name() method."""
        self.assertEqual("WARANG CITI OM", unicode_data.name(0x118FF))

    def test_category(self):
        """Tests the category() method."""
        self.assertEqual("Co", unicode_data.category(0xF0001))
        self.assertEqual("Cn", unicode_data.category(0xE01F0))

    def test_canonical_decomposition(self):
        """Tests the canonical_decomposition() method."""
        self.assertEqual("", unicode_data.canonical_decomposition(0x0627))
        self.assertEqual("\u064A\u0654", unicode_data.canonical_decomposition(0x0626))
        self.assertEqual("\U000226D4", unicode_data.canonical_decomposition(0x2F8A4))

    def test_script(self):
        """Tests the script() method."""
        self.assertEqual("Latn", unicode_data.script(0xA794))
        self.assertEqual("Zzzz", unicode_data.script(0xE006))

    def test_block(self):
        """Tests the block() method."""
        self.assertEqual("Emoticons", unicode_data.block(0x1F600))

    def test_default_ignorable(self):
        """Tests the is_default_ignorable() method."""
        self.assertTrue(unicode_data.is_default_ignorable(0x061C))
        self.assertFalse(unicode_data.is_default_ignorable(0x0020))

    def test_defined(self):
        """Tests the is_defined() method."""
        self.assertTrue(unicode_data.is_defined(0x20BD))
        self.assertFalse(unicode_data.is_defined(0xFDD0))
        self.assertFalse(unicode_data.is_defined(0x088F))
        # CJK ranges
        self.assertTrue(unicode_data.is_defined(0x3400))
        self.assertTrue(unicode_data.is_defined(0x4DB5))
        self.assertTrue(unicode_data.is_defined(0x4DB6))

    def test_defined_characters(self):
        """Tests the defined_characters() method."""
        self.assertIn(0x20BD, unicode_data.defined_characters())
        self.assertNotIn(0xFDD0, unicode_data.defined_characters())
        # Version-restricted
        self.assertNotIn(0x20BD, unicode_data.defined_characters(6.3))
        self.assertIn(0x20BD, unicode_data.defined_characters(7.0))
        # Script restricted
        self.assertIn(0x1CD1, unicode_data.defined_characters(scr="Deva"))
        self.assertNotIn(
            0x1CD1, unicode_data.defined_characters(version=5.1, scr="Deva")
        )
        self.assertIn(0x0964, unicode_data.defined_characters(scr="Beng"))
        self.assertIn(0xA92E, unicode_data.defined_characters(scr="Latn"))
        self.assertNotIn(0x0363, unicode_data.defined_characters(scr="Arab"))

    def test_private_use(self):
        """Tests the is_private_use method."""
        self.assertTrue(unicode_data.is_private_use(0xE000))
        self.assertTrue(unicode_data.is_private_use(0xF8FF))
        self.assertFalse(unicode_data.is_private_use(0x9000))
        self.assertTrue(unicode_data.is_private_use(0xF0000))
        self.assertTrue(unicode_data.is_private_use(0x10FFFD))
        self.assertFalse(unicode_data.is_private_use(0x10FFFE))

    def test_mirrored(self):
        """Tests the mirrored method."""
        self.assertNotIsInstance(unicode_data.mirrored(0x0000), bool)
        self.assertEqual(unicode_data.mirrored(0x0028), 1)
        self.assertEqual(unicode_data.mirrored(0x2140), 1)
        self.assertEqual(unicode_data.mirrored(0x0029), 1)
        self.assertEqual(unicode_data.mirrored(0x1D7C3), 1)
        self.assertEqual(unicode_data.mirrored(0x0020), 0)
        self.assertEqual(unicode_data.mirrored(0x27CB), 1)
        self.assertEqual(unicode_data.mirrored(0x27CD), 1)

    def test_age(self):
        """Tests the age method."""
        self.assertEqual(unicode_data.age(0xE000), "1.1")
        self.assertEqual(unicode_data.age(0xE0021), "3.1")
        self.assertEqual(unicode_data.age(0x20BD), "7.0")
        self.assertEqual(unicode_data.age(0x2B820), "8.0")
        self.assertEqual(unicode_data.age(0x104B0), "9.0")

    def test_bidi_mirroring_glyph(self):
        """Tests the bidi_mirroring_glyph() method."""
        self.assertEqual(unicode_data.bidi_mirroring_glyph(0x0028), 0x0029)
        self.assertEqual(unicode_data.bidi_mirroring_glyph(0x0029), 0x0028)
        self.assertEqual(unicode_data.bidi_mirroring_glyph(0x27CB), 0x27CD)
        self.assertEqual(unicode_data.bidi_mirroring_glyph(0x27CD), 0x27CB)
        self.assertIsNone(unicode_data.bidi_mirroring_glyph(0x2140))

    def test_script_code(self):
        """Tests the script_code method."""
        self.assertEqual(unicode_data.script_code("NKo"), "Nkoo")
        self.assertEqual(unicode_data.script_code("N'Ko"), "Nkoo")
        self.assertEqual(unicode_data.script_code("NewTaiLue"), "Talu")
        self.assertEqual(unicode_data.script_code("Klingon"), "Piqd")

    def test_human_readable_script_name(self):
        """Tests the human_readable_script_name method."""
        self.assertEqual(unicode_data.human_readable_script_name("Grek"), "Greek")
        self.assertEqual(unicode_data.human_readable_script_name("Talu"), "New Tai Lue")
        self.assertEqual(unicode_data.human_readable_script_name("Nkoo"), "N'Ko")
        self.assertEqual(unicode_data.human_readable_script_name("Zsye"), "Emoji")
        self.assertEqual(unicode_data.human_readable_script_name("Zsym"), "Symbols")
        self.assertEqual(unicode_data.human_readable_script_name("Zzzz"), "Unknown")

    def test_all_scripts(self):
        """Tests the all_scripts() method."""
        self.assertIn("Latn", unicode_data.all_scripts())
        self.assertNotIn("Japn", unicode_data.all_scripts())

    def test_parse_code_ranges(self):
        """Tests the _parse_code_ranges method."""
        source = (
            "0000..001F    ; Common # Cc  [32] <control-0000>..<control-001F>\n"
            "0020          ; Common # Zs       SPACE\n"
        )
        self.assertEqual(
            [(0, 31, "Common"), (32, 32, "Common")],
            unicode_data._parse_code_ranges(source),
        )


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