Skip to content

Commit

Permalink
Whitespace around <: and >:
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed May 26, 2024
1 parent 8e13c29 commit 0098719
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/runestone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,12 @@ end
function spaces_around_operators(ctx::Context, node::JuliaSyntax.GreenNode)
if !(
is_infix_op_call(node) ||
(JuliaSyntax.kind(node) in KSet"<: >:" && !is_leaf(node)) ||
(JuliaSyntax.kind(node) === K"comparison" && !JuliaSyntax.is_trivia(node))
)
return nothing
end
@assert JuliaSyntax.kind(node) in KSet"call comparison"
@assert JuliaSyntax.kind(node) in KSet"call comparison <: >:"
is_x = x -> is_operator_leaf(x) || is_comparison_leaf(x)
return spaces_around_x(ctx, node, is_x)
end
Expand Down
17 changes: 17 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,20 @@ end
@test format_string("for i = 1:10\nend\n") == "for i = 1 : 10\nend\n"
@test format_string("for i in 1:10\nend\n") == "for i in 1 : 10\nend\n"
end

@testset "whitespace around <: and >:, no whitespace around ::" begin
# K"::"
@test format_string("a::T") == "a::T"
@test format_string("a::T::S") == "a::T::S"
@test_broken format_string("a :: T") == "a::T" # TODO: Eliminate spaces instead
# K"<:" and K">:"
@test format_string("a<:T") == "a <: T"
@test format_string("a>:T") == "a >: T"
@test format_string("a <: T") == "a <: T"
@test format_string("a >: T") == "a >: T"
# K"comparison" for chains
@test format_string("a<:T<:S") == "a <: T <: S"
@test format_string("a>:T>:S") == "a >: T >: S"
@test format_string("a <: T <: S") == "a <: T <: S"
@test format_string("a >: T >: S") == "a >: T >: S"
end

0 comments on commit 0098719

Please sign in to comment.