From e14aaa07f32dcfa581da5ee9aef0393b0e445eec Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Sat, 6 Jul 2024 13:27:03 +0200 Subject: [PATCH] Fix single line begin-end blocks TODO: Should probably require leading and trailing newlines in such blocks? --- src/runestone.jl | 7 ++++--- test/runtests.jl | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/runestone.jl b/src/runestone.jl index 0ba3c75..68cf1cc 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -1299,9 +1299,10 @@ function indent_begin(ctx::Context, node::Node, block_kind = K"begin") any_kid_changed = true end # Second node is the newline - ln_idx = 2 - ln_node = kids[ln_idx] - @assert is_leaf(ln_node) && kind(ln_node) === K"NewlineWs" + # TODO: Require newline? + # ln_idx = 2 + # ln_node = kids[ln_idx] + # @assert is_leaf(ln_node) && kind(ln_node) === K"NewlineWs" # After the NewlineWs node we skip over all kids until the end end_idx = findlast(x -> kind(x) === K"end", kids) @assert end_idx == lastindex(kids) # ?? diff --git a/test/runtests.jl b/test/runtests.jl index e1cc059..8b090d2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -567,8 +567,11 @@ end @test format_string("$(t)[a b\n$(sp)c d]") == "$(t)[\n a b\n c d\n]" @test format_string("$(t)[\n$(sp)a b\n$(sp)c d\n$(sp)]") == "$(t)[\n a b\n c d\n]" end + # Single line begin-end + @test format_string("begin x\n$(sp)end") == "begin x\nend" + @test format_string("begin x end") == "begin x end" + @test format_string("begin\n x end") == "begin\n x end" end - end @testset "continuation/soft indentation" begin