diff options
author | pcpthm <[email protected]> | 2019-03-21 19:11:21 +0000 |
---|---|---|
committer | pcpthm <[email protected]> | 2019-03-21 23:09:11 +0000 |
commit | c60ec02d75a7cfa57a5a2b1e2256b70224deb531 (patch) | |
tree | c30df14c3452087d036fa6d6f3a913732f3701dc /crates/ra_syntax/src | |
parent | ec59d9bda569057727a9b04314c63e3b3adaaa95 (diff) |
Use template text to improve reparse fuzzing
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/fuzz.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/crates/ra_syntax/src/fuzz.rs b/crates/ra_syntax/src/fuzz.rs index c7084bc6d..1153f0fb9 100644 --- a/crates/ra_syntax/src/fuzz.rs +++ b/crates/ra_syntax/src/fuzz.rs | |||
@@ -22,12 +22,16 @@ pub struct CheckReparse { | |||
22 | 22 | ||
23 | impl CheckReparse { | 23 | impl CheckReparse { |
24 | pub fn from_data(data: &[u8]) -> Option<Self> { | 24 | pub fn from_data(data: &[u8]) -> Option<Self> { |
25 | const PREFIX: &'static str = "fn main(){\n\t"; | ||
26 | const SUFFIX: &'static str = "\n}"; | ||
27 | |||
25 | let data = str::from_utf8(data).ok()?; | 28 | let data = str::from_utf8(data).ok()?; |
26 | let mut lines = data.lines(); | 29 | let mut lines = data.lines(); |
27 | let delete_start = usize::from_str(lines.next()?).ok()?; | 30 | let delete_start = usize::from_str(lines.next()?).ok()? + PREFIX.len(); |
28 | let delete_len = usize::from_str(lines.next()?).ok()?; | 31 | let delete_len = usize::from_str(lines.next()?).ok()?; |
29 | let insert = lines.next()?.to_string(); | 32 | let insert = lines.next()?.to_string(); |
30 | let text = lines.collect::<Vec<_>>().join("\n"); | 33 | let text = lines.collect::<Vec<_>>().join("\n"); |
34 | let text = format!("{}{}{}", PREFIX, text, SUFFIX); | ||
31 | text.get(delete_start..delete_start.checked_add(delete_len)?)?; // make sure delete is a valid range | 35 | text.get(delete_start..delete_start.checked_add(delete_len)?)?; // make sure delete is a valid range |
32 | let delete = TextRange::offset_len( | 36 | let delete = TextRange::offset_len( |
33 | TextUnit::from_usize(delete_start), | 37 | TextUnit::from_usize(delete_start), |