1
"""Support functions for app-level _sre tests."""
3
from sre_constants import OPCODES, ATCODES, CHCODES
5
def encode_literal(string):
7
for character in string:
8
opcodes.extend([OPCODES["literal"], ord(character)])
11
def assert_match(opcodes, strings):
12
assert_something_about_match(lambda x: x, opcodes, strings)
14
def assert_no_match(opcodes, strings):
15
assert_something_about_match(lambda x: not x, opcodes, strings)
17
def assert_something_about_match(assert_modifier, opcodes, strings):
18
if isinstance(strings, str):
20
for string in strings:
21
assert assert_modifier(search(opcodes, string))
23
def search(opcodes, string):
24
pattern = _sre.compile("ignore", 0, opcodes, 0, {}, None)
25
return pattern.search(string)
28
locale.setlocale(locale.LC_ALL, (None, None))
30
def assert_lower_equal(tests, flags):
31
for arg, expected in tests:
32
assert ord(expected) == _sre.getlower(ord(arg), flags)