const char FirstCommentChar = Lines[i][IndentPrefix.size()];
const unsigned FirstCharByteSize =
encoding::getCodePointNumBytes(FirstCommentChar, Encoding);
- return encoding::columnWidth(
- Lines[i].substr(IndentPrefix.size(), FirstCharByteSize),
- Encoding) == 1 &&
- (FirstCommentChar == '\\' || isPunctuation(FirstCommentChar) ||
- isHorizontalWhitespace(FirstCommentChar));
+ if (encoding::columnWidth(
+ Lines[i].substr(IndentPrefix.size(), FirstCharByteSize),
+ Encoding) != 1)
+ return false;
+ if (FirstCommentChar == '#')
+ return false;
+ return FirstCommentChar == '\\' || isPunctuation(FirstCommentChar) ||
+ isHorizontalWhitespace(FirstCommentChar);
};
// On the first line of the comment section we calculate how many spaces
"// line 2\n"
"void f() {}\n");
+ EXPECT_EQ("// comment\n", format("//comment\n"));
+ EXPECT_EQ("// #comment\n", format("//#comment\n"));
+
EXPECT_EQ("// comment\n"
"// clang-format on\n",
format("//comment\n"
format(NoTextInComment, Style));
Style.SpacesInLineCommentPrefix.Minimum = 0;
+ EXPECT_EQ("//#comment", format("//#comment", Style));
EXPECT_EQ("//\n"
"\n"
"void foo() { //\n"
format(NoTextInComment, Style));
Style.SpacesInLineCommentPrefix.Minimum = 5;
+ EXPECT_EQ("// #comment", format("//#comment", Style));
EXPECT_EQ("//\n"
"\n"
"void foo() { //\n"
format(Code, Style));
Style.SpacesInLineCommentPrefix = {0, 0};
+ EXPECT_EQ("//#comment", format("// #comment", Style));
EXPECT_EQ("//Free comment without space\n"
"\n"
"//Free comment with 3 spaces\n"