Esempio n. 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(),
    ])
Esempio n. 2
0
def test_compile():
    ce = ClassExp(r'(RawText|Text)+ QuickRepliesList?')
    expect = "re.compile('((:?RawText,)|(:?Text,))+(:?QuickRepliesList,)?')"
    assert repr(ce._compiled_expression) == expect
Esempio n. 3
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])
Esempio n. 4
0
def test_make_string():
    ce = ClassExp(r'')
    expect = 'int,bool,int,bool,'
    assert ce._make_string([42, True, 42, False]) == expect
Esempio n. 5
0
 def match_exp(self, expression: Text):
     e = ClassExp(expression)
     return e.match(self._layers)