From 863ed19946d6f707ce09dd77bf26b26be73e097c Mon Sep 17 00:00:00 2001 From: Bernardo Date: Mon, 24 Dec 2018 17:01:25 +0100 Subject: remove benchmark and simplify tests --- crates/ra_editor/src/line_index.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'crates/ra_editor/src/line_index.rs') diff --git a/crates/ra_editor/src/line_index.rs b/crates/ra_editor/src/line_index.rs index 5304fbcf6..898fee7e0 100644 --- a/crates/ra_editor/src/line_index.rs +++ b/crates/ra_editor/src/line_index.rs @@ -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()) { -- cgit v1.2.3