Skip to content

Commit f486640

Browse files
committed
Extract tests module to file in ide_db crate
1 parent 5a1306a commit f486640

File tree

8 files changed

+1419
-1441
lines changed

8 files changed

+1419
-1441
lines changed

crates/ide_db/src/call_info.rs

Lines changed: 1 addition & 526 deletions
Large diffs are not rendered by default.

crates/ide_db/src/call_info/tests.rs

Lines changed: 523 additions & 0 deletions
Large diffs are not rendered by default.

crates/ide_db/src/helpers/insert_use.rs

Lines changed: 1 addition & 638 deletions
Large diffs are not rendered by default.

crates/ide_db/src/helpers/insert_use/tests.rs

Lines changed: 620 additions & 0 deletions
Large diffs are not rendered by default.

crates/ide_db/src/line_index.rs

Lines changed: 1 addition & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -149,133 +149,4 @@ impl LineIndex {
149149
}
150150

151151
#[cfg(test)]
152-
mod tests {
153-
use super::*;
154-
155-
#[test]
156-
fn test_line_index() {
157-
let text = "hello\nworld";
158-
let index = LineIndex::new(text);
159-
assert_eq!(index.line_col(0.into()), LineCol { line: 0, col_utf16: 0 });
160-
assert_eq!(index.line_col(1.into()), LineCol { line: 0, col_utf16: 1 });
161-
assert_eq!(index.line_col(5.into()), LineCol { line: 0, col_utf16: 5 });
162-
assert_eq!(index.line_col(6.into()), LineCol { line: 1, col_utf16: 0 });
163-
assert_eq!(index.line_col(7.into()), LineCol { line: 1, col_utf16: 1 });
164-
assert_eq!(index.line_col(8.into()), LineCol { line: 1, col_utf16: 2 });
165-
assert_eq!(index.line_col(10.into()), LineCol { line: 1, col_utf16: 4 });
166-
assert_eq!(index.line_col(11.into()), LineCol { line: 1, col_utf16: 5 });
167-
assert_eq!(index.line_col(12.into()), LineCol { line: 1, col_utf16: 6 });
168-
169-
let text = "\nhello\nworld";
170-
let index = LineIndex::new(text);
171-
assert_eq!(index.line_col(0.into()), LineCol { line: 0, col_utf16: 0 });
172-
assert_eq!(index.line_col(1.into()), LineCol { line: 1, col_utf16: 0 });
173-
assert_eq!(index.line_col(2.into()), LineCol { line: 1, col_utf16: 1 });
174-
assert_eq!(index.line_col(6.into()), LineCol { line: 1, col_utf16: 5 });
175-
assert_eq!(index.line_col(7.into()), LineCol { line: 2, col_utf16: 0 });
176-
}
177-
178-
#[test]
179-
fn test_char_len() {
180-
assert_eq!('メ'.len_utf8(), 3);
181-
assert_eq!('メ'.len_utf16(), 1);
182-
}
183-
184-
#[test]
185-
fn test_empty_index() {
186-
let col_index = LineIndex::new(
187-
"
188-
const C: char = 'x';
189-
",
190-
);
191-
assert_eq!(col_index.utf16_lines.len(), 0);
192-
}
193-
194-
#[test]
195-
fn test_single_char() {
196-
let col_index = LineIndex::new(
197-
"
198-
const C: char = 'メ';
199-
",
200-
);
201-
202-
assert_eq!(col_index.utf16_lines.len(), 1);
203-
assert_eq!(col_index.utf16_lines[&1].len(), 1);
204-
assert_eq!(col_index.utf16_lines[&1][0], Utf16Char { start: 17.into(), end: 20.into() });
205-
206-
// UTF-8 to UTF-16, no changes
207-
assert_eq!(col_index.utf8_to_utf16_col(1, 15.into()), 15);
208-
209-
// UTF-8 to UTF-16
210-
assert_eq!(col_index.utf8_to_utf16_col(1, 22.into()), 20);
211-
212-
// UTF-16 to UTF-8, no changes
213-
assert_eq!(col_index.utf16_to_utf8_col(1, 15), TextSize::from(15));
214-
215-
// UTF-16 to UTF-8
216-
assert_eq!(col_index.utf16_to_utf8_col(1, 19), TextSize::from(21));
217-
218-
let col_index = LineIndex::new("a𐐏b");
219-
assert_eq!(col_index.utf16_to_utf8_col(0, 3), TextSize::from(5));
220-
}
221-
222-
#[test]
223-
fn test_string() {
224-
let col_index = LineIndex::new(
225-
"
226-
const C: char = \"メ メ\";
227-
",
228-
);
229-
230-
assert_eq!(col_index.utf16_lines.len(), 1);
231-
assert_eq!(col_index.utf16_lines[&1].len(), 2);
232-
assert_eq!(col_index.utf16_lines[&1][0], Utf16Char { start: 17.into(), end: 20.into() });
233-
assert_eq!(col_index.utf16_lines[&1][1], Utf16Char { start: 21.into(), end: 24.into() });
234-
235-
// UTF-8 to UTF-16
236-
assert_eq!(col_index.utf8_to_utf16_col(1, 15.into()), 15);
237-
238-
assert_eq!(col_index.utf8_to_utf16_col(1, 21.into()), 19);
239-
assert_eq!(col_index.utf8_to_utf16_col(1, 25.into()), 21);
240-
241-
assert!(col_index.utf8_to_utf16_col(2, 15.into()) == 15);
242-
243-
// UTF-16 to UTF-8
244-
assert_eq!(col_index.utf16_to_utf8_col(1, 15), TextSize::from(15));
245-
246-
// メ UTF-8: 0xE3 0x83 0xA1, UTF-16: 0x30E1
247-
assert_eq!(col_index.utf16_to_utf8_col(1, 17), TextSize::from(17)); // first メ at 17..20
248-
assert_eq!(col_index.utf16_to_utf8_col(1, 18), TextSize::from(20)); // space
249-
assert_eq!(col_index.utf16_to_utf8_col(1, 19), TextSize::from(21)); // second メ at 21..24
250-
251-
assert_eq!(col_index.utf16_to_utf8_col(2, 15), TextSize::from(15));
252-
}
253-
254-
#[test]
255-
fn test_splitlines() {
256-
fn r(lo: u32, hi: u32) -> TextRange {
257-
TextRange::new(lo.into(), hi.into())
258-
}
259-
260-
let text = "a\nbb\nccc\n";
261-
let line_index = LineIndex::new(text);
262-
263-
let actual = line_index.lines(r(0, 9)).collect::<Vec<_>>();
264-
let expected = vec![r(0, 2), r(2, 5), r(5, 9)];
265-
assert_eq!(actual, expected);
266-
267-
let text = "";
268-
let line_index = LineIndex::new(text);
269-
270-
let actual = line_index.lines(r(0, 0)).collect::<Vec<_>>();
271-
let expected = vec![];
272-
assert_eq!(actual, expected);
273-
274-
let text = "\n";
275-
let line_index = LineIndex::new(text);
276-
277-
let actual = line_index.lines(r(0, 1)).collect::<Vec<_>>();
278-
let expected = vec![r(0, 1)];
279-
assert_eq!(actual, expected)
280-
}
281-
}
152+
mod tests;
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
use super::*;
2+
3+
#[test]
4+
fn test_line_index() {
5+
let text = "hello\nworld";
6+
let index = LineIndex::new(text);
7+
assert_eq!(index.line_col(0.into()), LineCol { line: 0, col_utf16: 0 });
8+
assert_eq!(index.line_col(1.into()), LineCol { line: 0, col_utf16: 1 });
9+
assert_eq!(index.line_col(5.into()), LineCol { line: 0, col_utf16: 5 });
10+
assert_eq!(index.line_col(6.into()), LineCol { line: 1, col_utf16: 0 });
11+
assert_eq!(index.line_col(7.into()), LineCol { line: 1, col_utf16: 1 });
12+
assert_eq!(index.line_col(8.into()), LineCol { line: 1, col_utf16: 2 });
13+
assert_eq!(index.line_col(10.into()), LineCol { line: 1, col_utf16: 4 });
14+
assert_eq!(index.line_col(11.into()), LineCol { line: 1, col_utf16: 5 });
15+
assert_eq!(index.line_col(12.into()), LineCol { line: 1, col_utf16: 6 });
16+
17+
let text = "\nhello\nworld";
18+
let index = LineIndex::new(text);
19+
assert_eq!(index.line_col(0.into()), LineCol { line: 0, col_utf16: 0 });
20+
assert_eq!(index.line_col(1.into()), LineCol { line: 1, col_utf16: 0 });
21+
assert_eq!(index.line_col(2.into()), LineCol { line: 1, col_utf16: 1 });
22+
assert_eq!(index.line_col(6.into()), LineCol { line: 1, col_utf16: 5 });
23+
assert_eq!(index.line_col(7.into()), LineCol { line: 2, col_utf16: 0 });
24+
}
25+
26+
#[test]
27+
fn test_char_len() {
28+
assert_eq!('メ'.len_utf8(), 3);
29+
assert_eq!('メ'.len_utf16(), 1);
30+
}
31+
32+
#[test]
33+
fn test_empty_index() {
34+
let col_index = LineIndex::new(
35+
"
36+
const C: char = 'x';
37+
",
38+
);
39+
assert_eq!(col_index.utf16_lines.len(), 0);
40+
}
41+
42+
#[test]
43+
fn test_single_char() {
44+
let col_index = LineIndex::new(
45+
"
46+
const C: char = 'メ';
47+
",
48+
);
49+
50+
assert_eq!(col_index.utf16_lines.len(), 1);
51+
assert_eq!(col_index.utf16_lines[&1].len(), 1);
52+
assert_eq!(col_index.utf16_lines[&1][0], Utf16Char { start: 17.into(), end: 20.into() });
53+
54+
// UTF-8 to UTF-16, no changes
55+
assert_eq!(col_index.utf8_to_utf16_col(1, 15.into()), 15);
56+
57+
// UTF-8 to UTF-16
58+
assert_eq!(col_index.utf8_to_utf16_col(1, 22.into()), 20);
59+
60+
// UTF-16 to UTF-8, no changes
61+
assert_eq!(col_index.utf16_to_utf8_col(1, 15), TextSize::from(15));
62+
63+
// UTF-16 to UTF-8
64+
assert_eq!(col_index.utf16_to_utf8_col(1, 19), TextSize::from(21));
65+
66+
let col_index = LineIndex::new("a𐐏b");
67+
assert_eq!(col_index.utf16_to_utf8_col(0, 3), TextSize::from(5));
68+
}
69+
70+
#[test]
71+
fn test_string() {
72+
let col_index = LineIndex::new(
73+
"
74+
const C: char = \"メ メ\";
75+
",
76+
);
77+
78+
assert_eq!(col_index.utf16_lines.len(), 1);
79+
assert_eq!(col_index.utf16_lines[&1].len(), 2);
80+
assert_eq!(col_index.utf16_lines[&1][0], Utf16Char { start: 17.into(), end: 20.into() });
81+
assert_eq!(col_index.utf16_lines[&1][1], Utf16Char { start: 21.into(), end: 24.into() });
82+
83+
// UTF-8 to UTF-16
84+
assert_eq!(col_index.utf8_to_utf16_col(1, 15.into()), 15);
85+
86+
assert_eq!(col_index.utf8_to_utf16_col(1, 21.into()), 19);
87+
assert_eq!(col_index.utf8_to_utf16_col(1, 25.into()), 21);
88+
89+
assert!(col_index.utf8_to_utf16_col(2, 15.into()) == 15);
90+
91+
// UTF-16 to UTF-8
92+
assert_eq!(col_index.utf16_to_utf8_col(1, 15), TextSize::from(15));
93+
94+
// メ UTF-8: 0xE3 0x83 0xA1, UTF-16: 0x30E1
95+
assert_eq!(col_index.utf16_to_utf8_col(1, 17), TextSize::from(17)); // first メ at 17..20
96+
assert_eq!(col_index.utf16_to_utf8_col(1, 18), TextSize::from(20)); // space
97+
assert_eq!(col_index.utf16_to_utf8_col(1, 19), TextSize::from(21)); // second メ at 21..24
98+
99+
assert_eq!(col_index.utf16_to_utf8_col(2, 15), TextSize::from(15));
100+
}
101+
102+
#[test]
103+
fn test_splitlines() {
104+
fn r(lo: u32, hi: u32) -> TextRange {
105+
TextRange::new(lo.into(), hi.into())
106+
}
107+
108+
let text = "a\nbb\nccc\n";
109+
let line_index = LineIndex::new(text);
110+
111+
let actual = line_index.lines(r(0, 9)).collect::<Vec<_>>();
112+
let expected = vec![r(0, 2), r(2, 5), r(5, 9)];
113+
assert_eq!(actual, expected);
114+
115+
let text = "";
116+
let line_index = LineIndex::new(text);
117+
118+
let actual = line_index.lines(r(0, 0)).collect::<Vec<_>>();
119+
let expected = vec![];
120+
assert_eq!(actual, expected);
121+
122+
let text = "\n";
123+
let line_index = LineIndex::new(text);
124+
125+
let actual = line_index.lines(r(0, 1)).collect::<Vec<_>>();
126+
let expected = vec![r(0, 1)];
127+
assert_eq!(actual, expected)
128+
}

0 commit comments

Comments
 (0)