Repository: carbon-language/carbon-lang
File: toolchain/lex/tokenized_buffer_test.cpp (C++)

Code before:
}

TEST_F(LexerTest, IndentedComments) {
  for (int indent = 0; indent < 40; ++indent) {
    SCOPED_TRACE(llvm::formatv("Indent: {0}", indent));

    std::string source;
    llvm::raw_string_ostream source_stream(source);
    source_stream.indent(indent);
    source_stream << "// Comment\n";

    auto& buffer = compile_helper_.GetTokenizedBuffer(source);
    ASSERT_FALSE(buffer.has_errors());
    EXPECT_THAT(buffer.comments_size(), Eq(1));

    std::string simd_source =
        source +
        "\"Add a bunch of padding so that SIMD logic shouldn't hit EOF\"";
    auto& simd_buffer = compile_helper_.GetTokenizedBuffer(simd_source);
    ASSERT_FALSE(simd_buffer.has_errors());
    EXPECT_THAT(simd_buffer.comments_size(), Eq(1));
  }
}

TEST_F(LexerTest, MultipleComments) {
  constexpr char Format[] = R"(
{0}
  {1}

{2}
                                                              {3}

'''This is a string, not a comment. The next comment will stop SIMD due to being
   too close to the EOF.
   '''

{4}
x
)";
  constexpr llvm::StringLiteral Comments[] = {
      // NOLINTNEXTLINE(bugprone-suspicious-missing-comma)
      "// This comment should be possible to parse with SIMD.\n"
      "// This one too.\n",
      "// This one as well, though it's a different indent.\n"
      "        // And mixes indent.\n"
      "   // And mixes indent more.\n",
      "// This is one comment:\n"
      "//Invalid\n"
      "// Valid\n"
      "//Invalid\n"
      "//\n"

Review comment (suggestion):
Specifically for `StringLiteral`, I think we should fix it to have a `c_str()` method. Would it make sense to disable the tidy until that lands in LLVM and we pull it back in?

I agree with you that this seems like a net negative change.

Code after:
}

TEST_F(LexerTest, IndentedComments) {
  for (int indent = 0; indent < 40; ++indent) {
    SCOPED_TRACE(llvm::formatv("Indent: {0}", indent));

    std::string source;
    llvm::raw_string_ostream source_stream(source);
    source_stream.indent(indent);
    source_stream << "// Comment\n";

    auto& buffer = compile_helper_.GetTokenizedBuffer(source);
    ASSERT_FALSE(buffer.has_errors());
    EXPECT_THAT(buffer.comments_size(), Eq(1));

    std::string simd_source =
        source +
        "\"Add a bunch of padding so that SIMD logic shouldn't hit EOF\"";
    auto& simd_buffer = compile_helper_.GetTokenizedBuffer(simd_source);
    ASSERT_FALSE(simd_buffer.has_errors());
    EXPECT_THAT(simd_buffer.comments_size(), Eq(1));
  }
}

TEST_F(LexerTest, MultipleComments) {
  // TODO: Switch format to `llvm::StringLiteral` if
  // `llvm::StringLiteral::c_str` is added.
  constexpr char Format[] = R"(
{0}
  {1}

{2}
                                                              {3}

'''This is a string, not a comment. The next comment will stop SIMD due to being
   too close to the EOF.
   '''

{4}
x
)";
  constexpr llvm::StringLiteral Comments[] = {
      // NOLINTNEXTLINE(bugprone-suspicious-missing-comma)
      "// This comment should be possible to parse with SIMD.\n"
      "// This one too.\n",
      "// This one as well, though it's a different indent.\n"
      "        // And mixes indent.\n"
      "   // And mixes indent more.\n",
      "// This is one comment:\n"
      "//Invalid\n"
      "// Valid\n"