From c19f5b578ef50912d7b8cb45e118d71fe7e4c547 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Sat, 27 Jul 2024 00:24:30 +0200 Subject: [PATCH] Fix import/using lists with operators and macros --- src/runestone.jl | 3 ++- test/runtests.jl | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/runestone.jl b/src/runestone.jl index 4221897..c8de53e 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -1031,7 +1031,8 @@ function format_importpath(ctx::Context, node::Node) node′ = replace_first_leaf(node, spacebar) else # No whitespace, insert - @assert kind(first_leaf(node)) === K"Identifier" + @assert kind(first_leaf(node)) in KSet"Identifier @" || + JuliaSyntax.is_operator(first_leaf(node)) kids′ = copy(verified_kids(node)) pushfirst!(kids′, spacebar) replace_bytes!(ctx, " ", 0) diff --git a/test/runtests.jl b/test/runtests.jl index e40bf02..dd0cd04 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -804,9 +804,15 @@ end @test format_string("$(verb) A$(sp),\nB") == "$(verb) A,\n B" @test format_string("$(verb) \nA$(sp),\nB") == "$(verb)\n A,\n B" # Colon lists - @test format_string("$(verb) $(sp)A: $(sp)a") == "$(verb) A: a" - @test format_string("$(verb) $(sp)A: $(sp)a$(sp),$(sp)b") == "$(verb) A: a, b" - @test format_string("$(verb) $(sp)A: $(sp)a$(sp),\nb") == "$(verb) A: a,\n b" + for a in ("a", "@a", "*") + @test format_string("$(verb) $(sp)A: $(sp)$(a)") == "$(verb) A: $(a)" + for b in ("b", "@b", "*") + @test format_string("$(verb) $(sp)A: $(sp)$(a)$(sp),$(sp)$(b)") == + "$(verb) A: $(a), $(b)" + @test format_string("$(verb) $(sp)A: $(sp)$(a)$(sp),\n$(b)") == + "$(verb) A: $(a),\n $(b)" + end + end end for sp in ("", " ", " ", "\t") # `import A as a, ...`