remove benchmark and simplify tests

This commit is contained in:
Bernardo 2018-12-24 17:01:25 +01:00
parent 6b2da4e547
commit 863ed19946
7 changed files with 70 additions and 382 deletions

View file

@ -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()) {