Пример #1
0
    def test_add_variant(self):
        c = Char(0x002A)
        c.add_variant([0x0030])

        self.assertEqual(len(c._variants), 1)
        self.assertIn((0x0030, ), c._variants)
        self.assertEqual(len(c._variants[(0x0030, )]), 1)
        self.assertEqual(c._variants[(0x0030, )][0].cp, (0x0030, ))

        self.assertRaises(VariantAlreadyExists, c.add_variant, [0x0030])

        c.add_variant([0x0030], when='w1')
        self.assertRaises(VariantAlreadyExists,
                          c.add_variant, [0x0030],
                          when='w1')

        c.add_variant([0x0030], not_when='w1')
        self.assertRaises(VariantAlreadyExists,
                          c.add_variant, [0x0030],
                          not_when='w1')

        c.add_variant([0x0030], when='w1', not_when='nw-1')
        self.assertRaises(VariantAlreadyExists,
                          c.add_variant, [0x0030],
                          when='w1',
                          not_when='nw-1')

        self.assertEqual(len(c._variants[(0x0030, )]), 4)
Пример #2
0
    def test_iter(self):
        self.cd.add_char([0x0010])
        self.cd.add_range(0x0001, 0x000A)
        self.cd.add_char([0x0000])
        self.cd.add_char([0x0011, 0x0012])
        self.cd.add_char([0x0013])

        expected_output = [
            Char(0x0000),
            RangeChar(0x0001, 0x0001, 0x000A),
            Char(0x0010),
            CharSequence([0x0011, 0x0012]),
            Char(0x0013),
        ]

        self.assertEqual(list(self.cd), expected_output)
Пример #3
0
    def test_is_prefix_of(self):
        c = Char(0x002A)
        s = CharBase.from_cp_or_sequence([0x002A, 0x002B])
        r = RangeChar(0x002A, 0x002A, 0x002B)

        self.assertTrue(c.is_prefix_of([0x002A]))
        self.assertTrue(r.is_prefix_of([0x002A]))
        self.assertTrue(c.is_prefix_of([0x002A, 0x002B]))
        self.assertTrue(r.is_prefix_of([0x002A, 0x002B]))
        self.assertTrue(s.is_prefix_of([0x002A, 0x002B]))
        self.assertTrue(s.is_prefix_of([0x002A, 0x002B, 0x002C]))

        self.assertFalse(c.is_prefix_of([0x002B]))
        self.assertFalse(r.is_prefix_of([0x002B]))
        self.assertFalse(s.is_prefix_of([0x002B, 0x002A]))
        self.assertFalse(s.is_prefix_of([0x002A]))
        self.assertFalse(s.is_prefix_of([0x002B]))
Пример #4
0
 def test_as_index(self):
     self.assertEqual(Char(0x002A).as_index(), 0x002A)
     self.assertEqual(CharSequence((0x002A, 0x002B)).as_index(), 0x002A)
     self.assertEqual(RangeChar(0x002A, 0x002A, 0x02C).as_index(), 0x002A)
     self.assertEqual(
         CharBase.from_cp_or_sequence(0x002A).as_index(), 0x002A)
     self.assertEqual(
         CharBase.from_cp_or_sequence([0x002A]).as_index(), 0x002A)
     self.assertEqual(
         CharBase.from_cp_or_sequence([0x002A, 0x002B]).as_index(), 0x002A)
Пример #5
0
    def test_add_codepoints(self):
        self.lgr.add_codepoints([c for c in range(0x0061, 0x007A + 1)] +
                                [0x0107] + [0x0137, 0x0138])

        expected_output = [
            RangeChar(0x061, 0x0061, 0x007A),
            Char(0x0107),
            RangeChar(0x0137, 0x0137, 0x0138)
        ]

        self.assertEqual(expected_output, list(self.lgr.repertoire))
Пример #6
0
    def test_get_variant(self):
        c = Char(0x002A)
        c.add_variant([0x0030], when='w1')
        c.add_variant([0x0031], when='w2')
        c.add_variant([0x0031], not_when='nw-1')

        variant = c.get_variant((0x031, ))
        expected_output = [
            Variant((0x0031, ), when='w2'),
            Variant((0x0031, ), not_when='nw-1')
        ]

        self.assertEqual(variant, expected_output)
Пример #7
0
 def test_len(self):
     self.assertEqual(len(Char(0x002A)), 1)
     self.assertEqual(len(CharBase.from_cp_or_sequence([0x002A, 0x002B])),
                      2)
     self.assertEqual(len(RangeChar(0x002A, 0x002A, 0x002B)), 1)
