Skip to content

Commit

Permalink
fix #604
Browse files Browse the repository at this point in the history
Do not join the single statement in a begin block if it's a macroblock,
i.e. a macrocall with whitespace separation such as "@foo a b".
  • Loading branch information
domluna committed Jan 7, 2023
1 parent 9092f29 commit ee47704
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/styles/sciml/pretty.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ function p_begin(ss::SciMLStyle, cst::CSTParser.EXPR, s::State)
else
stmts_idxs = 2:length(cst)-1
# Don't nest into multiple lines when there's only one statement
if length(stmts_idxs) == 1
# and it's not a macroblock.
if length(stmts_idxs) == 1 && !(cst[2].head === :macrocall && !is_closer(cst[2][end]))
add_node!(t, Whitespace(1), s)
add_node!(t, pretty(style, cst[2], s), s, join_lines = true)
add_node!(t, Whitespace(1), s)
Expand Down
17 changes: 17 additions & 0 deletions test/issues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,23 @@
@test format_text(s) == s_
end

@testset "604" begin
str = raw"""
begin @foo a end
"""
str_ = raw"""
begin
@foo a
end
"""
@test format_text(str, SciMLStyle()) == str_

str = raw"""
begin @foo(a) end
"""
@test format_text(str, SciMLStyle()) == str
end

@testset "613" begin
s = """
x = ```
Expand Down

0 comments on commit ee47704

Please sign in to comment.