diff --git a/compiler/frontend/src/string_to_rcst/text.rs b/compiler/frontend/src/string_to_rcst/text.rs index 003963867..befeda729 100644 --- a/compiler/frontend/src/string_to_rcst/text.rs +++ b/compiler/frontend/src/string_to_rcst/text.rs @@ -294,8 +294,8 @@ mod test { closing_double_quote: DoubleQuote closing_single_quotes: "###); - // issue: https://github.com/candy-lang/candy/issues/1016 - assert_rich_ir_snapshot!(text("\"\n text\n\"", 0), @r###" + // https://github.com/candy-lang/candy/issues/1016 + assert_rich_ir_snapshot!(text("\"\n foo\n bar\n\"", 0), @r###" Remaining input: "" Parsed: Text: opening: TrailingWhitespace: @@ -305,18 +305,22 @@ mod test { whitespace: Newline "\n" Whitespace " " - Whitespace " " parts: + TextPart "foo" TrailingWhitespace: - child: TextPart "text" + child: TextNewline "\n" + whitespace: + Whitespace " " + TrailingWhitespace: + child: TextPart " bar" whitespace: Newline "\n" closing: ClosingText: closing_double_quote: DoubleQuote closing_single_quotes: "###); - // https://github.com/candy-lang/candy/issues/1016 - assert_rich_ir_snapshot!(text("\"\n foo\n bar\n\"", 0), @r###" + // issue: https://github.com/candy-lang/candy/issues/1016 + assert_rich_ir_snapshot!(text("\"\n text\n\"", 0), @r###" Remaining input: "" Parsed: Text: opening: TrailingWhitespace: @@ -327,21 +331,14 @@ mod test { Newline "\n" Whitespace " " parts: - TextPart "foo" - TrailingWhitespace: - child: TextNewline "\n" - whitespace: - Whitespace " " - Whitespace " " TrailingWhitespace: - child: TextPart "bar" + child: TextPart " text" whitespace: Newline "\n" closing: ClosingText: closing_double_quote: DoubleQuote closing_single_quotes: "###); - assert_rich_ir_snapshot!(text("\" foobar \"", 0), @r###" Remaining input: "" Parsed: Text: diff --git a/compiler/frontend/src/string_to_rcst/whitespace.rs b/compiler/frontend/src/string_to_rcst/whitespace.rs index 31814c095..ee2dc2619 100644 --- a/compiler/frontend/src/string_to_rcst/whitespace.rs +++ b/compiler/frontend/src/string_to_rcst/whitespace.rs @@ -141,7 +141,6 @@ pub fn whitespaces_and_newlines( new_parts.push(newline); is_sufficiently_indented = false; } - if let Some((new_new_input, whitespace)) = leading_indentation(new_input, indentation) { new_input = new_new_input; new_parts.push(whitespace); @@ -149,7 +148,8 @@ pub fn whitespaces_and_newlines( input = new_input; parts.append(&mut new_parts); is_sufficiently_indented = true; - } else if let Some((new_new_input, whitespace)) = single_line_whitespace(new_input) { + } + if let Some((new_new_input, whitespace)) = single_line_whitespace(new_input) { new_input = new_new_input; new_parts.push(whitespace); } @@ -231,16 +231,18 @@ mod test { assert_rich_ir_snapshot!( whitespaces_and_newlines("\n foo", 0, true), @r###" - Remaining input: " foo" + Remaining input: "foo" Parsed: Newline "\n" + Whitespace " " "### ); assert_rich_ir_snapshot!( whitespaces_and_newlines(" \n foo", 0, true), @r###" - Remaining input: " foo" + Remaining input: "foo" Parsed: Whitespace " " Newline "\n" + Whitespace " " "### ); assert_rich_ir_snapshot!(