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/Cargo.toml | 6 --- 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 ---------------- crates/ra_text_edit/Cargo.toml | 6 --- crates/ra_text_edit/src/lib.rs | 5 +- crates/ra_text_edit/src/test_utils.rs | 83 -------------------------------- 7 files changed, 2 insertions(+), 206 deletions(-) delete mode 100644 crates/ra_text_edit/src/test_utils.rs (limited to 'crates') diff --git a/crates/ra_ide/Cargo.toml b/crates/ra_ide/Cargo.toml index 9ace35229..d50cf1d20 100644 --- a/crates/ra_ide/Cargo.toml +++ b/crates/ra_ide/Cargo.toml @@ -41,9 +41,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/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); - } - } -} diff --git a/crates/ra_text_edit/Cargo.toml b/crates/ra_text_edit/Cargo.toml index 8573c521a..4490ae43b 100644 --- a/crates/ra_text_edit/Cargo.toml +++ b/crates/ra_text_edit/Cargo.toml @@ -11,11 +11,5 @@ doctest = false [dependencies] text_unit = "0.1.6" -[dependencies.proptest] -version = "0.9.0" -# Disable `fork` feature to allow compiling on webassembly -default-features = false -features = ["std", "bit-set", "break-dead-code"] - [dev-dependencies] test_utils = { path = "../test_utils" } diff --git a/crates/ra_text_edit/src/lib.rs b/crates/ra_text_edit/src/lib.rs index 37f23d043..f6769e6a6 100644 --- a/crates/ra_text_edit/src/lib.rs +++ b/crates/ra_text_edit/src/lib.rs @@ -1,12 +1,11 @@ //! FIXME: write short doc here mod text_edit; -pub mod test_utils; - -pub use crate::text_edit::{TextEdit, TextEditBuilder}; use text_unit::{TextRange, TextUnit}; +pub use crate::text_edit::{TextEdit, TextEditBuilder}; + /// Must not overlap with other `AtomTextEdit`s #[derive(Debug, Clone)] pub struct AtomTextEdit { diff --git a/crates/ra_text_edit/src/test_utils.rs b/crates/ra_text_edit/src/test_utils.rs deleted file mode 100644 index d4c7840ff..000000000 --- a/crates/ra_text_edit/src/test_utils.rs +++ /dev/null @@ -1,83 +0,0 @@ -//! FIXME: write short doc here - -use crate::{AtomTextEdit, TextEdit}; -use proptest::prelude::*; -use text_unit::{TextRange, TextUnit}; - -pub fn arb_text() -> proptest::string::RegexGeneratorStrategy { - // generate multiple newlines - proptest::string::string_regex("(.*\n?)*").unwrap() -} - -fn text_offsets(text: &str) -> Vec { - text.char_indices().map(|(i, _)| TextUnit::from_usize(i)).collect() -} - -pub fn arb_offset(text: &str) -> BoxedStrategy { - let offsets = text_offsets(text); - // this is necessary to avoid "Uniform::new called with `low >= high`" panic - if offsets.is_empty() { - Just(TextUnit::from(0)).boxed() - } else { - prop::sample::select(offsets).boxed() - } -} - -pub fn arb_text_edit(text: &str) -> BoxedStrategy { - if text.is_empty() { - // only valid edits - return Just(vec![]) - .boxed() - .prop_union( - arb_text() - .prop_map(|text| vec![AtomTextEdit::insert(TextUnit::from(0), text)]) - .boxed(), - ) - .prop_map(TextEdit::from_atoms) - .boxed(); - } - - let offsets = text_offsets(text); - let max_cuts = 7.min(offsets.len()); - - proptest::sample::subsequence(offsets, 0..max_cuts) - .prop_flat_map(|cuts| { - let strategies: Vec<_> = cuts - .chunks(2) - .map(|chunk| match *chunk { - [from, to] => { - let range = TextRange::from_to(from, to); - Just(AtomTextEdit::delete(range)) - .boxed() - .prop_union( - arb_text() - .prop_map(move |text| AtomTextEdit::replace(range, text)) - .boxed(), - ) - .boxed() - } - [x] => arb_text().prop_map(move |text| AtomTextEdit::insert(x, text)).boxed(), - _ => unreachable!(), - }) - .collect(); - strategies - }) - .prop_map(TextEdit::from_atoms) - .boxed() -} - -#[derive(Debug, Clone)] -pub struct ArbTextWithEdit { - pub text: String, - pub edit: TextEdit, -} - -pub fn arb_text_with_edit() -> BoxedStrategy { - let text = arb_text(); - text.prop_flat_map(|s| { - let edit = arb_text_edit(&s); - (Just(s), edit) - }) - .prop_map(|(text, edit)| ArbTextWithEdit { text, edit }) - .boxed() -} -- cgit v1.2.3