summaryrefslogtreecommitdiff
path: root/support/texlab/crates/links/src/tests.rs
blob: 6837bc96b7c4b161d690d5c6136d0f3bbe43987b (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
use expect_test::{expect, Expect};

fn check(input: &str, expect: Expect) {
    let fixture = test_utils::fixture::Fixture::parse(input);
    let (params, _) = fixture.make_params().unwrap();
    let links = crate::find_links(&params);

    let actual_ranges = links.iter().map(|link| link.range).collect::<Vec<_>>();

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

    assert_eq!(actual_ranges, expected_ranges);

    let actual_targets = links
        .iter()
        .map(|link| link.document.uri.as_str())
        .collect::<Vec<_>>();

    expect.assert_debug_eq(&actual_targets);
}

#[test]
fn test_document_include() {
    check(
        r#"
%! foo.tex
\input{bar.tex}
       ^^^^^^^

%! bar.tex"#,
        expect![[r#"
            [
                "file:///texlab/bar.tex",
            ]
        "#]],
    );
}

#[test]
fn test_document_import() {
    check(
        r#"
%! foo.tex
\import{.}{bar/baz}
           ^^^^^^^

%! bar/baz.tex"#,
        expect![[r#"
            [
                "file:///texlab/bar/baz.tex",
            ]
        "#]],
    );
}