Skip to content

Commit

Permalink
test(uri): add an OCaml e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
tatchi committed Jul 5, 2022
1 parent 1e966c0 commit 6b293e2
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions ocaml-lsp-server/test/e2e-new/uri.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
open Test.Import

let%expect_test "uri" =
let notif_received = Fiber.Ivar.create () in
let handler =
let on_notification _ (notification : Lsp.Server_notification.t) =
(match notification with
| PublishDiagnostics d ->
print_endline "client: received publish diagnostics notification";
Printf.printf "uri received from the server: %s\n" (d.uri |> DocumentUri.to_string)
| ShowMessage _
| LogMessage _
| TelemetryNotification _
| CancelRequest _
| WorkDoneProgress _
| UnknownNotification _ -> ());
let* () = Fiber.Ivar.fill notif_received () in
Fiber.return ()
in
Client.Handler.make ~on_notification ()
in
( Test.run ~handler @@ fun client ->
let run_client () =
let capabilities = ClientCapabilities.create () in
Client.start client (InitializeParams.create ~capabilities ())
in
let run =
let* (_ : InitializeResult.t) = Client.initialized client in
let uri = DocumentUri.of_path "src/néw/Mödel + Other Thîngß/test.ml" in
Printf.printf "uri sent to the server: %s\n" (DocumentUri.to_string uri);
let textDocument =
TextDocumentItem.create ~uri ~languageId:"ocaml" ~text:"" ~version:0
in
let params = DidOpenTextDocumentParams.create ~textDocument in
let* () = Client.notification client (TextDocumentDidOpen params) in
Fiber.Ivar.read notif_received
in
Fiber.fork_and_join_unit run_client (fun () -> run >>> Client.stop client)
);
[%expect
{|
uri sent to the server: file:///src/néw/Mödel + Other Thîngß/test.ml
client: received publish diagnostics notification
uri received from the server: file:///src/néw/Mödel + Other Thîngß/test.ml |}]

0 comments on commit 6b293e2

Please sign in to comment.