2018-11-13 02:15:04 +08:00
|
|
|
//===- unittest/Format/FormatTestTableGen.cpp -----------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-11-13 02:15:04 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#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");
|
|
|
|
}
|
|
|
|
|
[clang-format][TableGen] Don't add spaces around items in square braces.
Summary:
clang-formatting wants to add spaces around items in square braces, e.g. [1, 2] -> [ 1, 2 ]. Based on a quick check [1], it seems like most cases are using the [1, 2] format, so make that the consistent one.
[1] in llvm `.td` files, the regex `\[[^ ]` (bracket followed by not-a-space) shows up ~400 times, but `\[\s[^ ]` (bracket followed by one space and one not-a-space) shows up ~40 times => ~90% uses this format.
Reviewers: djasper, krasimir, MyDeveloperDay
Reviewed By: MyDeveloperDay
Subscribers: MyDeveloperDay, arphaman, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D55964
llvm-svn: 355158
2019-03-01 08:12:18 +08:00
|
|
|
TEST_F(FormatTestTableGen, NoSpacesInSquareBracketLists) {
|
|
|
|
verifyFormat("def flag : Flag<[\"-\", \"--\"], \"foo\">;\n");
|
|
|
|
}
|
|
|
|
|
2018-11-13 02:15:04 +08:00
|
|
|
} // namespace format
|
|
|
|
} // end namespace clang
|