mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Fix invalid multiline string output in REPL
If a PlainLine string contains a newline character, the REPL will print the string using a triple-quoted block string.
This commit is contained in:
parent
5e8faf64be
commit
1b2952bc70
2 changed files with 30 additions and 2 deletions
|
@ -476,7 +476,24 @@ pub fn fmt_str_literal<'buf>(buf: &mut Buf<'buf>, literal: StrLiteral, indent: u
|
||||||
buf.push('"');
|
buf.push('"');
|
||||||
match literal {
|
match literal {
|
||||||
PlainLine(string) => {
|
PlainLine(string) => {
|
||||||
buf.push_str_allow_spaces(string);
|
// When a PlainLine contains "\n" it is formatted as a block string using """
|
||||||
|
let mut lines = string.split('\n');
|
||||||
|
match (lines.next(), lines.next()) {
|
||||||
|
(Some(first), Some(second)) => {
|
||||||
|
buf.push_str("\"\"");
|
||||||
|
buf.newline();
|
||||||
|
|
||||||
|
for line in [first, second].into_iter().chain(lines) {
|
||||||
|
buf.indent(indent);
|
||||||
|
buf.push_str_allow_spaces(line);
|
||||||
|
buf.newline();
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.indent(indent);
|
||||||
|
buf.push_str("\"\"");
|
||||||
|
}
|
||||||
|
_ => buf.push_str_allow_spaces(string),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Line(segments) => {
|
Line(segments) => {
|
||||||
for seg in segments.iter() {
|
for seg in segments.iter() {
|
||||||
|
|
|
@ -542,7 +542,18 @@ fn four_element_record() {
|
||||||
#[test]
|
#[test]
|
||||||
fn multiline_string() {
|
fn multiline_string() {
|
||||||
// If a string contains newlines, format it as a multiline string in the output
|
// If a string contains newlines, format it as a multiline string in the output
|
||||||
expect_success(r#""\n\nhi!\n\n""#, "\"\n\nhi!\n\n\" : Str");
|
expect_success(
|
||||||
|
r#""\n\nhi!\n\n""#,
|
||||||
|
indoc!(
|
||||||
|
r#""""
|
||||||
|
|
||||||
|
|
||||||
|
hi!
|
||||||
|
|
||||||
|
|
||||||
|
""" : Str"#
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue