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

LS: Allow parametrizing completion tests behaviour #6563

Merged
merged 1 commit into from
Nov 14, 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
36 changes: 32 additions & 4 deletions crates/cairo-lang-language-server/tests/e2e/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ cairo_lang_test_utils::test_file_test!(
/// expected quick fixes from the snapshot file.
fn test_completions_text_edits(
inputs: &OrderedHashMap<String, String>,
_args: &OrderedHashMap<String, String>,
args: &OrderedHashMap<String, String>,
) -> TestRunnerResult {
let check_detail: bool =
args.get("detail").map(|value| value.parse().unwrap()).unwrap_or_default();
let check_edit: bool = args.get("edit").map(|value| value.parse().unwrap()).unwrap_or_default();
let check_insert: bool =
args.get("insert").map(|value| value.parse().unwrap()).unwrap_or_default();

let (cairo, cursors) = cursors(&inputs["cairo_code"]);

let mut ls = sandbox! {
Expand All @@ -52,20 +58,42 @@ fn test_completions_text_edits(
partial_result_params: Default::default(),
context: None,
};

let caret_completions =
ls.send_request::<lsp_request!("textDocument/completion")>(completion_params);

if let Some(completions) = caret_completions {
let completion_items = match completions {
lsp_types::CompletionResponse::Array(items) => items,
lsp_types::CompletionResponse::List(list) => list.items,
};

for completion in completion_items {
if let Some(text_edit) = completion.additional_text_edits {
report.push_str("--------------------------\n");
report.push_str(format!("Completion: {}\n", completion.label).as_str());
report.push_str("--------------------------\n");
let completion_label = completion.label;

if completion_label.is_empty() {
// A special case to avoid having trailing spaces in tests.
report.push_str("Completion:\n");
} else {
report.push_str(format!("Completion: {}\n", completion_label).as_str());
}

if check_detail {
if let Some(detail) = completion.detail {
report.push_str(format!("Detail: {detail}\n").as_str());
}
}

if check_insert {
if let Some(text) = completion.insert_text {
report.push_str(format!("Insert text: {text}\n").as_str());
}
}

if check_edit {
let text_edit = completion.additional_text_edits.unwrap_or_default();

for edit in text_edit {
report.push_str(format!("Text edit: {}", edit.new_text).as_str());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! > Test adding simple trait.

//! > test_runner_name
test_completions_text_edits
test_completions_text_edits(edit: true, insert: true)

//! > cairo_project.toml
[crate_roots]
Expand Down Expand Up @@ -135,7 +135,7 @@ Text edit: use super::ATrait1;
//! > Test adding non directly visible traits.

//! > test_runner_name
test_completions_text_edits
test_completions_text_edits(edit: true, insert: true)

//! > cairo_project.toml
[crate_roots]
Expand Down