mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
simplify and reduce number of values explored
This commit is contained in:
parent
3d98744c2a
commit
dee426e1b1
1 changed files with 23 additions and 29 deletions
|
@ -24,41 +24,35 @@ pub fn arb_offset(text: &str) -> BoxedStrategy<TextUnit> {
|
|||
}
|
||||
|
||||
pub fn arb_edits(text: &str) -> BoxedStrategy<Vec<AtomTextEdit>> {
|
||||
let offsets = text_offsets(text);
|
||||
let offsets_len = offsets.len();
|
||||
|
||||
if offsets_len == 0 {
|
||||
return proptest::bool::ANY
|
||||
.prop_flat_map(|b| {
|
||||
if text.is_empty() {
|
||||
// only valid edits
|
||||
if b {
|
||||
return Just(vec![])
|
||||
.boxed()
|
||||
.prop_union(
|
||||
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)
|
||||
.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 {
|
||||
Just(AtomTextEdit::delete(range))
|
||||
.boxed()
|
||||
.prop_union(
|
||||
arb_text()
|
||||
.prop_map(move |text| AtomTextEdit::replace(range, text))
|
||||
.boxed()
|
||||
}
|
||||
})
|
||||
.boxed(),
|
||||
)
|
||||
.boxed()
|
||||
}
|
||||
&[x] => arb_text()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue