mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
Improve literal tests.
This commit is contained in:
@@ -19,17 +19,6 @@ str..
|
|||||||
#? []
|
#? []
|
||||||
a(0):.
|
a(0):.
|
||||||
|
|
||||||
# -----------------
|
|
||||||
# _ separators (for older versions than 3.6, a = 1_2_3 will just be 1, the rest
|
|
||||||
# gets ignored.)
|
|
||||||
# -----------------
|
|
||||||
#? int()
|
|
||||||
1_2_3
|
|
||||||
#? int()
|
|
||||||
123_345_345
|
|
||||||
#? int()
|
|
||||||
0x3_4
|
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# if/else/elif
|
# if/else/elif
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from jedi._compatibility import py_version
|
|||||||
|
|
||||||
def _eval_literal(value):
|
def _eval_literal(value):
|
||||||
def_, = jedi.Script(value).goto_definitions()
|
def_, = jedi.Script(value).goto_definitions()
|
||||||
return def_._name._context
|
return def_._name._context.obj
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif('sys.version_info[:2] < (3, 6)')
|
@pytest.mark.skipif('sys.version_info[:2] < (3, 6)')
|
||||||
@@ -15,23 +15,27 @@ def test_f_strings():
|
|||||||
f literals are not really supported in Jedi. They just get ignored and an
|
f literals are not really supported in Jedi. They just get ignored and an
|
||||||
empty string is returned.
|
empty string is returned.
|
||||||
"""
|
"""
|
||||||
context = _eval_literal('f"asdf"')
|
assert _eval_literal('f"asdf"') == ''
|
||||||
assert context.obj == ''
|
assert _eval_literal('f"{asdf}"') == ''
|
||||||
context = _eval_literal('f"{asdf}"')
|
assert _eval_literal('F"{asdf}"') == ''
|
||||||
assert context.obj == ''
|
assert _eval_literal('rF"{asdf}"') == ''
|
||||||
context = _eval_literal('F"{asdf}"')
|
|
||||||
assert context.obj == ''
|
|
||||||
context = _eval_literal('rF"{asdf}"')
|
|
||||||
assert context.obj == ''
|
|
||||||
|
|
||||||
|
|
||||||
def test_rb_strings():
|
def test_rb_strings():
|
||||||
context = _eval_literal('br"asdf"')
|
assert _eval_literal('br"asdf"') == b'asdf'
|
||||||
assert context.obj == b'asdf'
|
obj = _eval_literal('rb"asdf"')
|
||||||
context = _eval_literal('rb"asdf"')
|
|
||||||
if py_version < 33:
|
if py_version < 33:
|
||||||
# Before Python 3.3 there was a more strict definition in which order
|
# Before Python 3.3 there was a more strict definition in which order
|
||||||
# you could define literals.
|
# you could define literals.
|
||||||
assert context.obj == ''
|
assert obj == ''
|
||||||
else:
|
else:
|
||||||
assert context.obj == b'asdf'
|
assert obj == b'asdf'
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif('sys.version_info[:2] < (3, 6)')
|
||||||
|
def test_thousand_separators():
|
||||||
|
assert _eval_literal('1_2_3') == 123
|
||||||
|
assert _eval_literal('123_456_789') == 123456789
|
||||||
|
assert _eval_literal('0x3_4') == 52
|
||||||
|
assert _eval_literal('0b1_0') == 2
|
||||||
|
assert _eval_literal('0o1_0') == 8
|
||||||
|
|||||||
Reference in New Issue
Block a user