diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:04:05 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:04:05 +0000 |
commit | 676fbe8105eeb6ff4bb2ed261cb212fcfdbe7b63 (patch) | |
tree | 02a1ac369cb734d0abfa5000dd86e5b7797e6a74 /unittests/Format/FormatTestTableGen.cpp | |
parent | c7e70c433efc6953dc3888b9fbf9f3512d7da2b0 (diff) |
Diffstat (limited to 'unittests/Format/FormatTestTableGen.cpp')
-rw-r--r-- | unittests/Format/FormatTestTableGen.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/unittests/Format/FormatTestTableGen.cpp b/unittests/Format/FormatTestTableGen.cpp new file mode 100644 index 0000000000000..820ea783cc9c8 --- /dev/null +++ b/unittests/Format/FormatTestTableGen.cpp @@ -0,0 +1,56 @@ +//===- unittest/Format/FormatTestTableGen.cpp -----------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "FormatTestUtils.h" +#include "clang/Format/Format.h" +#include "llvm/Support/Debug.h" +#include "gtest/gtest.h" + +#define DEBUG_TYPE "format-test" + +namespace clang { +namespace format { + +class FormatTestTableGen : public ::testing::Test { +protected: + static std::string format(llvm::StringRef Code, unsigned Offset, + unsigned Length, const FormatStyle &Style) { + LLVM_DEBUG(llvm::errs() << "---\n"); + LLVM_DEBUG(llvm::errs() << Code << "\n\n"); + std::vector<tooling::Range> Ranges(1, tooling::Range(Offset, Length)); + tooling::Replacements Replaces = reformat(Style, Code, Ranges); + auto Result = applyAllReplacements(Code, Replaces); + EXPECT_TRUE(static_cast<bool>(Result)); + LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n"); + return *Result; + } + + static std::string format(llvm::StringRef Code) { + FormatStyle Style = getGoogleStyle(FormatStyle::LK_TableGen); + Style.ColumnLimit = 60; // To make writing tests easier. + return format(Code, 0, Code.size(), Style); + } + + static void verifyFormat(llvm::StringRef Code) { + EXPECT_EQ(Code.str(), format(Code)) << "Expected code is not stable"; + EXPECT_EQ(Code.str(), format(test::messUp(Code))); + } +}; + +TEST_F(FormatTestTableGen, FormatStringBreak) { + verifyFormat("include \"OptParser.td\"\n" + "def flag : Flag<\"--foo\">,\n" + " HelpText<\n" + " \"This is a very, very, very, very, \"\n" + " \"very, very, very, very, very, very, \"\n" + " \"very long help string\">;\n"); +} + +} // namespace format +} // end namespace clang |