diff options
-rw-r--r-- | crates/ra_text_edit/src/test_utils.rs | 52 |
1 files changed, 23 insertions, 29 deletions
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<TextUnit> { | |||
24 | } | 24 | } |
25 | 25 | ||
26 | pub fn arb_edits(text: &str) -> BoxedStrategy<Vec<AtomTextEdit>> { | 26 | pub fn arb_edits(text: &str) -> BoxedStrategy<Vec<AtomTextEdit>> { |
27 | let offsets = text_offsets(text); | 27 | if text.is_empty() { |
28 | let offsets_len = offsets.len(); | 28 | // only valid edits |
29 | 29 | return Just(vec![]) | |
30 | if offsets_len == 0 { | 30 | .boxed() |
31 | return proptest::bool::ANY | 31 | .prop_union( |
32 | .prop_flat_map(|b| { | 32 | arb_text() |
33 | // only valid edits | 33 | .prop_map(|text| vec![AtomTextEdit::insert(TextUnit::from(0), text)]) |
34 | if b { | 34 | .boxed(), |
35 | arb_text() | 35 | ) |
36 | .prop_map(|text| vec![AtomTextEdit::insert(TextUnit::from(0), text)]) | ||
37 | .boxed() | ||
38 | } else { | ||
39 | Just(vec![]).boxed() | ||
40 | } | ||
41 | }) | ||
42 | .boxed(); | 36 | .boxed(); |
43 | } | 37 | } |
44 | 38 | ||
45 | proptest::sample::subsequence(offsets, 0..offsets_len) | 39 | let offsets = text_offsets(text); |
46 | .prop_flat_map(|xs| { | 40 | let max_cuts = offsets.len().min(7); |
47 | let strategies: Vec<_> = xs | 41 | |
42 | proptest::sample::subsequence(offsets, 0..max_cuts) | ||
43 | .prop_flat_map(|cuts| { | ||
44 | let strategies: Vec<_> = cuts | ||
48 | .chunks(2) | 45 | .chunks(2) |
49 | .map(|chunk| match chunk { | 46 | .map(|chunk| match chunk { |
50 | &[from, to] => { | 47 | &[from, to] => { |
51 | let range = TextRange::from_to(from, to); | 48 | let range = TextRange::from_to(from, to); |
52 | (proptest::bool::ANY) | 49 | Just(AtomTextEdit::delete(range)) |
53 | .prop_flat_map(move |b| { | 50 | .boxed() |
54 | if b { | 51 | .prop_union( |
55 | Just(AtomTextEdit::delete(range)).boxed() | 52 | arb_text() |
56 | } else { | 53 | .prop_map(move |text| AtomTextEdit::replace(range, text)) |
57 | arb_text() | 54 | .boxed(), |
58 | .prop_map(move |text| AtomTextEdit::replace(range, text)) | 55 | ) |
59 | .boxed() | ||
60 | } | ||
61 | }) | ||
62 | .boxed() | 56 | .boxed() |
63 | } | 57 | } |
64 | &[x] => arb_text() | 58 | &[x] => arb_text() |
@@ -92,7 +86,7 @@ fn intersect(r1: TextRange, r2: TextRange) -> Option<TextRange> { | |||
92 | } | 86 | } |
93 | 87 | ||
94 | proptest! { | 88 | proptest! { |
95 | #[test] | 89 | #[test] |
96 | fn atom_text_edits_are_valid((text, edits) in arb_text_with_edits()) { | 90 | fn atom_text_edits_are_valid((text, edits) in arb_text_with_edits()) { |
97 | proptest_atom_text_edits_are_valid(text, edits) | 91 | proptest_atom_text_edits_are_valid(text, edits) |
98 | } | 92 | } |