From c60ec02d75a7cfa57a5a2b1e2256b70224deb531 Mon Sep 17 00:00:00 2001 From: pcpthm Date: Fri, 22 Mar 2019 04:11:21 +0900 Subject: Use template text to improve reparse fuzzing --- crates/ra_syntax/src/fuzz.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'crates/ra_syntax') 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 { impl CheckReparse { pub fn from_data(data: &[u8]) -> Option { + const PREFIX: &'static str = "fn main(){\n\t"; + const SUFFIX: &'static str = "\n}"; + let data = str::from_utf8(data).ok()?; let mut lines = data.lines(); - let delete_start = usize::from_str(lines.next()?).ok()?; + let delete_start = usize::from_str(lines.next()?).ok()? + PREFIX.len(); let delete_len = usize::from_str(lines.next()?).ok()?; let insert = lines.next()?.to_string(); let text = lines.collect::>().join("\n"); + let text = format!("{}{}{}", PREFIX, text, SUFFIX); text.get(delete_start..delete_start.checked_add(delete_len)?)?; // make sure delete is a valid range let delete = TextRange::offset_len( TextUnit::from_usize(delete_start), -- cgit v1.2.3