mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 23:25:03 +00:00
remove benchmark and simplify tests
This commit is contained in:
parent
6b2da4e547
commit
863ed19946
7 changed files with 70 additions and 382 deletions
|
@ -128,8 +128,8 @@ impl LineIndex {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
/// Simple reference implementation to use in proptests
|
||||
/// and benchmarks as baseline
|
||||
pub fn to_line_col(text: &str, offset: TextUnit) -> LineCol {
|
||||
let mut res = LineCol {
|
||||
line: 0,
|
||||
|
@ -270,6 +270,27 @@ mod test_line_index {
|
|||
.boxed()
|
||||
}
|
||||
|
||||
fn to_line_col(text: &str, offset: TextUnit) -> LineCol {
|
||||
let mut res = LineCol {
|
||||
line: 0,
|
||||
col_utf16: 0,
|
||||
};
|
||||
for (i, c) in text.char_indices() {
|
||||
if i + c.len_utf8() > offset.to_usize() {
|
||||
// if it's an invalid offset, inside a multibyte char
|
||||
// return as if it was at the start of the char
|
||||
break;
|
||||
}
|
||||
if c == '\n' {
|
||||
res.line += 1;
|
||||
res.col_utf16 = 0;
|
||||
} else {
|
||||
res.col_utf16 += 1;
|
||||
}
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
proptest! {
|
||||
#[test]
|
||||
fn test_line_index_proptest((offset, text) in arb_text_with_offset()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue