Example #1
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))
Example #2
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]))
Example #3
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)
Example #4
0
 def test_lgr_ranges(self):
     self.lgr.add_range(0x0061, 0x0065)
     self.lgr.add_range(0x0066, 0x0068)
     __, result = compute_stats(self.lgr, {})
     stats = self.STATS.copy()
     stats['codepoint_number'] = 8
     stats['range_number'] = 2
     stats['largest_range'] = RangeChar(0x0061, 0x0061, 0x0065)
     stats['largest_range_len'] = 5
     self.assertDictEqual(result, {'description': 'Generate stats',
                                   'stats': stats})
Example #5
0
 def test_lgr_wrong_range_char(self):
     self.lgr.add_range(0x0060, 0x0063, force=True)
     r = RangeChar(0x0060, 0x0060, 0x0063)
     unidb = IDNADatabase(self.DEFAULT_UNICODE_VERSION)
     self.lgr.unicode_database = unidb
     _, result = rebuild_lgr(self.lgr, {'unidb': unidb})
     errors = result.get('repertoire', {}).get(r, {'errors': []})['errors']
     self.assertEqual(len(errors), 1)
     self.assertIsInstance(errors[0], CharInvalidIdnaProperty)
     self.assertDictEqual(result, {'description': 'Rebuilding LGR with Unicode version {}'.format(
                                                                                 self.DEFAULT_UNICODE_VERSION),
                                   'repertoire': {r: {'errors': errors}}})
Example #6
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)
Example #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)
Example #8
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__())