From 4d2c0fd041cf712ea5325ce761693fc523eb521e Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Sun, 28 Jul 2024 23:11:10 +0200 Subject: [PATCH] Fix list spacing in K"braces" with K"parameters" --- src/runestone.jl | 4 ++-- test/runtests.jl | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/runestone.jl b/src/runestone.jl index 4ccbd8d..4597992 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -320,7 +320,7 @@ function spaces_in_listlike(ctx::Context, node::Node) end if kind(node) === K"parameters" # Note that some of these are not valid Julia syntax but still parse - @assert ctx.lineage_kinds[end] in KSet"tuple call dotcall macrocall curly vect ref" + @assert ctx.lineage_kinds[end] in KSet"tuple call dotcall macrocall curly vect ref braces" end @assert !is_leaf(node) @@ -602,7 +602,7 @@ function spaces_in_listlike(ctx::Context, node::Node) any_kid_changed && push!(kids′, kid′) elseif kind(kid′) === K"parameters" # Note that some of these are not valid Julia syntax still parse - @assert kind(node) in KSet"call dotcall macrocall curly tuple vect ref" + @assert kind(node) in KSet"call dotcall macrocall curly tuple vect ref braces" if kind(first_leaf(kid′)) === K"Whitespace" # Delete the whitespace leaf kid_ws = first_leaf(kid′) diff --git a/test/runtests.jl b/test/runtests.jl index 2676908..8f290e2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -318,15 +318,19 @@ end @test format_string("($(sp);$(sp))") == "(;)" @test format_string("($(sp); #= a =#$(sp))") == "(; #= a =#)" end - # Curly (not as extensive testing as tuple/call/dotcall above but the code path is the - # same) + # KSet"curly braces bracescat" (not as extensive testing as tuple/call/dotcall above but + # the code path is the same) for x in ("", "X"), sp in ("", " ", " "), a in ("A", "<:B", "C <: D"), b in ("E", "<:F", "G <: H") tr = x == "" ? "" : "," @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){$(sp)$(a)$(sp),$(sp)$(a)$(sp);$(sp)$(b)$(sp)}") == + "$(x){$(a), $(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)$(a)$(sp);$(sp)$(b)$(sp)\n}") == + "$(x){\n $(a), $(a); $(b),\n}" end # Trailing `;` in paren-block @test format_string("(a = A;)") == "(a = A)"