Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_word_at_position(doc):
"""
Return the position under the cursor (or last in line if past the end)
"""
assert doc.word_at_position(Position(0, 8)) == 'document'
assert doc.word_at_position(Position(0, 1000)) == 'document'
assert doc.word_at_position(Position(1, 5)) == 'for'
assert doc.word_at_position(Position(2, 0)) == 'testing'
assert doc.word_at_position(Position(3, 10)) == 'unicode'
assert doc.word_at_position(Position(4, 0)) == ''
def test_word_at_position(doc):
"""
Return the position under the cursor (or last in line if past the end)
"""
assert doc.word_at_position(Position(0, 8)) == 'document'
assert doc.word_at_position(Position(0, 1000)) == 'document'
assert doc.word_at_position(Position(1, 5)) == 'for'
assert doc.word_at_position(Position(2, 0)) == 'testing'
assert doc.word_at_position(Position(3, 10)) == 'unicode'
assert doc.word_at_position(Position(4, 0)) == ''
def test_offset_at_position(doc):
assert doc.offset_at_position(Position(0, 8)) == 8
assert doc.offset_at_position(Position(1, 5)) == 14
assert doc.offset_at_position(Position(2, 0)) == 13
assert doc.offset_at_position(Position(2, 4)) == 17
assert doc.offset_at_position(Position(3, 6)) == 27
assert doc.offset_at_position(Position(3, 7)) == 27
assert doc.offset_at_position(Position(3, 8)) == 28
assert doc.offset_at_position(Position(4, 0)) == 39
assert doc.offset_at_position(Position(5, 0)) == 39
def test_offset_at_position(doc):
assert doc.offset_at_position(Position(0, 8)) == 8
assert doc.offset_at_position(Position(1, 5)) == 14
assert doc.offset_at_position(Position(2, 0)) == 13
assert doc.offset_at_position(Position(2, 4)) == 17
assert doc.offset_at_position(Position(3, 6)) == 27
assert doc.offset_at_position(Position(3, 7)) == 27
assert doc.offset_at_position(Position(3, 8)) == 28
assert doc.offset_at_position(Position(4, 0)) == 39
assert doc.offset_at_position(Position(5, 0)) == 39
def test_position_to_utf16():
assert position_to_utf16(['x="😋"'], Position(0, 3)) == Position(0, 3)
assert position_to_utf16(['x="😋"'], Position(0, 4)) == Position(0, 5)
position = Position(0, 4)
position_to_utf16(['x="😋"'], position)
assert position == Position(0, 4)
def _validate_json(source):
"""Validates json file."""
diagnostics = []
try:
json.loads(source)
except JSONDecodeError as err:
msg = err.msg
col = err.colno
line = err.lineno
d = Diagnostic(
Range(
Position(line - 1, col - 1),
Position(line - 1, col)
),
msg,
source=type(json_server).__name__
)
diagnostics.append(d)
return diagnostics
def _validate_json(source):
"""Validates json file."""
diagnostics = []
try:
json.loads(source)
except JSONDecodeError as err:
msg = err.msg
col = err.colno
line = err.lineno
d = Diagnostic(
Range(
Position(line - 1, col - 1),
Position(line - 1, col)
),
msg,
source=type(json_server).__name__
)
diagnostics.append(d)
return diagnostics
def __eq__(self, other):
return (
isinstance(other, Position)
and self.line == other.line
and self.character == other.character)