Browse Source

Fix edge case with multiline lists with only a comment and no items

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

9
src/runestone.jl

@ -2485,13 +2485,16 @@ function indent_listlike(
end end
# Kid just before the closing token should be a newline and it should be tagged with # Kid just before the closing token should be a newline and it should be tagged with
# pre-dedent. # pre-dedent.
if close_idx - 1 == open_idx + 1 if idx_after_leading_nl == close_idx
# Just a single kid which should then have both leading and trailing newline # Just a single kid which should then have both leading and trailing newline
if any_kid_changed if any_kid_changed
# Modify this kid again by popping from the list and backtrack the stream # Modify this kid again by popping from the list
kid = pop!(kids′) kid = pop!(kids′)
seek(ctx.fmt_io, position(ctx.fmt_io) - span(kid)) else
kid = kids[close_idx - 1]
end end
# Backtrack the stream
seek(ctx.fmt_io, position(ctx.fmt_io) - span(kid))
else else
kid = kids[close_idx - 1] kid = kids[close_idx - 1]
end end

3
test/runtests.jl

@ -397,6 +397,9 @@ end
# Non space whitespace (TODO: Not sure if a JuliaSyntax bug or not?) # Non space whitespace (TODO: Not sure if a JuliaSyntax bug or not?)
@test format_string(String(UInt8[0x61, 0x20, 0x3d, 0x3d, 0x20, 0xc2, 0xa0, 0x62, 0x3a, 0x63])) == @test format_string(String(UInt8[0x61, 0x20, 0x3d, 0x3d, 0x20, 0xc2, 0xa0, 0x62, 0x3a, 0x63])) ==
"a == b:c" "a == b:c"
# Edge case with comment and no items
@test format_string("[# a\n]") == "[# a\n]"
@test format_string("[ # a\n]") == "[ # a\n]"
end end
@testset "whitespace around ->" begin @testset "whitespace around ->" begin

Loading…
Cancel
Save