1 //===- unittest/Format/FormatTestTableGen.cpp -----------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "FormatTestUtils.h"
11 #include "clang/Format/Format.h"
12 #include "llvm/Support/Debug.h"
13 #include "gtest/gtest.h"
15 #define DEBUG_TYPE "format-test"
20 class FormatTestTableGen : public ::testing::Test {
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");
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);
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)));
46 TEST_F(FormatTestTableGen, FormatStringBreak) {
47 verifyFormat("include \"OptParser.td\"\n"
48 "def flag : Flag<\"--foo\">,\n"
50 " \"This is a very, very, very, very, \"\n"
51 " \"very, very, very, very, very, very, \"\n"
52 " \"very long help string\">;\n");
56 } // end namespace clang