Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

goto_definition tests #15

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/handlers/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ mod test {
&[]
)]
#[tokio::test(flavor = "current_thread")]
async fn test_server_completions(
async fn server_completions(
#[case] source: &str,
#[case] position: Position,
#[case] symbols: &[SymbolInfo],
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/did_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ mod test {
]
)]
#[tokio::test(flavor = "current_thread")]
async fn test_server_did_change(
async fn server_did_change(
#[case] original: &str,
#[case] expected: &str,
#[case] edits: &[TestEdit],
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/did_change_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mod test {
};

#[tokio::test(flavor = "current_thread")]
async fn test_server_did_change_configuration() {
async fn server_did_change_configuration() {
// Arrange
let mut service = initialize_server(&[]).await.0;

Expand Down
2 changes: 1 addition & 1 deletion src/handlers/did_open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ mod test {
};

#[tokio::test(flavor = "current_thread")]
async fn test_server_did_open_document() {
async fn server_did_open_document() {
// Arrange
let mut service = initialize_server(&[]).await.0;
let source = r#""[" @cap"#;
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ mod test {
};

#[tokio::test(flavor = "current_thread")]
async fn test_server_formatting() {
async fn server_formatting() {
// Arrange
let mut service = initialize_server(&[(
TEST_URI.clone(),
Expand Down
97 changes: 97 additions & 0 deletions src/handlers/goto_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,100 @@ pub async fn goto_definition(

Ok(Some(GotoDefinitionResponse::Array(defs)))
}

#[cfg(test)]
mod test {
use pretty_assertions::assert_eq;
use rstest::rstest;
use tower::{Service, ServiceExt};
use tower_lsp::lsp_types::{
request::GotoDefinition, GotoDefinitionParams, GotoDefinitionResponse, Location,
PartialResultParams, Position, Range, TextDocumentIdentifier, TextDocumentPositionParams,
WorkDoneProgressParams,
};

use crate::test_helpers::helpers::{
initialize_server, lsp_request_to_jsonrpc_request, lsp_response_to_jsonrpc_response,
COMPLEX_FILE, SIMPLE_FILE, TEST_URI,
};

type Coordinate = ((u32, u32), (u32, u32));

#[rstest]
#[case(
&SIMPLE_FILE,
Position { line: 0, character: 4 },
&[]
)]
#[case(
&SIMPLE_FILE,
Position { line: 0, character: 20 },
&[((0, 14), (0, 23))]
)]
#[case(
&COMPLEX_FILE,
Position { line: 12, character: 14 },
&[((8, 24), (8, 42)), ((9, 22), (9, 40))]
)]
#[tokio::test(flavor = "current_thread")]
async fn goto_definition(
#[case] input: &str,
#[case] position: Position,
#[case] locations: &[Coordinate],
) {
// Arrange
let mut service = initialize_server(&[(TEST_URI.clone(), input, Vec::new(), Vec::new())])
.await
.0;

// Act
let refs = service
.ready()
.await
.unwrap()
.call(lsp_request_to_jsonrpc_request::<GotoDefinition>(
GotoDefinitionParams {
partial_result_params: PartialResultParams {
partial_result_token: None,
},
work_done_progress_params: WorkDoneProgressParams::default(),
text_document_position_params: TextDocumentPositionParams {
text_document: TextDocumentIdentifier {
uri: TEST_URI.clone(),
},
position,
},
},
))
.await
.unwrap();

// Assert
let actual = if locations.is_empty() {
None
} else {
Some(GotoDefinitionResponse::Array(
locations
.iter()
.map(|r| Location {
uri: TEST_URI.clone(),
range: Range {
start: Position {
line: r.0 .0,
character: r.0 .1,
},
end: Position {
line: r.1 .0,
character: r.1 .1,
},
},
})
.collect(),
))
};
assert_eq!(
refs,
Some(lsp_response_to_jsonrpc_response::<GotoDefinition>(actual))
);
}
}
2 changes: 1 addition & 1 deletion src/handlers/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ mod test {
],
)])]
#[tokio::test(flavor = "current_thread")]
async fn test_server_initialize(#[case] documents: &[(Url, &str, Vec<SymbolInfo>, Vec<&str>)]) {
async fn server_initialize(#[case] documents: &[(Url, &str, Vec<SymbolInfo>, Vec<&str>)]) {
// Act
let (service, response) = initialize_server(documents).await;

Expand Down
2 changes: 1 addition & 1 deletion src/handlers/references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function: (identifier) @function)",
&[((5, 25), (5, 44)), ((11, 15), (11, 34)), ((17, 16), (17, 35))]
)]
#[tokio::test(flavor = "current_thread")]
async fn test_capture_references(
async fn capture_references(
#[case] input: &str,
#[case] position: Position,
#[case] ranges: &[Coordinate],
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ mod test {
"invariant"
)]
#[tokio::test(flavor = "current_thread")]
async fn test_server_rename(
async fn server_rename(
#[case] original: &str,
#[case] cursor_position: Position,
#[case] edits: &[TestEdit],
Expand Down
Loading