summaryrefslogtreecommitdiff
path: root/support/texlab/tests/lsp/text_document/document_highlight.rs
blob: 5cfb8fbee83552a7438c61153c86e5abb303b565 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use assert_unordered::assert_eq_unordered;
use lsp_types::{
    request::DocumentHighlightRequest, ClientCapabilities, DocumentHighlight,
    DocumentHighlightKind, DocumentHighlightParams,
};

use crate::fixture::TestBed;

fn check(fixture: &str, highlight_kinds: &[DocumentHighlightKind]) {
    let test_bed = TestBed::new(fixture).unwrap();
    test_bed.initialize(ClientCapabilities::default()).unwrap();

    let expected: Vec<_> = test_bed
        .locations()
        .iter()
        .zip(highlight_kinds)
        .map(|(location, kind)| DocumentHighlight {
            range: location.range,
            kind: Some(*kind),
        })
        .collect();

    let text_document_position_params = test_bed.cursor().unwrap();
    let actual = test_bed
        .client()
        .send_request::<DocumentHighlightRequest>(DocumentHighlightParams {
            text_document_position_params,
            partial_result_params: Default::default(),
            work_done_progress_params: Default::default(),
        })
        .unwrap()
        .unwrap_or_default();

    assert_eq_unordered!(actual, expected);
}

#[test]
fn test_label() {
    check(
        r#"
%! main.tex
\label{foo}
        |
       ^^^
\ref{foo}
     ^^^
\label{bar}
"#,
        &[DocumentHighlightKind::WRITE, DocumentHighlightKind::READ],
    )
}