Skip to content

Commit

Permalink
Merge pull request #172 from notpeter/hanging_comment
Browse files Browse the repository at this point in the history
Fix: short comment following long comment close
  • Loading branch information
CppCXY authored May 18, 2024
2 parents 22e4509 + eb59d99 commit 025d898
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
9 changes: 8 additions & 1 deletion CodeFormatCore/src/Format/Analyzer/LineBreakAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,15 @@ void LineBreakAnalyzer::ComplexAnalyze(FormatState &f, const LuaSyntaxTree &t) {

} else {
switch (stmt.GetTokenKind(t)) {
case TK_SHORT_COMMENT:
case TK_LONG_COMMENT:
{
auto nextToken = stmt.GetNextToken(t).GetTokenKind(t);
if (nextToken == TK_SHORT_COMMENT) {
break;
}
// Fall through
}
case TK_SHORT_COMMENT:
case TK_SHEBANG: {
BreakAfter(stmt, t, style.line_space_after_comment);
break;
Expand Down
28 changes: 28 additions & 0 deletions Test/src/FormatResult_unitest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1147,3 +1147,31 @@ only_latin = {
}
)", style));
}

TEST(Format, issue_170) {
EXPECT_TRUE(TestHelper::TestFormatted(
R"(
--[[]]
)",
R"(
--[[]]
)"));
EXPECT_TRUE(TestHelper::TestFormatted(
R"(
--[[]]--
)",
R"(
--[[]] --
)"));
EXPECT_TRUE(TestHelper::TestFormatted(
R"(
--[[-----------
]]-------------
)",
R"(
--[[-----------
]] -------------
)"));
}

0 comments on commit 025d898

Please sign in to comment.