summaryrefslogtreecommitdiff
path: root/support/texlab/crates/highlights/src/tests.rs
blob: ef63a3137b93ca6ab03a4e13fabfbbdc9771e947 (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
use crate::{HighlightKind, HighlightParams};

fn check(input: &str, expected_kinds: &[HighlightKind]) {
    let fixture = test_utils::fixture::Fixture::parse(input);

    let (feature, offset) = fixture.make_params().unwrap();

    let expected_ranges = fixture
        .locations()
        .map(|location| location.range)
        .collect::<Vec<_>>();

    let results = crate::find_all(&HighlightParams { feature, offset });

    let actual_ranges = results
        .iter()
        .map(|result| result.range)
        .collect::<Vec<_>>();
    assert_eq!(actual_ranges, expected_ranges);

    assert_eq!(
        results.iter().map(|result| result.kind).collect::<Vec<_>>(),
        expected_kinds
    );
}

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