test_completion_lexer.py
47 lines
| 1.4 KiB
| text/x-python
|
PythonLexer
epatters
|
r2605 | # Standard library imports | ||
import unittest | ||||
# System library imports | ||||
from pygments.lexers import CLexer, CppLexer, PythonLexer | ||||
# Local imports | ||||
Fernando Perez
|
r11024 | from IPython.qt.console.completion_lexer import CompletionLexer | ||
epatters
|
r2605 | |||
class TestCompletionLexer(unittest.TestCase): | ||||
def testPython(self): | ||||
""" Does the CompletionLexer work for Python? | ||||
""" | ||||
lexer = CompletionLexer(PythonLexer()) | ||||
epatters
|
r2640 | # Test simplest case. | ||
Bradley M. Froehle
|
r7874 | self.assertEqual(lexer.get_context("foo.bar.baz"), | ||
epatters
|
r2605 | [ "foo", "bar", "baz" ]) | ||
epatters
|
r2640 | |||
# Test trailing period. | ||||
Bradley M. Froehle
|
r7874 | self.assertEqual(lexer.get_context("foo.bar."), [ "foo", "bar", "" ]) | ||
epatters
|
r2605 | |||
epatters
|
r2640 | # Test with prompt present. | ||
Bradley M. Froehle
|
r7874 | self.assertEqual(lexer.get_context(">>> foo.bar.baz"), | ||
epatters
|
r2605 | [ "foo", "bar", "baz" ]) | ||
epatters
|
r2640 | |||
# Test spacing in name. | ||||
Bradley M. Froehle
|
r7874 | self.assertEqual(lexer.get_context("foo.bar. baz"), [ "baz" ]) | ||
epatters
|
r2605 | |||
epatters
|
r2640 | # Test parenthesis. | ||
Bradley M. Froehle
|
r7874 | self.assertEqual(lexer.get_context("foo("), []) | ||
epatters
|
r2640 | |||
epatters
|
r2605 | def testC(self): | ||
""" Does the CompletionLexer work for C/C++? | ||||
""" | ||||
lexer = CompletionLexer(CLexer()) | ||||
Bradley M. Froehle
|
r7874 | self.assertEqual(lexer.get_context("foo.bar"), [ "foo", "bar" ]) | ||
self.assertEqual(lexer.get_context("foo->bar"), [ "foo", "bar" ]) | ||||
epatters
|
r2605 | |||
lexer = CompletionLexer(CppLexer()) | ||||
Bradley M. Froehle
|
r7874 | self.assertEqual(lexer.get_context("Foo::Bar"), [ "Foo", "Bar" ]) | ||
epatters
|
r2605 | |||
if __name__ == '__main__': | ||||
unittest.main() | ||||