diff options
Diffstat (limited to 'support/texlab/src/tests/text_document/document_highlight.rs')
-rw-r--r-- | support/texlab/src/tests/text_document/document_highlight.rs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/support/texlab/src/tests/text_document/document_highlight.rs b/support/texlab/src/tests/text_document/document_highlight.rs new file mode 100644 index 0000000000..01945ce342 --- /dev/null +++ b/support/texlab/src/tests/text_document/document_highlight.rs @@ -0,0 +1,60 @@ +use assert_unordered::assert_eq_unordered; +use lsp_types::{ + request::DocumentHighlightRequest, ClientCapabilities, DocumentHighlight, + DocumentHighlightKind, DocumentHighlightParams, +}; + +use crate::tests::{client::Client, fixture}; + +fn check(fixture: &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_highlights = Vec::new(); + for ranges in fixture.ranges.values() { + let (i, file_range) = ranges.iter().next().unwrap(); + let kind = match i { + 1 => DocumentHighlightKind::TEXT, + 2 => DocumentHighlightKind::READ, + 3 => DocumentHighlightKind::WRITE, + _ => unreachable!(), + }; + + expected_highlights.push(DocumentHighlight { + range: file_range.range, + kind: Some(kind), + }); + } + + let actual_highlights = client + .request::<DocumentHighlightRequest>(DocumentHighlightParams { + text_document_position_params: fixture.cursor.unwrap().into_params(&client), + partial_result_params: Default::default(), + work_done_progress_params: Default::default(), + }) + .unwrap() + .unwrap_or_default(); + + client.shutdown(); + assert_eq_unordered!(actual_highlights, expected_highlights); +} + +#[test] +fn test_label() { + check( + r#" +%TEX main.tex +%SRC \label{foo} +%CUR ^ +%1.3 ^^^ +%SRC \ref{foo} +%2.2 ^^^ +%SRC \label{bar} +"#, + ) +} |