From 1ddcfac20a44611384bc507d7278a0ba2d4f22c9 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Sun, 23 Jun 2024 01:55:16 +0200 Subject: [PATCH] Fix a bug with newline instead of space after `where`. --- src/runestone.jl | 8 ++++++-- test/runtests.jl | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) 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}"