Go to the documentation of this file.
13 #include "clang/Format/Format.h"
14 #include "clang/Tooling/Core/Replacement.h"
15 #include "llvm/Support/Error.h"
16 #include "gmock/gmock.h"
17 #include "gtest/gtest.h"
23 std::string afterTyped(llvm::StringRef CodeWithCursor,
24 llvm::StringRef Typed) {
25 Annotations
Code(CodeWithCursor);
29 format::getGoogleStyle(format::FormatStyle::LK_Cpp));
30 tooling::Replacements Merged;
34 auto NewCode = tooling::applyAllReplacements(
Code.code(), Merged);
35 EXPECT_TRUE(
bool(NewCode))
42 void expectAfterNewline(
const char *Before,
const char *After) {
43 EXPECT_EQ(After, afterTyped(Before,
"\n")) << Before;
45 void expectAfter(
const char *Typed,
const char *Before,
const char *After) {
46 EXPECT_EQ(After, afterTyped(Before, Typed)) << Before;
49 TEST(FormatIncremental, SplitComment) {
50 expectAfterNewline(R
"cpp(
59 expectAfterNewline(R"cpp(
60 // trailing whitespace is not a split
64 // trailing whitespace is not a split
68 expectAfterNewline(R"cpp(
79 expectAfterNewline(R"cpp(
88 expectAfterNewline(R"cpp(
97 expectAfterNewline(R
"cpp(
106 expectAfterNewline(R
"cpp(
116 expectAfterNewline(R"cpp(
127 expectAfterNewline(R
"cpp(
130 return; // All spelled tokens are accounted for.
131 // that takes two lines
138 return; // All spelled tokens are accounted for.
139 // that takes two lines
145 TEST(FormatIncremental, Indentation) {
146 expectAfterNewline(R"cpp(
157 expectAfterNewline(R"cpp(
168 expectAfterNewline(R"cpp(
178 expectAfterNewline(R"cpp(
190 expectAfterNewline(R
"cpp(
204 expectAfterNewline(R
"cpp(
218 expectAfterNewline(R
"cpp(
233 TEST(FormatIncremental, FormatPreviousLine) {
234 expectAfterNewline(R"cpp(
247 expectAfterNewline(R"cpp(
249 auto L = []{return;return;};
262 TEST(FormatIncremental, Annoyances) {
264 expectAfterNewline(R
"cpp(
279 expectAfterNewline(R
"cpp(
294 TEST(FormatIncremental, FormatBrace) {
295 expectAfter("}", R
"cpp(
302 vector<int> x = {1, 2, 3}^
TEST(BackgroundQueueTest, Priority)
llvm::Expected< size_t > positionToOffset(llvm::StringRef Code, Position P, bool AllowColumnsBeyondLineLength)
Turn a [line, column] pair into an offset in Code.
unsigned transformCursorPosition(unsigned Offset, const std::vector< tooling::Replacement > &Replacements)
Determine the new cursor position after applying Replacements.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::vector< tooling::Replacement > formatIncremental(llvm::StringRef OriginalCode, unsigned OriginalCursor, llvm::StringRef InsertedText, format::FormatStyle Style)
Applies limited formatting around new InsertedText.
static llvm::StringRef toString(SpecialMemberFunctionsCheck::SpecialMemberFunctionKind K)