From dee426e1b120cd12fc608df77f977d4800b6655d Mon Sep 17 00:00:00 2001 From: Bernardo Date: Wed, 12 Dec 2018 19:25:50 +0100 Subject: simplify and reduce number of values explored --- crates/ra_text_edit/src/test_utils.rs | 52 ++++++++++++++++------------------- 1 file changed, 23 insertions(+), 29 deletions(-) (limited to 'crates/ra_text_edit/src') diff --git a/crates/ra_text_edit/src/test_utils.rs b/crates/ra_text_edit/src/test_utils.rs index 92b79ab59..29301bff3 100644 --- a/crates/ra_text_edit/src/test_utils.rs +++ b/crates/ra_text_edit/src/test_utils.rs @@ -24,41 +24,35 @@ pub fn arb_offset(text: &str) -> BoxedStrategy { } pub fn arb_edits(text: &str) -> BoxedStrategy> { - let offsets = text_offsets(text); - let offsets_len = offsets.len(); - - if offsets_len == 0 { - return proptest::bool::ANY - .prop_flat_map(|b| { - // only valid edits - if b { - arb_text() - .prop_map(|text| vec![AtomTextEdit::insert(TextUnit::from(0), text)]) - .boxed() - } else { - Just(vec![]).boxed() - } - }) + 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(), + ) .boxed(); } - proptest::sample::subsequence(offsets, 0..offsets_len) - .prop_flat_map(|xs| { - let strategies: Vec<_> = xs + let offsets = text_offsets(text); + let max_cuts = offsets.len().min(7); + + 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); - (proptest::bool::ANY) - .prop_flat_map(move |b| { - if b { - Just(AtomTextEdit::delete(range)).boxed() - } else { - arb_text() - .prop_map(move |text| AtomTextEdit::replace(range, text)) - .boxed() - } - }) + Just(AtomTextEdit::delete(range)) + .boxed() + .prop_union( + arb_text() + .prop_map(move |text| AtomTextEdit::replace(range, text)) + .boxed(), + ) .boxed() } &[x] => arb_text() @@ -92,7 +86,7 @@ fn intersect(r1: TextRange, r2: TextRange) -> Option { } proptest! { -#[test] + #[test] fn atom_text_edits_are_valid((text, edits) in arb_text_with_edits()) { proptest_atom_text_edits_are_valid(text, edits) } -- cgit v1.2.3