blob: 0491624d2a09827d2351fb29266dc8bdaa11c66c [file] [edit]
/-!
Tests for the placement of comments around tokens that span several lines (multi-line string
literals, in particular).
The fallback comment insertion mechanism, which inserts comments into the rendered output rather
than into the document, must never place a comment within such a token; comments that would be
placed there are moved to the line before the token instead.
This also applies to a token that is on one line in the input and that the formatter breaks, such
as a string literal that does not fit on one line.
-/
def f (a b : String) : String := a ++ b
def g (a : String) : String := a
-- A comment after a token that is followed by a multi-line token on the same rendered line.
def afterTokenBeforeMultiLineToken :=
f "x" -- comment
"abc\
\ndef"
-- The same for a block comment.
def blockAfterTokenBeforeMultiLineToken :=
f "x" /- comment -/
"abc\
\ndef"
-- A comment after a multi-line token can stay on the token's last line.
def afterMultiLineToken :=
f
"abc\
\ndef" -- comment
"y"
-- Several multi-line tokens on the same line of the input.
def betweenMultiLineTokens :=
f
"abc\
\ndef"
("ghi\
\njkl") -- comment
-- A comment on its own line before a token that is rendered on a continuation line of a multi-line
-- token.
def beforeTokenOnContinuationLine :=
-- comment
(g "abc\
\ndef")
-- The same for a block comment.
def blockBeforeTokenOnContinuationLine :=
/- comment -/
(g "abc\
\ndef")
-- A comment group spanning several lines.
def multiLineCommentGroup :=
f "x" -- first
-- second
"abc\
\ndef"
-- A comment in an interpolation that starts on a continuation line of an interpolated string.
def inInterpolation (a : Nat) : String :=
/-
first
second
-/
s!"first {a} \
{Nat.succ a}"
-- A comment on its own line before a token that is rendered on the last line of a string literal
-- that the formatter breaks at `\n`.
def beforeTokenAfterBrokenString :=
-- comment
(g "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
-- The same for a block comment.
def blockBeforeTokenAfterBrokenString :=
/- comment -/
(g "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
-- The same for a string literal that the formatter breaks between two words.
def beforeTokenAfterFilledString :=
-- comment
["some words that fill the line some words that fill the line some words that fill the line some \
words"]
-- A comment after a token that is followed by a string literal that the formatter breaks.
def afterTokenBeforeBrokenString :=
f "x" -- comment
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
-- Comments in an interpolation of an interpolated string that the formatter breaks.
def inInterpolationOfBrokenString (name : String) (expected actual : Nat) : String :=
-- first
-- second
s!"{name}: expected {expected} framed responses in total for this connection, got {actual} in \
{actual + 1} bytes"