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_text_edit/Cargo.toml | 6 --- crates/ra_text_edit/src/lib.rs | 5 +-- crates/ra_text_edit/src/test_utils.rs | 83 ----------------------------------- 3 files changed, 2 insertions(+), 92 deletions(-) delete mode 100644 crates/ra_text_edit/src/test_utils.rs (limited to 'crates/ra_text_edit') 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