Skip to content

Commit

Permalink
Fix a bug with newline instead of space after where.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Jun 22, 2024
1 parent abfc1e5 commit 1ddcfac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/runestone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,12 @@ function spaces_around_keywords(ctx::Context, node::Node)
any_changes && push!(kids′, kid)
end
elseif state === :looking_for_space
if kind(kid) === K"Whitespace" && span(kid) == 1
# TODO: Include NewlineWs here?
if (kind(kid) === K"Whitespace" && span(kid) == 1) ||
kind(kid) === K"NewlineWs"
if kind(kid) === K"NewlineWs"
# Is a newline instead of a space accepted for any other case?
@assert kind(node) === K"where"
end
accept_node!(ctx, kid)
any_changes && push!(kids′, kid)
elseif kind(kid) === K"Whitespace"
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ end
@test format_string("A$(sp)where$(sp){T}$(sp)where$(sp){S}") == "A where {T} where {S}"
@test format_string("f()$(sp)do$(sp)x\ny\nend") == "f() do x\n y\nend"
@test format_string("f()$(sp)do\ny\nend") == "f() do\n y\nend"
# After `where` (anywhere else?) a newline can be used instead of a space
@test format_string("A$(sp)where$(sp)\n{A}") == "A where\n{A}"
end
@test format_string("try\nerror()\ncatch\nend") == "try\n error()\ncatch\nend"
@test format_string("A where{T}") == "A where {T}"
Expand Down

0 comments on commit 1ddcfac

Please sign in to comment.