Skip to content

Commit 40d7633

Browse files
Merge pull request #296 from Tcode-Motion/refactor-lsp-quickfix-test-9454651291763357923
🧹 Refactor quick fix lookup in LSP tests
2 parents f12d818 + a95c200 commit 40d7633

1 file changed

Lines changed: 16 additions & 19 deletions

File tree

‎tools/lsp/tests/lsp_tests.rs‎

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -177,23 +177,20 @@ async fn test_lsp_code_action_make_to_const() {
177177
let actions = res.unwrap();
178178

179179
// Find the quick fix action
180-
let mut found = false;
181-
for action in actions {
182-
if let CodeActionOrCommand::CodeAction(a) = action {
183-
if a.title.contains("immutable 'const'") {
184-
found = true;
185-
186-
let edits = a.edit.unwrap().changes.unwrap();
187-
let edits_for_uri = edits.get(&doc_uri).unwrap();
188-
189-
assert_eq!(edits_for_uri.len(), 1);
190-
assert_eq!(edits_for_uri[0].new_text, "const ");
191-
assert_eq!(edits_for_uri[0].range.start.line, 1);
192-
assert_eq!(edits_for_uri[0].range.start.character, 4);
193-
assert_eq!(edits_for_uri[0].range.end.character, 8);
194-
}
195-
}
196-
}
197-
198-
assert!(found, "Did not find the 'Change to const' quick fix");
180+
let action = actions
181+
.into_iter()
182+
.find_map(|action| match action {
183+
CodeActionOrCommand::CodeAction(a) if a.title.contains("immutable 'const'") => Some(a),
184+
_ => None,
185+
})
186+
.expect("Did not find the 'Change to const' quick fix");
187+
188+
let edits = action.edit.unwrap().changes.unwrap();
189+
let edits_for_uri = edits.get(&doc_uri).unwrap();
190+
191+
assert_eq!(edits_for_uri.len(), 1);
192+
assert_eq!(edits_for_uri[0].new_text, "const ");
193+
assert_eq!(edits_for_uri[0].range.start.line, 1);
194+
assert_eq!(edits_for_uri[0].range.start.character, 4);
195+
assert_eq!(edits_for_uri[0].range.end.character, 8);
199196
}

0 commit comments

Comments
 (0)