From 12535ab6cc74fa0a2cce9999373a2f631556b413 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Tue, 22 Oct 2024 13:17:39 +0200 Subject: [PATCH] Fix space-around-operator with non-space whitespace --- src/runestone.jl | 4 +--- test/runtests.jl | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/runestone.jl b/src/runestone.jl index 6a42d87..0f72f4d 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -189,9 +189,7 @@ function spaces_around_x(ctx::Context, node::Node, is_x::F, n_leaves_per_x::Int # Replace the whitespace node of the kid kid′ = replace_first_leaf(kid, ws) @assert span(kid′) == span(kid) - span(kid_ws) + 1 - bytes_to_skip = span(kid) - span(kid′) - @assert bytes_to_skip > 0 - replace_bytes!(ctx, "", bytes_to_skip) + replace_bytes!(ctx, " ", span(kid_ws)) accept_node!(ctx, kid′) any_changes = true if kids′ === kids diff --git a/test/runtests.jl b/test/runtests.jl index f66b755..9065eca 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -384,6 +384,9 @@ end @test format_string("(\na, x -> @m(x[i])\n)") == "(\n a, x -> @m(x[i]),\n)" # Weird cornercase where a trailing comma messes some cases up (don't recall...) @test format_string("{\n@f\n}") == "{\n @f\n}" + # Non space whitespace (TODO: Not sure if a JuliaSyntax bug or not?) + @test format_string(String(UInt8[0x61, 0x20, 0x3d, 0x3d, 0x20, 0xc2, 0xa0, 0x62, 0x3a, 0x63])) == + "a == b:c" end @testset "whitespace around ->" begin