Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl committed Jan 12, 2024
1 parent 954d911 commit 7a396b2
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions tests/test_edit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from LSP.plugin.core.edit import parse_workspace_edit, parse_text_edit
from LSP.plugin.edit import _sort_by_application_order as sort_by_application_order
from LSP.plugin.core.url import filename_to_uri
from LSP.plugin.core.views import entire_content
from LSP.plugin.edit import temporary_setting
from setup import TextDocumentTestCase
from test_protocol import LSP_RANGE
import sublime
import unittest
Expand Down Expand Up @@ -233,6 +235,69 @@ def test_sorts_in_application_order2(self):
self.assertEqual(sorted_edits[1][1], (27, 32))


class ApplyDocumentEditTestCase(TextDocumentTestCase):

def test_applies_text_edit(self) -> None:
self.insert_characters('abc')
edit = parse_text_edit({
'newText': 'x$0y',
'range': {
'start': {
'line': 0,
'character': 1,
},
'end': {
'line': 0,
'character': 2,
}
}
})
self.view.run_command("lsp_apply_document_edit", {"changes": [edit]})
self.assertEquals(entire_content(self.view), 'ax$0yc')

def test_applies_text_edit_with_placeholder(self) -> None:
self.insert_characters('abc')
edit = parse_text_edit({
'newText': 'x$0y',
'range': {
'start': {
'line': 0,
'character': 1,
},
'end': {
'line': 0,
'character': 2,
}
}
})
self.view.run_command('lsp_apply_document_edit', {'changes': [edit], 'process_placeholders': True})
self.assertEquals(entire_content(self.view), 'axyc')
self.assertEqual(len(self.view.sel()), 1)
self.assertEqual(self.view.sel()[0], sublime.Region(2, 2))

def test_applies_multiple_text_edits_with_placeholders(self) -> None:
self.insert_characters('ab')
newline_edit = parse_text_edit({
'newText': '\n$0',
'range': {
'start': {
'line': 0,
'character': 1,
},
'end': {
'line': 0,
'character': 1,
}
}
})
edits = [newline_edit, newline_edit]
self.view.run_command('lsp_apply_document_edit', {'changes': edits, 'process_placeholders': True})
self.assertEquals(entire_content(self.view), 'a\n\nb')
self.assertEqual(len(self.view.sel()), 2)
self.assertEqual(self.view.sel()[0], sublime.Region(2, 2))
self.assertEqual(self.view.sel()[1], sublime.Region(3, 3))


class TemporarySetting(unittest.TestCase):

def test_basics(self) -> None:
Expand Down

0 comments on commit 7a396b2

Please sign in to comment.