simplify and reduce number of values explored

This commit is contained in:
Bernardo 2018-12-12 19:25:50 +01:00
parent 3d98744c2a
commit dee426e1b1

View File

@ -24,41 +24,35 @@ pub fn arb_offset(text: &str) -> BoxedStrategy<TextUnit> {
} }
pub fn arb_edits(text: &str) -> BoxedStrategy<Vec<AtomTextEdit>> { pub fn arb_edits(text: &str) -> BoxedStrategy<Vec<AtomTextEdit>> {
let offsets = text_offsets(text); if text.is_empty() {
let offsets_len = offsets.len(); // only valid edits
return Just(vec![])
if offsets_len == 0 { .boxed()
return proptest::bool::ANY .prop_union(
.prop_flat_map(|b| { arb_text()
// only valid edits .prop_map(|text| vec![AtomTextEdit::insert(TextUnit::from(0), text)])
if b { .boxed(),
arb_text() )
.prop_map(|text| vec![AtomTextEdit::insert(TextUnit::from(0), text)])
.boxed()
} else {
Just(vec![]).boxed()
}
})
.boxed(); .boxed();
} }
proptest::sample::subsequence(offsets, 0..offsets_len) let offsets = text_offsets(text);
.prop_flat_map(|xs| { let max_cuts = offsets.len().min(7);
let strategies: Vec<_> = xs
proptest::sample::subsequence(offsets, 0..max_cuts)
.prop_flat_map(|cuts| {
let strategies: Vec<_> = cuts
.chunks(2) .chunks(2)
.map(|chunk| match chunk { .map(|chunk| match chunk {
&[from, to] => { &[from, to] => {
let range = TextRange::from_to(from, to); let range = TextRange::from_to(from, to);
(proptest::bool::ANY) Just(AtomTextEdit::delete(range))
.prop_flat_map(move |b| { .boxed()
if b { .prop_union(
Just(AtomTextEdit::delete(range)).boxed() arb_text()
} else { .prop_map(move |text| AtomTextEdit::replace(range, text))
arb_text() .boxed(),
.prop_map(move |text| AtomTextEdit::replace(range, text)) )
.boxed()
}
})
.boxed() .boxed()
} }
&[x] => arb_text() &[x] => arb_text()
@ -92,7 +86,7 @@ fn intersect(r1: TextRange, r2: TextRange) -> Option<TextRange> {
} }
proptest! { proptest! {
#[test] #[test]
fn atom_text_edits_are_valid((text, edits) in arb_text_with_edits()) { fn atom_text_edits_are_valid((text, edits) in arb_text_with_edits()) {
proptest_atom_text_edits_are_valid(text, edits) proptest_atom_text_edits_are_valid(text, edits)
} }