mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
Fix a bunch of bugs found in fuzzing
This commit is contained in:
parent
5cd38c969f
commit
f7a5f06e5b
217 changed files with 5745 additions and 994 deletions
|
@ -18,12 +18,14 @@ pub struct Buf<'a> {
|
|||
spaces_to_flush: usize,
|
||||
newlines_to_flush: usize,
|
||||
beginning_of_line: bool,
|
||||
line_indent: u16,
|
||||
}
|
||||
|
||||
impl<'a> Buf<'a> {
|
||||
pub fn new_in(arena: &'a Bump) -> Buf<'a> {
|
||||
Buf {
|
||||
text: String::new_in(arena),
|
||||
line_indent: 0,
|
||||
spaces_to_flush: 0,
|
||||
newlines_to_flush: 0,
|
||||
beginning_of_line: true,
|
||||
|
@ -40,11 +42,18 @@ impl<'a> Buf<'a> {
|
|||
|
||||
pub fn indent(&mut self, indent: u16) {
|
||||
if self.beginning_of_line {
|
||||
self.line_indent = indent;
|
||||
self.spaces_to_flush = indent as usize;
|
||||
}
|
||||
self.beginning_of_line = false;
|
||||
}
|
||||
|
||||
pub fn cur_line_indent(&self) -> u16 {
|
||||
debug_assert!(!self.beginning_of_line, "cur_line_indent before indent");
|
||||
self.line_indent
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn push(&mut self, ch: char) {
|
||||
debug_assert!(!self.beginning_of_line);
|
||||
debug_assert!(
|
||||
|
@ -61,6 +70,7 @@ impl<'a> Buf<'a> {
|
|||
self.text.push(ch);
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn push_str_allow_spaces(&mut self, s: &str) {
|
||||
debug_assert!(
|
||||
!self.beginning_of_line,
|
||||
|
@ -73,6 +83,7 @@ impl<'a> Buf<'a> {
|
|||
self.text.push_str(s);
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn push_str(&mut self, s: &str) {
|
||||
debug_assert!(
|
||||
!self.beginning_of_line,
|
||||
|
@ -129,6 +140,12 @@ impl<'a> Buf<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn ensure_ends_with_whitespace(&mut self) {
|
||||
if !self.text.is_empty() && self.newlines_to_flush == 0 && self.spaces_to_flush == 0 {
|
||||
self.spaces_to_flush = 1;
|
||||
}
|
||||
}
|
||||
|
||||
fn flush_spaces(&mut self) {
|
||||
for _ in 0..self.newlines_to_flush {
|
||||
self.text.push('\n');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue