Index: clang/unittests/Format/FormatTestRawStrings.cpp =================================================================== --- clang/unittests/Format/FormatTestRawStrings.cpp +++ clang/unittests/Format/FormatTestRawStrings.cpp @@ -75,6 +75,31 @@ return Style; } + FormatStyle getRawStringPbStyleSeparateSection() { + constexpr const char *FormatStr = R"format(--- +BasedOnStyle: LLVM +ColumnLimit: 40 +RawStringFormats: + - Language: TextProto + Delimiters: + - 'pb' + BasedOnStyle: google +--- +Language: TextProto +# Don't set any options. +... +)format"; + llvm::MemoryBufferRef ConfigBuffer(FormatStr, "ClangFormatConfig"); + FormatStyle Style = {}; + Style.Language = FormatStyle::LK_Cpp; + if (auto Err = parseConfiguration(ConfigBuffer, &Style)) { + llvm::dbgs() << Err.value(); + llvm::dbgs() << Err.message(); + assert(Err); + } + return Style; + } + FormatStyle getRawStringLLVMCppStyleBasedOn(std::string BasedOnStyle) { FormatStyle Style = getLLVMStyle(); Style.RawStringFormats = { @@ -164,6 +189,18 @@ getRawStringPbStyleWithColumns(40))); } +// Currently a bug in how configs are processed: +// See: https://github.com/llvm/llvm-project/issues/62871 +TEST_F(FormatTestRawStrings, + DISABLED_FormatsCorrectlyWhenTextProtoIsInOwnSection) { + // TextProto formatting works when in a RawString. + expect_eq(R"test( +t = R"pb(item: 1)pb";)test", + format(R"test( +t = R"pb(item:1)pb";)test", + getRawStringPbStyleSeparateSection())); +} + TEST_F(FormatTestRawStrings, RespectsClangFormatOff) { expect_eq(R"test( // clang-format off