Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'lib/line-index/src/tests.rs')
| -rw-r--r-- | lib/line-index/src/tests.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/line-index/src/tests.rs b/lib/line-index/src/tests.rs index 57fad1dfc0..f2bb04aec3 100644 --- a/lib/line-index/src/tests.rs +++ b/lib/line-index/src/tests.rs @@ -195,3 +195,26 @@ fn test_every_chars() { } } } + +#[test] +fn test_line() { + use text_size::TextRange; + + macro_rules! validate { + ($text:expr, $line:expr, $expected_start:literal .. $expected_end:literal) => { + let line_index = LineIndex::new($text); + assert_eq!( + line_index.line($line), + Some(TextRange::new( + TextSize::from($expected_start), + TextSize::from($expected_end) + )) + ); + }; + } + + validate!("", 0, 0..0); + validate!("\n", 1, 1..1); + validate!("\nabc", 1, 1..4); + validate!("\nabc\ndef", 1, 1..5); +} |