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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
use expect_test::{expect, Expect};
use rowan::{TextLen, TextRange};
fn check(input: &str, expect: Expect) {
let fixture = test_utils::fixture::Fixture::parse(input);
let (feature, _) = fixture.make_params().unwrap();
let range = TextRange::new(0.into(), feature.document.text.text_len());
let params = crate::InlayHintParams { range, feature };
let actual = crate::find_all(params).unwrap_or_default();
let expected_offsets = fixture.locations().map(|location| location.range.start());
for (hint, offset) in actual.iter().zip(expected_offsets) {
assert_eq!(hint.offset, offset);
}
let data = actual.into_iter().map(|hint| hint.data).collect::<Vec<_>>();
expect.assert_debug_eq(&data);
}
#[test]
fn test_label_definition() {
check(
r#"
%! main.tex
\documentclass{article}
\usepackage{caption}
\begin{document}
\section{Foo}\label{sec:foo}
!
\section{Bar}\label{sec:bar}
!
\subsection{Baz}\label{sec:baz}
!
\begin{figure}
Test
\label{fig:qux}
!
\caption{Qux}
\end{figure}
\end{document}
%! main.aux
\relax
\providecommand*\caption@xref[2]{\@setref\relax\@undefined{#1}}
\newlabel{fig:qux}{{\caption@xref {fig:qux}{ on input line 15}}{1}}
\@writefile{lof}{\contentsline {figure}{\numberline {1}{\ignorespaces Qux\relax }}{1}{}\protected@file@percent }
\@writefile{toc}{\contentsline {section}{\numberline {1}Foo}{1}{}\protected@file@percent }
\newlabel{sec:foo}{{1}{1}}
\@writefile{toc}{\contentsline {section}{\numberline {2}Bar}{1}{}\protected@file@percent }
\newlabel{sec:bar}{{2}{1}}
\@writefile{toc}{\contentsline {subsection}{\numberline {2.1}Baz}{1}{}\protected@file@percent }
\newlabel{sec:baz}{{2.1}{1}}
\gdef \@abspage@last{1}"#,
expect![[r#"
[
LabelDefinition(
RenderedLabel {
range: 62..90,
number: Some(
"1",
),
object: Section {
prefix: "Section",
text: "Foo",
},
},
),
LabelDefinition(
RenderedLabel {
range: 91..226,
number: Some(
"2",
),
object: Section {
prefix: "Section",
text: "Bar",
},
},
),
LabelDefinition(
RenderedLabel {
range: 120..226,
number: Some(
"2.1",
),
object: Section {
prefix: "Subsection",
text: "Baz",
},
},
),
LabelDefinition(
RenderedLabel {
range: 152..226,
number: Some(
"fig:qux",
),
object: Float {
kind: Figure,
caption: "Qux",
},
},
),
]
"#]],
);
}
|