Skip to content

Commit

Permalink
added tests for handling malformed contents on hovering and formatting
Browse files Browse the repository at this point in the history
without panicing
  • Loading branch information
sabify committed Jul 7, 2024
1 parent 5b374e5 commit 2eb8486
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions internal/lsp/lsp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ func TestDocumentFormat(t *testing.T) {
End: lsp.Position{Line: 10000000, Character: 100000000},
}, resp[0].Range)
require.Equal(t, "definition user {}", resp[0].NewText)

// test formatting malformed content without panicing
tester.setFileContents("file:///test", "dfinition user{}")
err, _ := sendAndExpectError(tester, "textDocument/formatting",
lsp.DocumentFormattingParams{
TextDocument: lsp.TextDocumentIdentifier{URI: "file:///test"},
})
require.Error(t, err)
}

func TestDocumentOpenedClosed(t *testing.T) {
Expand Down Expand Up @@ -204,4 +212,27 @@ definition resource {

require.Equal(t, "definition user {}", resp.Contents.Value)
require.Equal(t, "spicedb", resp.Contents.Language)

// test hovering malformed content without panicing
sendAndReceive[any](tester, "textDocument/didOpen", lsp.DidOpenTextDocumentParams{
TextDocument: lsp.TextDocumentItem{
URI: lsp.DocumentURI("file:///test"),
LanguageID: "test",
Version: 1,
Text: `definition user {}
dfinition resource {
relation viewer: user
}
`,
},
})

err, _ := sendAndExpectError(tester, "textDocument/hover", lsp.TextDocumentPositionParams{
TextDocument: lsp.TextDocumentIdentifier{
URI: lsp.DocumentURI("file:///test"),
},
Position: lsp.Position{Line: 3, Character: 18},
})
require.Error(t, err)
}

0 comments on commit 2eb8486

Please sign in to comment.