diff options
Diffstat (limited to 'crates')
-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), |