diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-17 15:58:42 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-17 15:58:42 +0000 |
commit | f7b0135c64da13d64fb0add0c96e84289beb07b4 (patch) | |
tree | 1efc29623af8929e31fc90a34f1588bc24375985 /crates/ra_text_edit/src | |
parent | b4c30fb8961177809646ccd72a7f62c7fd4fca4f (diff) | |
parent | 57140f1730b4ac39697bfad530409ac8472e4e9d (diff) |
Merge #3195
3195: Drop proptest tests r=matklad a=matklad
It takes waaay to long to compile.
We should add quickcheck tests when we touch the relevant code next
time.
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_text_edit/src')
-rw-r--r-- | crates/ra_text_edit/src/lib.rs | 5 | ||||
-rw-r--r-- | crates/ra_text_edit/src/test_utils.rs | 83 |
2 files changed, 2 insertions, 86 deletions
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 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | mod text_edit; | 3 | mod text_edit; |
4 | pub mod test_utils; | ||
5 | |||
6 | pub use crate::text_edit::{TextEdit, TextEditBuilder}; | ||
7 | 4 | ||
8 | use text_unit::{TextRange, TextUnit}; | 5 | use text_unit::{TextRange, TextUnit}; |
9 | 6 | ||
7 | pub use crate::text_edit::{TextEdit, TextEditBuilder}; | ||
8 | |||
10 | /// Must not overlap with other `AtomTextEdit`s | 9 | /// Must not overlap with other `AtomTextEdit`s |
11 | #[derive(Debug, Clone)] | 10 | #[derive(Debug, Clone)] |
12 | pub struct AtomTextEdit { | 11 | 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 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | use crate::{AtomTextEdit, TextEdit}; | ||
4 | use proptest::prelude::*; | ||
5 | use text_unit::{TextRange, TextUnit}; | ||
6 | |||
7 | pub fn arb_text() -> proptest::string::RegexGeneratorStrategy<String> { | ||
8 | // generate multiple newlines | ||
9 | proptest::string::string_regex("(.*\n?)*").unwrap() | ||
10 | } | ||
11 | |||
12 | fn text_offsets(text: &str) -> Vec<TextUnit> { | ||
13 | text.char_indices().map(|(i, _)| TextUnit::from_usize(i)).collect() | ||
14 | } | ||
15 | |||
16 | pub fn arb_offset(text: &str) -> BoxedStrategy<TextUnit> { | ||
17 | let offsets = text_offsets(text); | ||
18 | // this is necessary to avoid "Uniform::new called with `low >= high`" panic | ||
19 | if offsets.is_empty() { | ||
20 | Just(TextUnit::from(0)).boxed() | ||
21 | } else { | ||
22 | prop::sample::select(offsets).boxed() | ||
23 | } | ||
24 | } | ||
25 | |||
26 | pub fn arb_text_edit(text: &str) -> BoxedStrategy<TextEdit> { | ||
27 | if text.is_empty() { | ||
28 | // only valid edits | ||
29 | return Just(vec![]) | ||
30 | .boxed() | ||
31 | .prop_union( | ||
32 | arb_text() | ||
33 | .prop_map(|text| vec![AtomTextEdit::insert(TextUnit::from(0), text)]) | ||
34 | .boxed(), | ||
35 | ) | ||
36 | .prop_map(TextEdit::from_atoms) | ||
37 | .boxed(); | ||
38 | } | ||
39 | |||
40 | let offsets = text_offsets(text); | ||
41 | let max_cuts = 7.min(offsets.len()); | ||
42 | |||
43 | proptest::sample::subsequence(offsets, 0..max_cuts) | ||
44 | .prop_flat_map(|cuts| { | ||
45 | let strategies: Vec<_> = cuts | ||
46 | .chunks(2) | ||
47 | .map(|chunk| match *chunk { | ||
48 | [from, to] => { | ||
49 | let range = TextRange::from_to(from, to); | ||
50 | Just(AtomTextEdit::delete(range)) | ||
51 | .boxed() | ||
52 | .prop_union( | ||
53 | arb_text() | ||
54 | .prop_map(move |text| AtomTextEdit::replace(range, text)) | ||
55 | .boxed(), | ||
56 | ) | ||
57 | .boxed() | ||
58 | } | ||
59 | [x] => arb_text().prop_map(move |text| AtomTextEdit::insert(x, text)).boxed(), | ||
60 | _ => unreachable!(), | ||
61 | }) | ||
62 | .collect(); | ||
63 | strategies | ||
64 | }) | ||
65 | .prop_map(TextEdit::from_atoms) | ||
66 | .boxed() | ||
67 | } | ||
68 | |||
69 | #[derive(Debug, Clone)] | ||
70 | pub struct ArbTextWithEdit { | ||
71 | pub text: String, | ||
72 | pub edit: TextEdit, | ||
73 | } | ||
74 | |||
75 | pub fn arb_text_with_edit() -> BoxedStrategy<ArbTextWithEdit> { | ||
76 | let text = arb_text(); | ||
77 | text.prop_flat_map(|s| { | ||
78 | let edit = arb_text_edit(&s); | ||
79 | (Just(s), edit) | ||
80 | }) | ||
81 | .prop_map(|(text, edit)| ArbTextWithEdit { text, edit }) | ||
82 | .boxed() | ||
83 | } | ||