diff options
author | Aleksey Kladov <[email protected]> | 2021-02-12 18:31:32 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-02-16 16:17:32 +0000 |
commit | 00cc778c8c62e8f68531c1cadcce8b05b7287d84 (patch) | |
tree | a021472f303861aae0212aec5b773b6d8562c788 /crates | |
parent | 2cb4ac9eb4cb02e7d14ec50a9e7d8e9fe49a4ec1 (diff) |
reduce code duplication in tests
Diffstat (limited to 'crates')
-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] |