diff --git a/src/runestone.jl b/src/runestone.jl index 329e30d..c1a124b 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -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" diff --git a/test/runtests.jl b/test/runtests.jl index 9b7c88c..1bbe353 100644 --- a/test/runtests.jl +++ b/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("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}"