Browse Source

Fix space-around-operator with non-space whitespace (#73)

pull/74/head
Fredrik Ekre 1 year ago committed by GitHub
parent
commit
797a1ba83a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      src/runestone.jl
  2. 3
      test/runtests.jl

4
src/runestone.jl

@ -189,9 +189,7 @@ function spaces_around_x(ctx::Context, node::Node, is_x::F, n_leaves_per_x::Int @@ -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

3
test/runtests.jl

@ -384,6 +384,9 @@ end @@ -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

Loading…
Cancel
Save