diff --git a/src/runestone.jl b/src/runestone.jl index 7629541..a25c567 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 147dda8..9502282 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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