Browse Source

Fix list spacing in K"braces" with K"parameters"

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

4
src/runestone.jl

@ -320,7 +320,7 @@ function spaces_in_listlike(ctx::Context, node::Node) @@ -320,7 +320,7 @@ function spaces_in_listlike(ctx::Context, node::Node)
end
if kind(node) === K"parameters"
# Note that some of these are not valid Julia syntax but still parse
@assert ctx.lineage_kinds[end] in KSet"tuple call dotcall macrocall curly vect ref"
@assert ctx.lineage_kinds[end] in KSet"tuple call dotcall macrocall curly vect ref braces"
end
@assert !is_leaf(node)
@ -602,7 +602,7 @@ function spaces_in_listlike(ctx::Context, node::Node) @@ -602,7 +602,7 @@ function spaces_in_listlike(ctx::Context, node::Node)
any_kid_changed && push!(kids′, kid′)
elseif kind(kid′) === K"parameters"
# Note that some of these are not valid Julia syntax still parse
@assert kind(node) in KSet"call dotcall macrocall curly tuple vect ref"
@assert kind(node) in KSet"call dotcall macrocall curly tuple vect ref braces"
if kind(first_leaf(kid′)) === K"Whitespace"
# Delete the whitespace leaf
kid_ws = first_leaf(kid′)

8
test/runtests.jl

@ -318,15 +318,19 @@ end @@ -318,15 +318,19 @@ end
@test format_string("($(sp);$(sp))") == "(;)"
@test format_string("($(sp); #= a =#$(sp))") == "(; #= a =#)"
end
# Curly (not as extensive testing as tuple/call/dotcall above but the code path is the
# same)
# KSet"curly braces bracescat" (not as extensive testing as tuple/call/dotcall above but
# the code path is the same)
for x in ("", "X"), sp in ("", " ", " "), a in ("A", "<:B", "C <: D"), b in ("E", "<:F", "G <: H")
tr = x == "" ? "" : ","
@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){$(sp)$(a)$(sp),$(sp)$(a)$(sp);$(sp)$(b)$(sp)}") ==
"$(x){$(a), $(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)$(a)$(sp);$(sp)$(b)$(sp)\n}") ==
"$(x){\n $(a), $(a); $(b),\n}"
end
# Trailing `;` in paren-block
@test format_string("(a = A;)") == "(a = A)"

Loading…
Cancel
Save