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