From 00cc778c8c62e8f68531c1cadcce8b05b7287d84 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 12 Feb 2021 21:31:32 +0300 Subject: reduce code duplication in tests --- crates/ide_db/src/line_index/tests.rs | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'crates/ide_db/src') 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::*; #[test] fn test_line_index() { let text = "hello\nworld"; + let table = [ + (00, 0, 0), + (01, 0, 1), + (05, 0, 5), + (06, 1, 0), + (07, 1, 1), + (08, 1, 2), + (10, 1, 4), + (11, 1, 5), + (12, 1, 6), + ]; + let index = LineIndex::new(text); - assert_eq!(index.line_col(0.into()), LineColUtf16 { line: 0, col: 0 }); - assert_eq!(index.line_col(1.into()), LineColUtf16 { line: 0, col: 1 }); - assert_eq!(index.line_col(5.into()), LineColUtf16 { line: 0, col: 5 }); - assert_eq!(index.line_col(6.into()), LineColUtf16 { line: 1, col: 0 }); - assert_eq!(index.line_col(7.into()), LineColUtf16 { line: 1, col: 1 }); - assert_eq!(index.line_col(8.into()), LineColUtf16 { line: 1, col: 2 }); - assert_eq!(index.line_col(10.into()), LineColUtf16 { line: 1, col: 4 }); - assert_eq!(index.line_col(11.into()), LineColUtf16 { line: 1, col: 5 }); - assert_eq!(index.line_col(12.into()), LineColUtf16 { line: 1, col: 6 }); + for &(offset, line, col) in &table { + assert_eq!(index.line_col(offset.into()), LineColUtf16 { line, col }); + } let text = "\nhello\nworld"; + let table = [(0, 0, 0), (1, 1, 0), (2, 1, 1), (6, 1, 5), (7, 2, 0)]; let index = LineIndex::new(text); - assert_eq!(index.line_col(0.into()), LineColUtf16 { line: 0, col: 0 }); - assert_eq!(index.line_col(1.into()), LineColUtf16 { line: 1, col: 0 }); - assert_eq!(index.line_col(2.into()), LineColUtf16 { line: 1, col: 1 }); - assert_eq!(index.line_col(6.into()), LineColUtf16 { line: 1, col: 5 }); - assert_eq!(index.line_col(7.into()), LineColUtf16 { line: 2, col: 0 }); + for &(offset, line, col) in &table { + assert_eq!(index.line_col(offset.into()), LineColUtf16 { line, col }); + } } #[test] -- cgit v1.2.3