aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db/src/line_index
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-02-16 16:34:22 +0000
committerGitHub <[email protected]>2021-02-16 16:34:22 +0000
commitc9672a0539a59b626619724092077f57c70e6ffe (patch)
tree77097454dc598a5e0a0b1d98b8c9645b9e213289 /crates/ide_db/src/line_index
parentf7b7a09f752caba21f2b21ccb8f74421a599d2c6 (diff)
parent3f09e3fba62839f26da2f27ce27a2335b1dca7ef (diff)
Merge #7657
7657: utf8 r=matklad a=matklad - Prepare for utf-8 offsets - reduce code duplication in tests - Make utf8 default, implement utf16 in terms of it - Make it easy to add additional context for offset conversion - Implement utf8 offsets closes #7453 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ide_db/src/line_index')
-rw-r--r--crates/ide_db/src/line_index/tests.rs33
1 files changed, 19 insertions, 14 deletions
diff --git a/crates/ide_db/src/line_index/tests.rs b/crates/ide_db/src/line_index/tests.rs
index 05f7484e8..09f3bca62 100644
--- a/crates/ide_db/src/line_index/tests.rs
+++ b/crates/ide_db/src/line_index/tests.rs
@@ -3,24 +3,29 @@ use super::*;
3#[test] 3#[test]
4fn test_line_index() { 4fn test_line_index() {
5 let text = "hello\nworld"; 5 let text = "hello\nworld";
6 let table = [
7 (00, 0, 0),
8 (01, 0, 1),
9 (05, 0, 5),
10 (06, 1, 0),
11 (07, 1, 1),
12 (08, 1, 2),
13 (10, 1, 4),
14 (11, 1, 5),
15 (12, 1, 6),
16 ];
17
6 let index = LineIndex::new(text); 18 let index = LineIndex::new(text);
7 assert_eq!(index.line_col(0.into()), LineCol { line: 0, col_utf16: 0 }); 19 for &(offset, line, col) in &table {
8 assert_eq!(index.line_col(1.into()), LineCol { line: 0, col_utf16: 1 }); 20 assert_eq!(index.line_col(offset.into()), LineCol { line, col });
9 assert_eq!(index.line_col(5.into()), LineCol { line: 0, col_utf16: 5 }); 21 }
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 22
17 let text = "\nhello\nworld"; 23 let text = "\nhello\nworld";
24 let table = [(0, 0, 0), (1, 1, 0), (2, 1, 1), (6, 1, 5), (7, 2, 0)];
18 let index = LineIndex::new(text); 25 let index = LineIndex::new(text);
19 assert_eq!(index.line_col(0.into()), LineCol { line: 0, col_utf16: 0 }); 26 for &(offset, line, col) in &table {
20 assert_eq!(index.line_col(1.into()), LineCol { line: 1, col_utf16: 0 }); 27 assert_eq!(index.line_col(offset.into()), LineCol { line, col });
21 assert_eq!(index.line_col(2.into()), LineCol { line: 1, col_utf16: 1 }); 28 }
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} 29}
25 30
26#[test] 31#[test]