summaryrefslogtreecommitdiff
path: root/support/texlab/src/tests/text_document/document_highlight.rs
blob: 01945ce34239075cfcd3d21eba9945cf68325582 (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
52
53
54
55
56
57
58
59
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}
"#,
    )
}