diff options
author | Norbert Preining <norbert@preining.info> | 2022-12-30 03:01:26 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2022-12-30 03:01:26 +0000 |
commit | 844019377157163b461e0fd4a66592e61963a530 (patch) | |
tree | 32f61991c6a5acc3a3359ffc2cdefdd2aa004268 /support/texlab/src/tests/text_document/rename.rs | |
parent | 55c69feeef908f49007708be194b7bb1c607f302 (diff) |
CTAN sync 202212300301
Diffstat (limited to 'support/texlab/src/tests/text_document/rename.rs')
-rw-r--r-- | support/texlab/src/tests/text_document/rename.rs | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/support/texlab/src/tests/text_document/rename.rs b/support/texlab/src/tests/text_document/rename.rs new file mode 100644 index 0000000000..2bbdfb1513 --- /dev/null +++ b/support/texlab/src/tests/text_document/rename.rs @@ -0,0 +1,110 @@ +use std::collections::HashMap; + +use lsp_types::{request::Rename, ClientCapabilities, RenameParams, TextEdit, Url, WorkspaceEdit}; + +use crate::tests::{client::Client, fixture}; + +fn check(fixture: &str, new_name: &str) { + let mut client = Client::spawn(); + client.initialize(ClientCapabilities::default(), None); + + let fixture = fixture::parse(fixture); + for file in fixture.files { + client.open(file.name, file.lang, file.text); + } + + let mut expected_changes: HashMap<Url, Vec<TextEdit>> = HashMap::new(); + for ranges in fixture.ranges.values() { + expected_changes + .entry(client.uri(ranges[&1].name)) + .or_default() + .push(TextEdit::new(ranges[&1].range, new_name.to_string())); + } + + let actual_edit = client + .request::<Rename>(RenameParams { + text_document_position: fixture.cursor.unwrap().into_params(&client), + new_name: new_name.to_string(), + work_done_progress_params: Default::default(), + }) + .unwrap() + .unwrap_or_default(); + + client.shutdown(); + + assert_eq!(actual_edit, WorkspaceEdit::new(expected_changes)); +} + +#[test] +fn command() { + check( + r#" +%TEX foo.tex +%SRC \baz +%CUR ^ +%1.1 ^^^ +%SRC \include{bar.tex} + +%TEX bar.tex +%SRC \baz +%2.1 ^^^ +"#, + "qux", + ) +} + +#[test] +fn entry() { + check( + r#" +%BIB main.bib +%SRC @article{foo, bar = baz} +%CUR ^ +%1.1 ^^^ + +%TEX main.tex +%SRC \addbibresource{main.bib} +%SRC \cite{foo} +%2.1 ^^^ +"#, + "qux", + ) +} + +#[test] +fn citation() { + check( + r#" +%BIB main.bib +%SRC @article{foo, bar = baz} +%1.1 ^^^ + +%TEX main.tex +%SRC \addbibresource{main.bib} +%SRC \cite{foo} +%CUR ^ +%2.1 ^^^ +"#, + "qux", + ) +} + +#[test] +fn label() { + check( + r#" +%TEX foo.tex +%SRC \label{foo}\include{bar} +%CUR ^ +%1.1 ^^^ + +%TEX bar.tex +%SRC \ref{foo} +%2.1 ^^^ + +%TEX baz.tex +%SRC \ref{foo} +"#, + "bar", + ) +} |