Skip to content

Commit

Permalink
Fix formatting of for-loops with Unicode \in.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed May 27, 2024
1 parent b10a7f9 commit 5ddee14
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/runestone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ function spaces_around_assignments(ctx::Context, node::JuliaSyntax.GreenNode)
if !(is_assignment(node) && !JuliaSyntax.is_trivia(node))
return nothing
end
# 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"
# for-loop nodes are of kind K"=" even when `in` or `∈` is used so we need to
# include these kinds in the predicate too.
is_x = x -> is_assignment(x) || JuliaSyntax.kind(x) in KSet"in"
return spaces_around_x(ctx, node, is_x)
end

Expand Down
10 changes: 5 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ 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"
# For loop nodes are assignment, even when using `in` and `∈`
for op in ("in", "=", ""), sp in ("", " ", " ")
op == "in" && sp == "" && continue
@test format_string("for i$(sp)$(op)$(sp)1:10\nend\n") == "for i $(op) 1:10\nend\n"
end
end

@testset "whitespace around <: and >:, no whitespace around ::" begin
Expand Down

0 comments on commit 5ddee14

Please sign in to comment.