From 57140f1730b4ac39697bfad530409ac8472e4e9d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 17 Feb 2020 16:57:06 +0100 Subject: Drop proptest tests It takes waaay to long to compile. We should add quickcheck tests when we touch the relevant code next time. --- crates/ra_ide_db/Cargo.toml | 6 ---- crates/ra_ide_db/src/line_index.rs | 60 -------------------------------- crates/ra_ide_db/src/line_index_utils.rs | 42 ---------------------- 3 files changed, 108 deletions(-) (limited to 'crates/ra_ide_db') diff --git a/crates/ra_ide_db/Cargo.toml b/crates/ra_ide_db/Cargo.toml index 495fffb5a..ad3acce59 100644 --- a/crates/ra_ide_db/Cargo.toml +++ b/crates/ra_ide_db/Cargo.toml @@ -38,9 +38,3 @@ hir = { path = "../ra_hir", package = "ra_hir" } [dev-dependencies] insta = "0.13.0" - -[dev-dependencies.proptest] -version = "0.9.0" -# Disable `fork` feature to allow compiling on webassembly -default-features = false -features = ["std", "bit-set", "break-dead-code"] diff --git a/crates/ra_ide_db/src/line_index.rs b/crates/ra_ide_db/src/line_index.rs index 452c87ac5..af7b759e5 100644 --- a/crates/ra_ide_db/src/line_index.rs +++ b/crates/ra_ide_db/src/line_index.rs @@ -124,31 +124,9 @@ impl LineIndex { } } -#[cfg(test)] -/// Simple reference implementation to use in proptests -pub 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 -} - #[cfg(test)] mod test_line_index { use super::*; - use proptest::{prelude::*, proptest}; - use ra_text_edit::test_utils::{arb_offset, arb_text}; #[test] fn test_line_index() { @@ -173,44 +151,6 @@ mod test_line_index { assert_eq!(index.line_col(7.into()), LineCol { line: 2, col_utf16: 0 }); } - fn arb_text_with_offset() -> BoxedStrategy<(TextUnit, String)> { - arb_text().prop_flat_map(|text| (arb_offset(&text), Just(text))).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()) { - let expected = to_line_col(&text, offset); - let line_index = LineIndex::new(&text); - let actual = line_index.line_col(offset); - - assert_eq!(actual, expected); - } - } -} - -#[cfg(test)] -mod test_utf8_utf16_conv { - use super::*; - #[test] fn test_char_len() { assert_eq!('メ'.len_utf8(), 3); diff --git a/crates/ra_ide_db/src/line_index_utils.rs b/crates/ra_ide_db/src/line_index_utils.rs index 435b06511..75a498151 100644 --- a/crates/ra_ide_db/src/line_index_utils.rs +++ b/crates/ra_ide_db/src/line_index_utils.rs @@ -297,45 +297,3 @@ impl RunningLineCol { self.col_adjust += range.len() - TextUnit::from(1); } } - -#[cfg(test)] -mod test { - use proptest::{prelude::*, proptest}; - use ra_text_edit::test_utils::{arb_offset, arb_text_with_edit}; - use ra_text_edit::TextEdit; - - use crate::line_index; - - use super::*; - - #[derive(Debug)] - struct ArbTextWithEditAndOffset { - text: String, - edit: TextEdit, - edited_text: String, - offset: TextUnit, - } - - fn arb_text_with_edit_and_offset() -> BoxedStrategy { - arb_text_with_edit() - .prop_flat_map(|x| { - let edited_text = x.edit.apply(&x.text); - let arb_offset = arb_offset(&edited_text); - (Just(x), Just(edited_text), arb_offset).prop_map(|(x, edited_text, offset)| { - ArbTextWithEditAndOffset { text: x.text, edit: x.edit, edited_text, offset } - }) - }) - .boxed() - } - - proptest! { - #[test] - fn test_translate_offset_with_edit(x in arb_text_with_edit_and_offset()) { - let expected = line_index::to_line_col(&x.edited_text, x.offset); - let line_index = LineIndex::new(&x.text); - let actual = translate_offset_with_edit(&line_index, x.offset, &x.edit); - - assert_eq!(actual, expected); - } - } -} -- cgit v1.2.3