From 23ece5e4c83585338066fa95f3bd5d8fd1ddfeb1 Mon Sep 17 00:00:00 2001 From: David Halter Date: Sat, 31 Aug 2013 11:47:10 +0430 Subject: [PATCH] Script needs valid ranges, otherwise ValueError should be raised (test) --- test/test_api.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/test_api.py b/test/test_api.py index 594bf5b3..4ee7db3c 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -3,6 +3,7 @@ Test all things related to the ``jedi.api`` module. """ from jedi import common, api +from pytest import raises def test_preload_modules(): @@ -28,3 +29,25 @@ def test_preload_modules(): def test_empty_script(): assert api.Script('') + +def test_line_number_errors(): + """ + Script should raise a ValueError if line/column numbers are not in a + valid range. + """ + s = 'hello' + # lines + with raises(ValueError): + api.Script(s, 2, 0) + with raises(ValueError): + api.Script(s, 0, 0) + + # columns + with raises(ValueError): + api.Script(s, 1, len(s) + 1) + with raises(ValueError): + api.Script(s, 1, -1) + + # ok + api.Script(s, 1, 0) + api.Script(s, 1, len(s) + 1)