Browse Source

Fix a bug with newline instead of space after `where`.

pull/19/head
Fredrik Ekre 1 year ago
parent
commit
32c3219566
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  1. 8
      src/runestone.jl
  2. 2
      test/runtests.jl

8
src/runestone.jl

@ -839,8 +839,12 @@ function spaces_around_keywords(ctx::Context, node::Node)
any_changes && push!(kids′, kid) any_changes && push!(kids′, kid)
end end
elseif state === :looking_for_space elseif state === :looking_for_space
if kind(kid) === K"Whitespace" && span(kid) == 1 if (kind(kid) === K"Whitespace" && span(kid) == 1) ||
# TODO: Include NewlineWs here? 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) accept_node!(ctx, kid)
any_changes && push!(kids′, kid) any_changes && push!(kids′, kid)
elseif kind(kid) === K"Whitespace" elseif kind(kid) === K"Whitespace"

2
test/runtests.jl

@ -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("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$(sp)x\ny\nend") == "f() do x\n y\nend"
@test format_string("f()$(sp)do\ny\nend") == "f() do\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 end
@test format_string("try\nerror()\ncatch\nend") == "try\n error()\ncatch\nend" @test format_string("try\nerror()\ncatch\nend") == "try\n error()\ncatch\nend"
@test format_string("A where{T}") == "A where {T}" @test format_string("A where{T}") == "A where {T}"

Loading…
Cancel
Save