mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Properly format characters with escape sequences
Ran into this just now
This commit is contained in:
parent
be2f143353
commit
3883867b5c
3 changed files with 31 additions and 1 deletions
|
@ -288,8 +288,17 @@ impl<'a> Formattable for Expr<'a> {
|
|||
buf.push_str(string)
|
||||
}
|
||||
SingleQuote(string) => {
|
||||
buf.indent(indent);
|
||||
buf.push('\'');
|
||||
buf.push_str(string);
|
||||
for c in string.chars() {
|
||||
if c == '"' {
|
||||
buf.push_char_literal('"')
|
||||
} else {
|
||||
for escaped in c.escape_default() {
|
||||
buf.push_char_literal(escaped);
|
||||
}
|
||||
}
|
||||
}
|
||||
buf.push('\'');
|
||||
}
|
||||
&NonBase10Int {
|
||||
|
|
|
@ -86,6 +86,12 @@ impl<'a> Buf<'a> {
|
|||
self.text.push_str(s);
|
||||
}
|
||||
|
||||
pub fn push_char_literal(&mut self, c: char) {
|
||||
self.flush_spaces();
|
||||
|
||||
self.text.push(c);
|
||||
}
|
||||
|
||||
pub fn spaces(&mut self, count: usize) {
|
||||
self.spaces_to_flush += count;
|
||||
}
|
||||
|
|
|
@ -5567,6 +5567,21 @@ mod test_fmt {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_chars() {
|
||||
expr_formats_same(indoc!(
|
||||
r#"
|
||||
' '
|
||||
"#
|
||||
));
|
||||
|
||||
expr_formats_same(indoc!(
|
||||
r#"
|
||||
'\n'
|
||||
"#
|
||||
));
|
||||
}
|
||||
|
||||
// this is a parse error atm
|
||||
// #[test]
|
||||
// fn multiline_apply() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue