diff options
-rw-r--r-- | crates/ide_db/src/line_index/tests.rs | 33 |
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 1a109654e..af51d7348 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] |
4 | fn test_line_index() { | 4 | fn 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()), LineColUtf16 { line: 0, col: 0 }); | 19 | for &(offset, line, col) in &table { |
8 | assert_eq!(index.line_col(1.into()), LineColUtf16 { line: 0, col: 1 }); | 20 | assert_eq!(index.line_col(offset.into()), LineColUtf16 { line, col }); |
9 | assert_eq!(index.line_col(5.into()), LineColUtf16 { line: 0, col: 5 }); | 21 | } |
10 | assert_eq!(index.line_col(6.into()), LineColUtf16 { line: 1, col: 0 }); | ||
11 | assert_eq!(index.line_col(7.into()), LineColUtf16 { line: 1, col: 1 }); | ||
12 | assert_eq!(index.line_col(8.into()), LineColUtf16 { line: 1, col: 2 }); | ||
13 | assert_eq!(index.line_col(10.into()), LineColUtf16 { line: 1, col: 4 }); | ||
14 | assert_eq!(index.line_col(11.into()), LineColUtf16 { line: 1, col: 5 }); | ||
15 | assert_eq!(index.line_col(12.into()), LineColUtf16 { line: 1, col: 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()), LineColUtf16 { line: 0, col: 0 }); | 26 | for &(offset, line, col) in &table { |
20 | assert_eq!(index.line_col(1.into()), LineColUtf16 { line: 1, col: 0 }); | 27 | assert_eq!(index.line_col(offset.into()), LineColUtf16 { line, col }); |
21 | assert_eq!(index.line_col(2.into()), LineColUtf16 { line: 1, col: 1 }); | 28 | } |
22 | assert_eq!(index.line_col(6.into()), LineColUtf16 { line: 1, col: 5 }); | ||
23 | assert_eq!(index.line_col(7.into()), LineColUtf16 { line: 2, col: 0 }); | ||
24 | } | 29 | } |
25 | 30 | ||
26 | #[test] | 31 | #[test] |