summaryrefslogtreecommitdiff
path: root/support/texlab/tests/integration/hover.rs
blob: 319ebcc5e942df268748ffc85de99e715b295b0a (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use indoc::indoc;
use texlab::{
    protocol::{HoverContents, MarkupContent, MarkupKind},
    test::{TestBedBuilder, PULL_CAPABILITIES},
};

#[tokio::test]
async fn label_theorem_child_file() {
    let mut test_bed = TestBedBuilder::new()
        .file(
            "main.tex",
            indoc!(
                r#"
                    \documentclass{article}
                    \newtheorem{lemma}{Lemma}
                    \include{child}
                    \ref{thm:foo}
                "#
            ),
        )
        .file(
            "child.tex",
            indoc!(
                r#"
                    \begin{lemma}\label{thm:foo}
                        1 + 1 = 2
                    \end{lemma}
                "#
            ),
        )
        .build()
        .await;
    test_bed.spawn();
    test_bed.initialize(PULL_CAPABILITIES.clone()).await;
    test_bed.open("main.tex").await;

    let actual_hover = test_bed.hover("main.tex", 3, 8).await.unwrap().unwrap();
    assert_eq!(
        actual_hover.contents,
        HoverContents::Markup(MarkupContent {
            kind: MarkupKind::PlainText,
            value: "Lemma".into()
        })
    );
}

#[tokio::test]
async fn label_theorem_child_file_number() {
    let mut test_bed = TestBedBuilder::new()
        .file(
            "main.tex",
            indoc!(
                r#"
                \documentclass{article}
                \newtheorem{lemma}{Lemma}
                \include{child}
                \ref{thm:foo}
            "#
            ),
        )
        .file(
            "child.tex",
            indoc!(
                r#"
                \begin{lemma}[Foo]\label{thm:foo}
                    1 + 1 = 2
                \end{lemma}
            "#
            ),
        )
        .file("child.aux", r#"\newlabel{thm:foo}{{1}{1}{Foo}{lemma.1}{}}"#)
        .build()
        .await;
    test_bed.spawn();
    test_bed.initialize(PULL_CAPABILITIES.clone()).await;
    test_bed.open("main.tex").await;

    let actual_hover = test_bed.hover("main.tex", 3, 8).await.unwrap().unwrap();
    assert_eq!(
        actual_hover.contents,
        HoverContents::Markup(MarkupContent {
            kind: MarkupKind::PlainText,
            value: "Lemma 1 (Foo)".into()
        })
    );
}