mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 23:25:03 +00:00
line-index method to allow clamping column to line length
Part of #18240
This commit is contained in:
parent
0319586ef2
commit
d42a4e6c88
3 changed files with 32 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue