1 //===- unittest/Format/FormatTestTableGen.cpp -----------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "FormatTestUtils.h" 11 #include "clang/Format/Format.h" 12 #include "llvm/Support/Debug.h" 13 #include "gtest/gtest.h" 14 15 #define DEBUG_TYPE "format-test" 16 17 namespace clang { 18 namespace format { 19 20 class FormatTestTableGen : public ::testing::Test { 21 protected: 22 static std::string format(llvm::StringRef Code, unsigned Offset, 23 unsigned Length, const FormatStyle &Style) { 24 LLVM_DEBUG(llvm::errs() << "---\n"); 25 LLVM_DEBUG(llvm::errs() << Code << "\n\n"); 26 std::vector<tooling::Range> Ranges(1, tooling::Range(Offset, Length)); 27 tooling::Replacements Replaces = reformat(Style, Code, Ranges); 28 auto Result = applyAllReplacements(Code, Replaces); 29 EXPECT_TRUE(static_cast<bool>(Result)); 30 LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n"); 31 return *Result; 32 } 33 34 static std::string format(llvm::StringRef Code) { 35 FormatStyle Style = getGoogleStyle(FormatStyle::LK_TableGen); 36 Style.ColumnLimit = 60; // To make writing tests easier. 37 return format(Code, 0, Code.size(), Style); 38 } 39 40 static void verifyFormat(llvm::StringRef Code) { 41 EXPECT_EQ(Code.str(), format(Code)) << "Expected code is not stable"; 42 EXPECT_EQ(Code.str(), format(test::messUp(Code))); 43 } 44 }; 45 46 TEST_F(FormatTestTableGen, FormatStringBreak) { 47 verifyFormat("include \"OptParser.td\"\n" 48 "def flag : Flag<\"--foo\">,\n" 49 " HelpText<\n" 50 " \"This is a very, very, very, very, \"\n" 51 " \"very, very, very, very, very, very, \"\n" 52 " \"very long help string\">;\n"); 53 } 54 55 } // namespace format 56 } // end namespace clang 57