1# -*- coding: utf-8 -*- 2""" 3 Test suite for the unistring module 4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 6 :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. 7 :license: BSD, see LICENSE for details. 8""" 9 10import re 11import random 12 13from pygments import unistring as uni 14from pygments.util import unichr 15 16 17def test_cats_exist_and_compilable(): 18 for cat in uni.cats: 19 s = getattr(uni, cat) 20 if s == '': # Probably Cs on Jython 21 continue 22 print("%s %r" % (cat, s)) 23 re.compile('[%s]' % s) 24 25 26def _cats_that_match(c): 27 matching_cats = [] 28 for cat in uni.cats: 29 s = getattr(uni, cat) 30 if s == '': # Probably Cs on Jython 31 continue 32 if re.compile('[%s]' % s).match(c): 33 matching_cats.append(cat) 34 return matching_cats 35 36 37def test_spot_check_types(): 38 # Each char should match one, and precisely one, category 39 random.seed(0) 40 for i in range(1000): 41 o = random.randint(0, 65535) 42 c = unichr(o) 43 if o > 0xd800 and o <= 0xdfff and not uni.Cs: 44 continue # Bah, Jython. 45 print(hex(o)) 46 cats = _cats_that_match(c) 47 assert len(cats) == 1, "%d (%s): %s" % (o, c, cats) 48