Browse Source

Fix indent of while-end with K"block" as conditions

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

3
src/runestone.jl

@ -1976,7 +1976,8 @@ function indent_loop(ctx::Context, node::Node)
kids[for_idx] = add_tag(kids[for_idx], TAG_INDENT) kids[for_idx] = add_tag(kids[for_idx], TAG_INDENT)
any_kid_changed = true any_kid_changed = true
end end
block_idx = findnext(x -> kind(x) === K"block", kids, for_idx + 1)::Int # findlast because the condition can also be a block
block_idx = findlast(x -> kind(x) === K"block", kids)::Int
block_node′ = indent_block(ctx, kids[block_idx]) block_node′ = indent_block(ctx, kids[block_idx])
if block_node′ !== nothing if block_node′ !== nothing
kids[block_idx] = block_node′ kids[block_idx] = block_node′

2
test/runtests.jl

@ -538,6 +538,8 @@ end
@test format_string("for i in I, j in J\n$(sp)x\n$(sp)end") == "for i in I, j in J\n x\nend" @test format_string("for i in I, j in J\n$(sp)x\n$(sp)end") == "for i in I, j in J\n x\nend"
# while-end # while-end
@test format_string("while x\n$(sp)y\n$(sp)end") == "while x\n y\nend" @test format_string("while x\n$(sp)y\n$(sp)end") == "while x\n y\nend"
@test format_string("while (x = 1; x == 1)\n$(sp)y\n$(sp)end") ==
"while (x = 1; x == 1)\n y\nend"
# try-catch-end # try-catch-end
@test format_string("try\n$(sp)x\n$(sp)catch\n$(sp)y\n$(sp)end") == @test format_string("try\n$(sp)x\n$(sp)catch\n$(sp)y\n$(sp)end") ==
"try\n x\ncatch\n y\nend" "try\n x\ncatch\n y\nend"

Loading…
Cancel
Save