diff --git a/src/runestone.jl b/src/runestone.jl index 671b3a6..533e523 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -1272,7 +1272,7 @@ function indent_paren(ctx::Context, node::Node) end function indent_braces(ctx::Context, node::Node) - @assert kind(node) === K"braces" + @assert kind(node) in KSet"curly braces bracescat" kids = verified_kids(node) opening_brace_idx = findfirst(x -> kind(x) === K"{", kids)::Int closing_brace_idx = findnext(x -> kind(x) === K"}", kids, opening_brace_idx + 1)::Int @@ -1600,7 +1600,7 @@ function insert_delete_mark_newlines(ctx::Context, node::Node) return indent_struct(ctx, node) elseif kind(node) === K"parens" return indent_parens(ctx, node) - elseif kind(node) === K"braces" + elseif kind(node) in KSet"curly braces bracescat" return indent_braces(ctx, node) elseif kind(node) in KSet"|| &&" return indent_short_circuit(ctx, node) diff --git a/test/runtests.jl b/test/runtests.jl index e9c567c..923bbe4 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -260,7 +260,8 @@ end @test format_string("$(x){$(sp)$(a)$(sp),$(sp)$(b)$(sp)}") == "$(x){$(a), $(b)}" @test format_string("$(x){$(sp)$(a)$(sp);$(sp)$(b)$(sp)}") == "$(x){$(a); $(b)}" @test format_string("$(x){$(sp)$(a)$(sp);$(sp)$(b)$(sp)}") == "$(x){$(a); $(b)}" - @test format_string("$(x){\n$(sp)$(a)$(sp);$(sp)$(b)$(sp)\n}") == "$(x){\n$(a); $(b)$(tr)\n}" + @test format_string("$(x){\n$(sp)$(a)$(sp);$(sp)$(b)$(sp)\n}") == + "$(x){\n $(a); $(b)$(tr)\n}" end end @@ -542,10 +543,21 @@ end # comparison @test format_string("a == b ==\n$(sp)c") == "a == b ==\n c" @test format_string("a <= b >=\n$(sp)c") == "a <= b >=\n c" - # curly braces - @test format_string("{a,\n$(sp)b}") == "{a,\n b}" - @test format_string("{a,\n$(sp)b\n$(sp)}") == - format_string("{a,\n$(sp)b,\n$(sp)}") == "{a,\n b,\n}" - @test format_string("{\n$(sp)a,\n$(sp)b,\n$(sp)}") == "{\n a,\n b,\n}" + + # curly, braces, bracescat + for x in ("", "X") + tr = x == "" ? "" : "," + @test format_string("$(x){a,\n$(sp)b}") == "$(x){a,\n b}" + @test format_string("$(x){a,\n$(sp)b\n$(sp)}") == + format_string("$(x){a,\n$(sp)b,\n$(sp)}") == + "$(x){a,\n b,\n}" + @test format_string("$(x){a;\n$(sp)b\n$(sp)}") == "$(x){a;\n b$(tr)\n}" + @test format_string("$(x){\n$(sp)a,\n$(sp)b\n$(sp)}") == + format_string("$(x){\n$(sp)a,\n$(sp)b,\n$(sp)}") == + "$(x){\n a,\n b,\n}" + @test format_string("$(x){\n$(sp)a;\n$(sp)b\n$(sp)}") == + "$(x){\n a;\n b$(tr)\n}" + end + end end