Skip to content

Commit

Permalink
Line continuation in curly and bracescat.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Jun 19, 2024
1 parent 4a63e66 commit 59ee9fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/runestone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ function indent_paren(ctx::Context, node::Node)
end

function indent_braces(ctx::Context, node::Node)
@assert kind(node) === K"braces"
@assert kind(node) in KSet"curly braces bracescat"
kids = verified_kids(node)
opening_brace_idx = findfirst(x -> kind(x) === K"{", kids)::Int
closing_brace_idx = findnext(x -> kind(x) === K"}", kids, opening_brace_idx + 1)::Int
Expand Down Expand Up @@ -1600,7 +1600,7 @@ function insert_delete_mark_newlines(ctx::Context, node::Node)
return indent_struct(ctx, node)
elseif kind(node) === K"parens"
return indent_parens(ctx, node)
elseif kind(node) === K"braces"
elseif kind(node) in KSet"curly braces bracescat"
return indent_braces(ctx, node)
elseif kind(node) in KSet"|| &&"
return indent_short_circuit(ctx, node)
Expand Down
24 changes: 18 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ end
@test format_string("$(x){$(sp)$(a)$(sp),$(sp)$(b)$(sp)}") == "$(x){$(a), $(b)}"
@test format_string("$(x){$(sp)$(a)$(sp);$(sp)$(b)$(sp)}") == "$(x){$(a); $(b)}"
@test format_string("$(x){$(sp)$(a)$(sp);$(sp)$(b)$(sp)}") == "$(x){$(a); $(b)}"
@test format_string("$(x){\n$(sp)$(a)$(sp);$(sp)$(b)$(sp)\n}") == "$(x){\n$(a); $(b)$(tr)\n}"
@test format_string("$(x){\n$(sp)$(a)$(sp);$(sp)$(b)$(sp)\n}") ==
"$(x){\n $(a); $(b)$(tr)\n}"
end
end

Expand Down Expand Up @@ -542,10 +543,21 @@ end
# comparison
@test format_string("a == b ==\n$(sp)c") == "a == b ==\n c"
@test format_string("a <= b >=\n$(sp)c") == "a <= b >=\n c"
# curly braces
@test format_string("{a,\n$(sp)b}") == "{a,\n b}"
@test format_string("{a,\n$(sp)b\n$(sp)}") ==
format_string("{a,\n$(sp)b,\n$(sp)}") == "{a,\n b,\n}"
@test format_string("{\n$(sp)a,\n$(sp)b,\n$(sp)}") == "{\n a,\n b,\n}"

# curly, braces, bracescat
for x in ("", "X")
tr = x == "" ? "" : ","
@test format_string("$(x){a,\n$(sp)b}") == "$(x){a,\n b}"
@test format_string("$(x){a,\n$(sp)b\n$(sp)}") ==
format_string("$(x){a,\n$(sp)b,\n$(sp)}") ==
"$(x){a,\n b,\n}"
@test format_string("$(x){a;\n$(sp)b\n$(sp)}") == "$(x){a;\n b$(tr)\n}"
@test format_string("$(x){\n$(sp)a,\n$(sp)b\n$(sp)}") ==
format_string("$(x){\n$(sp)a,\n$(sp)b,\n$(sp)}") ==
"$(x){\n a,\n b,\n}"
@test format_string("$(x){\n$(sp)a;\n$(sp)b\n$(sp)}") ==
"$(x){\n a;\n b$(tr)\n}"
end

end
end

0 comments on commit 59ee9fb

Please sign in to comment.