From d5dea456ff24e27776f60e5c65297aa3444d90f6 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Fri, 12 Jul 2024 19:34:13 +0200 Subject: [PATCH] Fix stripping of trailing `;` in listlike --- src/runestone.jl | 6 ++++++ test/runtests.jl | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/runestone.jl b/src/runestone.jl index 66e0d19..06c9f90 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -612,7 +612,13 @@ function spaces_in_listlike(ctx::Context, node::Node) end else # Nothing in the parameter node needed, overwrite it fully + any_kid_changed = true replace_bytes!(ctx, "", span(kid′)) + if any_kid_changed + if kids′ === kids + kids′ = kids[1:(i - 1)] + end + end end else # TODO: Tag for requiring trailing comma. diff --git a/test/runtests.jl b/test/runtests.jl index 58daafe..53b9691 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -264,9 +264,10 @@ end @test format_string("# a\n$(a)$(sp),\n# b\n$(b)") == "# a\n$(a),\n # b\n $(b)" end - # Single item + # Single item with trailing `,` and `;` @test format_string("($(sp)$(a)$(sp),$(sp))") == "($(a),)" - @test format_string("f($(sp)$(a)$(sp),$(sp))") == "f($(a))" + @test format_string("f($(sp)$(a)$(sp),$(sp))") == + format_string("f($(sp)$(a)$(sp);$(sp))") == "f($(a))" # Keyword arguments @test format_string("f($(sp)$(a)$(sp);$(sp)$(b)$(sp))") == format_string("f($(sp)$(a)$(sp);$(sp)$(b)$(sp),$(sp))") ==