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
|
use std::collections::HashMap;
use lsp_types::{request::Rename, ClientCapabilities, RenameParams, TextEdit, Url, WorkspaceEdit};
use crate::tests::{client::Client, fixture};
fn check(fixture: &str, new_name: &str) {
let mut client = Client::spawn();
client.initialize(ClientCapabilities::default(), None);
let fixture = fixture::parse(fixture);
for file in fixture.files {
client.open(file.name, file.lang, file.text);
}
let mut expected_changes: HashMap<Url, Vec<TextEdit>> = HashMap::new();
for ranges in fixture.ranges.values() {
expected_changes
.entry(client.uri(ranges[&1].name))
.or_default()
.push(TextEdit::new(ranges[&1].range, new_name.to_string()));
}
let actual_edit = client
.request::<Rename>(RenameParams {
text_document_position: fixture.cursor.unwrap().into_params(&client),
new_name: new_name.to_string(),
work_done_progress_params: Default::default(),
})
.unwrap()
.unwrap_or_default();
client.shutdown();
assert_eq!(actual_edit, WorkspaceEdit::new(expected_changes));
}
#[test]
fn command() {
check(
r#"
%TEX foo.tex
%SRC \baz
%CUR ^
%1.1 ^^^
%SRC \include{bar.tex}
%TEX bar.tex
%SRC \baz
%2.1 ^^^
"#,
"qux",
)
}
#[test]
fn entry() {
check(
r#"
%BIB main.bib
%SRC @article{foo, bar = baz}
%CUR ^
%1.1 ^^^
%TEX main.tex
%SRC \addbibresource{main.bib}
%SRC \cite{foo}
%2.1 ^^^
"#,
"qux",
)
}
#[test]
fn citation() {
check(
r#"
%BIB main.bib
%SRC @article{foo, bar = baz}
%1.1 ^^^
%TEX main.tex
%SRC \addbibresource{main.bib}
%SRC \cite{foo}
%CUR ^
%2.1 ^^^
"#,
"qux",
)
}
#[test]
fn label() {
check(
r#"
%TEX foo.tex
%SRC \label{foo}\include{bar}
%CUR ^
%1.1 ^^^
%TEX bar.tex
%SRC \ref{foo}
%2.1 ^^^
%TEX baz.tex
%SRC \ref{foo}
"#,
"bar",
)
}
|