Пример #1
0
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(),
    ])
Пример #2
0
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])
Пример #3
0
 def match_exp(self, expression: Text):
     e = ClassExp(expression)
     return e.match(self._layers)