Skip to content

Commit

Permalink
test: text document update tests (#1279)
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrinberg committed May 17, 2024
1 parent b47bd73 commit 93f214d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lsp/test/text_document_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,24 @@ let%expect_test "absolute_position" =
[%expect {| position: 7/13 |}];
test (100, 0);
[%expect {| position: 13/13 |}]

let%expect_test "replace second line first line is \\n" =
let range = tuple_range (1, 2) (1, 2) in
let doc = make_document (Uri.of_path "foo.ml") ~text:"\nfoo\nbar\nbaz\n" in
let edit = TextEdit.create ~newText:"change" ~range in
let new_doc = Text_document.apply_text_document_edits doc [ edit ] in
new_doc |> Text_document.text |> String.escaped |> print_endline;
[%expect {|
\nfochange\nfoo\nbar\nbaz\n |}]

let%expect_test "get position after change" =
let range = tuple_range (1, 2) (1, 2) in
let doc = make_document (Uri.of_path "foo.ml") ~text:"\nfoo\nbar\nbaz\n" in
let edit = TextDocumentContentChangeEvent.create ~text:"change" ~range () in
let new_doc = Text_document.apply_content_changes doc [ edit ] in
let pos = Text_document.absolute_position new_doc range.start in
new_doc |> Text_document.text |> String.escaped |> print_endline;
printf "pos: %d\n" pos;
[%expect {|
\nfochangeo\nbar\nbaz\n
pos: 19 |}]

0 comments on commit 93f214d

Please sign in to comment.