diff --git a/src/runestone.jl b/src/runestone.jl index 9bbd34d..7629541 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -283,5 +283,8 @@ function spaces_around_assignments(ctx::Context, node::JuliaSyntax.GreenNode) if !(is_assignment(node) && !JuliaSyntax.is_trivia(node)) return nothing end - return spaces_around_x(ctx, node, is_assignment) + # for-loop nodes are of kind K"=" even when `in` is used so we need to + # include K"in" in the predicate too. + is_x = x -> is_assignment(x) || JuliaSyntax.kind(x) === K"in" + return spaces_around_x(ctx, node, is_x) end diff --git a/test/runtests.jl b/test/runtests.jl index d612e3d..147dda8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -136,4 +136,9 @@ end @test format_string("a =+ c") == "a = + c" # Short form function definitions @test format_string("sin(π)=cos(pi)") == "sin(π) = cos(pi)" + # For loop nodes are assignment, even when using `in` + @test format_string("for i=1:10\nend\n") == "for i = 1 : 10\nend\n" + @test format_string("for i =1:10\nend\n") == "for i = 1 : 10\nend\n" + @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