def test_markdown(): pattern = ('^Markdown+ ' '(InlineKeyboard|ReplyKeyboard|ReplyKeyboardRemove)? ' 'Reply?$' '|^Markdown InlineKeyboard? Reply? Update$') ce = ClassExp(pattern) assert repr(ce._compiled_expression) == \ "re.compile('^(?:Markdown,)+((?:InlineKeyboard,)|(?:ReplyKeyboard,)|" \ "(?:ReplyKeyboardRemove,))?(?:Reply,)?$" \ "|^(?:Markdown,)(?:InlineKeyboard,)?(?:Reply,)?(?:Update,)$')" assert ce.match([ lyr.Markdown(''), tgr.InlineKeyboard([]), tgr.Reply(), tgr.Update(), ])
def test_compile(): ce = ClassExp(r'(RawText|Text)+ QuickRepliesList?') expect = "re.compile('((:?RawText,)|(:?Text,))+(:?QuickRepliesList,)?')" assert repr(ce._compiled_expression) == expect
def test_match(): ce = ClassExp(r'(int|bool)+ float') assert ce.match([42, 42, 42, True, 42, 42.0]) assert not ce.match([42, True, 42, True])
def test_make_string(): ce = ClassExp(r'') expect = 'int,bool,int,bool,' assert ce._make_string([42, True, 42, False]) == expect
def match_exp(self, expression: Text): e = ClassExp(expression) return e.match(self._layers)