diff --git a/plugin/pythonhelper.py b/ftplugin/python/pythonhelper.py similarity index 98% rename from plugin/pythonhelper.py rename to ftplugin/python/pythonhelper.py index d4f869a..8131ece 100644 --- a/plugin/pythonhelper.py +++ b/ftplugin/python/pythonhelper.py @@ -151,7 +151,11 @@ class PythonHelper(object): line_number = vim.current.window.cursor[0] - 1 while True: - line = vim.current.buffer[line_number] + try: + line = vim.current.buffer[line_number] + except IndexError: + return None + line_indent = len(RE_INDENT.match(line).group(1)) if line.strip(): break diff --git a/plugin/pythonhelper.vim b/ftplugin/python/pythonhelper.vim similarity index 100% rename from plugin/pythonhelper.vim rename to ftplugin/python/pythonhelper.vim diff --git a/plugin/test_py_example.py b/ftplugin/python/test_py_example.py similarity index 100% rename from plugin/test_py_example.py rename to ftplugin/python/test_py_example.py diff --git a/plugin/test_pythonhelper.py b/ftplugin/python/test_pythonhelper.py similarity index 89% rename from plugin/test_pythonhelper.py rename to ftplugin/python/test_pythonhelper.py index 9f24255..00fe85a 100755 --- a/plugin/test_pythonhelper.py +++ b/ftplugin/python/test_pythonhelper.py @@ -17,8 +17,7 @@ class Window(object): class Current(object): def __init__(self): - with open('test_py_example.py') as fobj: - self.buffer = fobj.read().split('\n') + self.buffer = [] self.window = Window() @@ -26,6 +25,9 @@ class MockVim(object): current = Current() command = Command() +with open('test_py_example.py') as fobj: + BUFFER = fobj.read().split('\n') + sys.modules['vim'] = vim = MockVim @@ -33,8 +35,22 @@ sys.modules['vim'] = vim = MockVim import pythonhelper +class TestTagsHelperWithEmptyBuffer(unittest.TestCase): + + def setUp(self): + vim.current.buffer = [] + + def test_get_tag(self): + vim.current.window.cursor = (1, 1) + tag = pythonhelper.PythonHelper._get_tag(1, 2) + self.assertIsNone(tag) + + class TestTagsHelper(unittest.TestCase): + def setUp(self): + vim.current.buffer = BUFFER + def test_import(self): vim.current.window.cursor = (1, 1) tag = pythonhelper.PythonHelper._get_tag(1, 2)