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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
use rowan::TextRange;
use rustc_hash::FxHashSet;
use crate::{DefinitionParams, DefinitionResult};
fn check(input: &str) {
let fixture = test_utils::fixture::Fixture::parse(input);
let (feature, offset) = fixture.make_params().unwrap();
let origin_document = feature.document;
let origin_selection_range = fixture
.locations()
.filter(|location| location.document == origin_document)
.find(|location| location.range.contains_inclusive(offset))
.map_or_else(TextRange::default, |location| location.range);
let mut expected = FxHashSet::default();
for document in &fixture.documents {
let mut ranges = document.ranges.iter();
while let Some(target_selection_range) = ranges.next().copied() {
if (&origin_document.uri, origin_selection_range)
!= (&document.uri, target_selection_range)
{
expected.insert(DefinitionResult {
origin_selection_range,
target: fixture.workspace.lookup(&document.uri).unwrap(),
target_range: *ranges.next().unwrap(),
target_selection_range,
});
}
}
}
let actual = crate::goto_definition(&DefinitionParams { feature, offset });
assert_eq!(actual, expected);
}
#[test]
fn test_old_command_definition() {
check(
r#"
%! main.tex
\def\foo{foo}
^^^^
^^^^^^^^
\foo
|
^^^^"#,
)
}
#[test]
fn test_new_command_definition() {
check(
r#"
%! main.tex
\DeclareMathOperator{\foo}{foo}
^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
\foo
|
^^^^"#,
)
}
#[test]
fn test_document() {
check(
r#"
%! foo.tex
\addbibresource{baz.bib}
|
^^^^^^^
%! bar.bib
@article{foo, bar = {baz}}
%! baz.bib
@article{foo, bar = {baz}}
!
!"#,
)
}
#[test]
fn test_entry() {
check(
r#"
%! foo.tex
\addbibresource{baz.bib}
\cite{foo}
|
^^^
%! bar.bib
@article{foo, bar = {baz}}
%! baz.bib
@article{foo, bar = {baz}}
^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^"#,
)
}
#[test]
fn test_string_simple() {
check(
r#"
%! main.bib
@string{foo = {bar}}
^^^
^^^^^^^^^^^^^^^^^^^^
@article{bar, author = foo}
|
^^^"#,
)
}
#[test]
fn test_string_join() {
check(
r#"
%! main.bib
@string{foo = {bar}}
^^^
^^^^^^^^^^^^^^^^^^^^
@article{bar, author = foo # "bar"}
|
^^^"#,
)
}
#[test]
fn test_string_field() {
check(
r#"
%! main.bib
@string{foo = {bar}}
@article{bar, author = foo # "bar"}
|"#,
)
}
|