forked from ocaml/ocaml-lsp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
text_document_tests.ml
61 lines (53 loc) · 1.68 KB
/
text_document_tests.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
open Lsp
open Lsp.Types
let tuple_range start end_ =
Some
{ Range.start =
(let line, character = start in
{ Position.line; character })
; end_ =
(let line, character = end_ in
{ Position.line; character })
}
let test text range ~change =
let td =
let uri = DocumentUri.of_path "" in
let version = 1 in
let languageId = "fake language" in
let textDocument = { TextDocumentItem.uri; version; languageId; text } in
Text_document.make { DidOpenTextDocumentParams.textDocument }
in
let td =
Text_document.apply_content_change
td
(TextDocumentContentChangeEvent.create ?range ~text:change ())
in
print_endline (String.escaped (Text_document.text td))
let%expect_test "first line insert" =
let range = tuple_range (0, 1) (0, 3) in
test "foo bar baz" range ~change:"XXXX";
[%expect {| fXXXX bar baz |}]
let%expect_test "no range" =
let range = None in
test "foo bar baz" range ~change:"XXXX";
[%expect {| XXXX |}]
let%expect_test "replace second line" =
let range = tuple_range (1, 0) (2, 0) in
test "foo\n\bar\nbaz\n" range ~change:"XXXX\n";
[%expect {|
foo\nXXXX\nbaz\n |}]
let%expect_test "edit in second line" =
let range = tuple_range (1, 1) (1, 2) in
test "foo\n\bar\nbaz\n" range ~change:"-XXX-";
[%expect {|
foo\n\b-XXX-r\nbaz\n |}]
let%expect_test "insert at the end" =
let range = tuple_range (3, 1) (4, 0) in
test "foo\n\bar\nbaz\n" range ~change:"XXX";
[%expect {|
foo\n\bar\nbaz\nXXX |}]
let%expect_test "insert at the beginning" =
let range = tuple_range (0, 0) (0, 0) in
test "foo\n\bar\nbaz\n" range ~change:"XXX\n";
[%expect {|
XXX\nfoo\n\bar\nbaz\n |}]