Browse Source

Spaces around anonymous function heads (->), closes #7.

pull/19/head
Fredrik Ekre 2 years ago
parent
commit
0080cdfe20
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  1. 1
      src/Runic.jl
  2. 8
      src/runestone.jl
  3. 6
      test/runtests.jl

1
src/Runic.jl

@ -293,6 +293,7 @@ function format_node!(ctx::Context, node::Node)::Union{Node, Nothing, NullNode}
@return_something format_float_literals(ctx, node) @return_something format_float_literals(ctx, node)
@return_something spaces_around_operators(ctx, node) @return_something spaces_around_operators(ctx, node)
@return_something spaces_around_assignments(ctx, node) @return_something spaces_around_assignments(ctx, node)
@return_something spaces_around_anonymous_function(ctx, node)
@return_something no_spaces_around_colon_etc(ctx, node) @return_something no_spaces_around_colon_etc(ctx, node)
@return_something for_loop_use_in(ctx, node) @return_something for_loop_use_in(ctx, node)
@return_something four_space_indent(ctx, node) @return_something four_space_indent(ctx, node)

8
src/runestone.jl

@ -314,6 +314,14 @@ function spaces_around_assignments(ctx::Context, node::Node)
return spaces_around_x(ctx, node, is_x) return spaces_around_x(ctx, node, is_x)
end end
function spaces_around_anonymous_function(ctx::Context, node::Node)
if !(kind(node) === K"->" && !is_leaf(node))
return nothing
end
is_x = x -> kind(x) === K"->"
return spaces_around_x(ctx, node, is_x)
end
# Opposite of `spaces_around_x`: remove spaces around `x` # Opposite of `spaces_around_x`: remove spaces around `x`
function no_spaces_around_x(ctx::Context, node::Node, is_x::F) where F function no_spaces_around_x(ctx::Context, node::Node, is_x::F) where F
@assert !is_leaf(node) @assert !is_leaf(node)

6
test/runtests.jl

@ -198,6 +198,12 @@ end
end end
end end
@testset "whitespace around ->" begin
for sp in ("", " ", " ")
@test format_string("a$(sp)->$(sp)b") == "a -> b"
end
end
@testset "whitespace in comparison chains" begin @testset "whitespace in comparison chains" begin
for sp in ("", " ", " ") for sp in ("", " ", " ")
@test format_string("a$(sp)==$(sp)b") == "a == b" @test format_string("a$(sp)==$(sp)b") == "a == b"

Loading…
Cancel
Save