Пример #8
0
 def test_equal_cp(self):
     self.assertEqual(Char([0x002A]), Char([0x002A]))
     self.assertNotEqual(Char([0x002A]), Char([0x002B]))
     c1 = Char(0x002A)
     c2 = Char(0x002A)
     self.assertEqual(c1, c2)
Пример #9
0
    def test_get_variants(self):
        c = Char(0x002A)
        c.add_variant([0x0030])
        c.add_variant([0x0030], when='w1')
        c.add_variant([0x0030], not_when='w1')
        c.add_variant([0x0030], when='w1', not_when='nw-1')

        variants = c.get_variants()

        self.assertIsInstance(variants, types.GeneratorType)

        variant_list = list(variants)
        self.assertEqual(len(variant_list), 4)

        expected_output = [
            Variant((0x0030, )),
            Variant((0x0030, ), when='w1'),
            Variant((0x0030, ), not_when='w1'),
            Variant((0x0030, ), when='w1', not_when='nw-1')
        ]

        self.assertEqual(variant_list, expected_output)
Пример #10
0
    def test_del_variant(self):
        c = Char(0x002A)
        c.add_variant([0x0030])
        c.del_variant([0x0030])

        self.assertEqual(len(c._variants), 0)

        c.add_variant([0x0030])
        c.add_variant([0x0031])
        c.del_variant([0x0031])

        self.assertEqual(len(c._variants), 1)
        self.assertIn((0x0030, ), c._variants)
        self.assertEqual(len(c._variants[(0x0030, )]), 1)
        self.assertEqual(c._variants[(0x0030, )][0].cp, (0x0030, ))

        c.add_variant([0x0030], when='w1')
        c.del_variant([0x0030], when='w1')
        self.assertEqual(len(c._variants[(0x0030, )]), 1)
        self.assertEqual(c._variants[(0x0030, )][0].cp, (0x0030, ))
        self.assertIsNone(c._variants[(0x0030, )][0].when)
Пример #11
0
 def test_char_range(self):
     char = Char(0x002A)
     range_char = RangeChar(0x002A, 0x002A, 0x002B)
     self.assertEqual(char, range_char)
     self.assertEqual(char.__hash__(), range_char.__hash__())
Пример #12
0
 def test_hash_char(self):
     c1 = Char(0x002A)
     c2 = Char(0x002A)
     c3 = Char(0x002B)
     self.assertEqual(c1.__hash__(), c2.__hash__())
     self.assertNotEqual(c1.__hash__(), c3.__hash__())
Пример #13
0
    def test_all_repertoire(self):
        self.cd.add_char([0x0010])
        self.cd.add_range(0x0001, 0x0005)
        self.cd.add_char([0x0000])
        self.cd.add_char([0x0011, 0x0012])
        self.cd.add_char([0x0013])

        # Full output
        expected_output = {
            Char(0x0000),
            RangeChar(0x0001, 0x0001, 0x0005),
            RangeChar(0x0002, 0x0001, 0x0005),
            RangeChar(0x0003, 0x0001, 0x0005),
            RangeChar(0x0004, 0x0001, 0x0005),
            RangeChar(0x0005, 0x0001, 0x0005),
            Char(0x0010),
            CharSequence([0x0011, 0x0012]),
            Char(0x0013),
        }
        self.assertEqual(set(self.cd.all_repertoire()), expected_output)

        # Exclude ranges
        expected_output = {
            Char(0x0000),
            Char(0x0010),
            CharSequence([0x0011, 0x0012]),
            Char(0x0013),
        }
        self.assertEqual(set(self.cd.all_repertoire(include_ranges=False)),
                         expected_output)

        # Exclude sequences
        expected_output = {
            Char(0x0000),
            RangeChar(0x0001, 0x0001, 0x0005),
            RangeChar(0x0002, 0x0001, 0x0005),
            RangeChar(0x0003, 0x0001, 0x0005),
            RangeChar(0x0004, 0x0001, 0x0005),
            RangeChar(0x0005, 0x0001, 0x0005),
            Char(0x0010),
            Char(0x0013),
        }
        self.assertEqual(set(self.cd.all_repertoire(include_sequences=False)),
                         expected_output)

        # Exclude ranges and sequences
        expected_output = {
            Char(0x0000),
            Char(0x0010),
            Char(0x0013),
        }
        self.assertEqual(
            set(
                self.cd.all_repertoire(include_ranges=False,
                                       include_sequences=False)),
            expected_output)