diff --git a/IPython/utils/tests/test_tokenutil.py b/IPython/utils/tests/test_tokenutil.py index 024c5c7..986adf8 100644 --- a/IPython/utils/tests/test_tokenutil.py +++ b/IPython/utils/tests/test_tokenutil.py @@ -4,7 +4,7 @@ import nose.tools as nt -from IPython.utils.tokenutil import token_at_cursor +from IPython.utils.tokenutil import token_at_cursor, line_at_cursor def expect_token(expected, cell, cursor_pos): token = token_at_cursor(cell, cursor_pos) @@ -68,3 +68,9 @@ def test_attrs(): expected = 'obj.attr.subattr' for i in range(idx, len(cell)): expect_token(expected, cell, i) + +def test_line_at_cursor(): + cell = "" + (line, offset) = line_at_cursor(cell, cursor_pos=11) + assert line == "", ("Expected '', got %r" % line) + assert offset == 0, ("Expected '', got %r" % line) diff --git a/IPython/utils/tokenutil.py b/IPython/utils/tokenutil.py index d9d333f..48cc82c 100644 --- a/IPython/utils/tokenutil.py +++ b/IPython/utils/tokenutil.py @@ -49,6 +49,8 @@ def line_at_cursor(cell, cursor_pos=0): if next_offset >= cursor_pos: break offset = next_offset + else: + line = "" return (line, offset) def token_at_cursor(cell, cursor_pos=0):