Ejemplo n.º 1
0
    def testExceptionToken(self):
        def func():
            pass

        pattern = lexers.Pattern(name='foo',
                                 regex=re.compile('\S'),
                                 function=func)
        tokens.ExceptionToken(pattern=pattern, traceback='foo')
Ejemplo n.º 2
0
    def testErrorToken(self):
        def func():
            pass

        pattern = lexers.Pattern(name='foo',
                                 regex=re.compile('\S'),
                                 function=func)
        tokens.ErrorToken(pattern=pattern)
Ejemplo n.º 3
0
    def testPattern(self):
        comp = components.TokenComponent()

        regex = re.compile(r'foo')
        pattern = lexers.Pattern('foo', regex, comp)
        pick = do_pickle(pattern)

        self.assertEqual(pattern.name, pick.name)
        self.assertEqual(pattern.regex, pick.regex)
        self.assertIs(pattern.function, pick.function)
Ejemplo n.º 4
0
    def testInfo(self):
        regex = re.compile(r'(?P<key>foo)')
        match = regex.search('foo bar')

        pattern = lexers.Pattern(name='name', regex=regex, function=Proxy())
        info = lexers.LexerInformation(match=match, pattern=pattern, line=42)
        self.assertEqual(info.line, 42)
        self.assertEqual(info.pattern, 'name')
        self.assertEqual(list(info.keys()), [0, 1, 'key'])
        self.assertIn('key', info)
        self.assertIn('line:42', str(info))