def test_internal_ucp_width(self):
        '''Test that ucp_width returns proper width for characters'''
        for codepoint in xrange(0, 0xFFFFF + 1):
            if codepoint < 32 or (codepoint < 0xa0 and codepoint >= 0x7f):
                # With strict on, we should raise an error
                tools.assert_raises(ControlCharError, display._ucp_width, codepoint, 'strict')

                if codepoint in (0x08, 0x1b, 0x7f, 0x94):
                    # Backspace, delete, clear delete remove one char
                    tools.eq_(display._ucp_width(codepoint), -1)
                else:
                    # Everything else returns 0
                    tools.eq_(display._ucp_width(codepoint), 0)
            elif display._interval_bisearch(codepoint, display._COMBINING):
                # Combining character
                tools.eq_(display._ucp_width(codepoint), 0)
            elif (codepoint >= 0x1100 and
                    (codepoint <= 0x115f or                     # Hangul Jamo init. consonants
                        codepoint == 0x2329 or codepoint == 0x232a or
                        (codepoint >= 0x2e80 and codepoint <= 0xa4cf and
                            codepoint != 0x303f) or                   # CJK ... Yi
                        (codepoint >= 0xac00 and codepoint <= 0xd7a3) or # Hangul Syllables
                        (codepoint >= 0xf900 and codepoint <= 0xfaff) or # CJK Compatibility Ideographs
                        (codepoint >= 0xfe10 and codepoint <= 0xfe19) or # Vertical forms
                        (codepoint >= 0xfe30 and codepoint <= 0xfe6f) or # CJK Compatibility Forms
                        (codepoint >= 0xff00 and codepoint <= 0xff60) or # Fullwidth Forms
                        (codepoint >= 0xffe0 and codepoint <= 0xffe6) or
                        (codepoint >= 0x20000 and codepoint <= 0x2fffd) or
                        (codepoint >= 0x30000 and codepoint <= 0x3fffd))):
                tools.eq_(display._ucp_width(codepoint), 2)
            else:
                tools.eq_(display._ucp_width(codepoint), 1)
    def test_internal_generate_combining_table(self):
        '''Test that the combining table we generate is equal to or a subseet of what's in the current table

        If we assert it can mean one of two things:

        1. The code is broken
        2. The table we have is out of date.
        '''
        old_table = display._COMBINING
        new_table = display._generate_combining_table()
        for interval in new_table:
            if interval[0] == interval[1]:
                tools.assert_true(display._interval_bisearch(interval[0], old_table))
            else:
                for codepoint in xrange(interval[0], interval[1] + 1):
                    tools.assert_true(display._interval_bisearch(interval[0], old_table))
Example #3
0
    def test_internal_ucp_width(self):
        '''Test that ucp_width returns proper width for characters'''
        for codepoint in range(0, 0xFFFFF + 1):
            if codepoint < 32 or (codepoint < 0xa0 and codepoint >= 0x7f):
                # With strict on, we should raise an error
                tools.assert_raises(ControlCharError, display._ucp_width, codepoint, 'strict')

                if codepoint in (0x08, 0x1b, 0x7f, 0x94):
                    # Backspace, delete, clear delete remove one char
                    tools.eq_(display._ucp_width(codepoint), -1)
                else:
                    # Everything else returns 0
                    tools.eq_(display._ucp_width(codepoint), 0)
            elif display._interval_bisearch(codepoint, display._COMBINING):
                # Combining character
                tools.eq_(display._ucp_width(codepoint), 0)
            elif (codepoint >= 0x1100 and
                    (codepoint <= 0x115f or                     # Hangul Jamo init. consonants
                        codepoint == 0x2329 or codepoint == 0x232a or
                        (codepoint >= 0x2e80 and codepoint <= 0xa4cf and
                            codepoint != 0x303f) or                   # CJK ... Yi
                        (codepoint >= 0xac00 and codepoint <= 0xd7a3) or # Hangul Syllables
                        (codepoint >= 0xf900 and codepoint <= 0xfaff) or # CJK Compatibility Ideographs
                        (codepoint >= 0xfe10 and codepoint <= 0xfe19) or # Vertical forms
                        (codepoint >= 0xfe30 and codepoint <= 0xfe6f) or # CJK Compatibility Forms
                        (codepoint >= 0xff00 and codepoint <= 0xff60) or # Fullwidth Forms
                        (codepoint >= 0xffe0 and codepoint <= 0xffe6) or
                        (codepoint >= 0x20000 and codepoint <= 0x2fffd) or
                        (codepoint >= 0x30000 and codepoint <= 0x3fffd))):
                tools.eq_(display._ucp_width(codepoint), 2)
            else:
                tools.eq_(display._ucp_width(codepoint), 1)
Example #4
0
    def test_internal_generate_combining_table(self):
        '''Test that the combining table we generate is equal to or a subset of what's in the current table

        If we assert it can mean one of two things:

        1. The code is broken
        2. The table we have is out of date.
        '''
        old_table = display._COMBINING
        new_table = display._generate_combining_table()
        for interval in new_table:
            if interval[0] == interval[1]:
                tools.assert_true(display._interval_bisearch(interval[0], old_table))
            else:
                for codepoint in range(interval[0], interval[1] + 1):
                    tools.assert_true(display._interval_bisearch(interval[0], old_table))
 def test_internal_interval_bisearch(self):
     '''Test that we can find things in an interval table'''
     table = ((0, 3), (5, 7), (9, 10))
     tools.assert_true(display._interval_bisearch(0, table))
     tools.assert_true(display._interval_bisearch(1, table))
     tools.assert_true(display._interval_bisearch(2, table))
     tools.assert_true(display._interval_bisearch(3, table))
     tools.assert_true(display._interval_bisearch(5, table))
     tools.assert_true(display._interval_bisearch(6, table))
     tools.assert_true(display._interval_bisearch(7, table))
     tools.assert_true(display._interval_bisearch(9, table))
     tools.assert_true(display._interval_bisearch(10, table))
     tools.assert_false(display._interval_bisearch(-1, table))
     tools.assert_false(display._interval_bisearch(4, table))
     tools.assert_false(display._interval_bisearch(8, table))
     tools.assert_false(display._interval_bisearch(11, table))
 def test_internal_interval_bisearch(self):
     '''Test that we can find things in an interval table'''
     table = ((0, 3), (5, 7), (9, 10))
     tools.assert_true(display._interval_bisearch(0, table))
     tools.assert_true(display._interval_bisearch(1, table))
     tools.assert_true(display._interval_bisearch(2, table))
     tools.assert_true(display._interval_bisearch(3, table))
     tools.assert_true(display._interval_bisearch(5, table))
     tools.assert_true(display._interval_bisearch(6, table))
     tools.assert_true(display._interval_bisearch(7, table))
     tools.assert_true(display._interval_bisearch(9, table))
     tools.assert_true(display._interval_bisearch(10, table))
     tools.assert_false(display._interval_bisearch(-1, table))
     tools.assert_false(display._interval_bisearch(4, table))
     tools.assert_false(display._interval_bisearch(8, table))
     tools.assert_false(display._interval_bisearch(11, table))