#include "FormatTestBase.h"
#include "clang/Format/Format.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Debug.h"
#include "gtest/gtest.h"
#define DEBUG_TYPE …
namespace clang {
namespace format {
namespace {
class SortIncludesTest : public test::FormatTestBase { … };
TEST_F(SortIncludesTest, BasicSorting) { … }
TEST_F(SortIncludesTest, TrailingComments) { … }
TEST_F(SortIncludesTest, SortedIncludesUsingSortPriorityAttribute) { … }
TEST_F(SortIncludesTest, SortPriorityNotDefined) { … }
TEST_F(SortIncludesTest, NoReplacementsForValidIncludes) { … }
TEST_F(SortIncludesTest, MainFileHeader) { … }
TEST_F(SortIncludesTest, SortedIncludesInMultipleBlocksAreMerged) { … }
TEST_F(SortIncludesTest, SupportClangFormatOff) { … }
TEST_F(SortIncludesTest, SupportClangFormatOffCStyle) { … }
TEST_F(SortIncludesTest, IncludeSortingCanBeDisabled) { … }
TEST_F(SortIncludesTest, MixIncludeAndImport) { … }
TEST_F(SortIncludesTest, FixTrailingComments) { … }
TEST_F(SortIncludesTest, LeadingWhitespace) { … }
TEST_F(SortIncludesTest, TrailingWhitespace) { … }
TEST_F(SortIncludesTest, GreaterInComment) { … }
TEST_F(SortIncludesTest, SortsLocallyInEachBlock) { … }
TEST_F(SortIncludesTest, SortsAllBlocksWhenMerging) { … }
TEST_F(SortIncludesTest, CommentsAlwaysSeparateGroups) { … }
TEST_F(SortIncludesTest, HandlesAngledIncludesAsSeparateBlocks) { … }
TEST_F(SortIncludesTest, RegroupsAngledIncludesInSeparateBlocks) { … }
TEST_F(SortIncludesTest, HandlesMultilineIncludes) { … }
TEST_F(SortIncludesTest, HandlesTrailingCommentsWithAngleBrackets) { … }
TEST_F(SortIncludesTest, LeavesMainHeaderFirst) { … }
TEST_F(SortIncludesTest, LeavesMainHeaderFirstInAdditionalExtensions) { … }
TEST_F(SortIncludesTest, RecognizeMainHeaderInAllGroups) { … }
TEST_F(SortIncludesTest, MainHeaderIsSeparatedWhenRegroupping) { … }
TEST_F(SortIncludesTest, SupportOptionalCaseSensitiveSorting) { … }
TEST_F(SortIncludesTest, SupportCaseInsensitiveMatching) { … }
TEST_F(SortIncludesTest, SupportOptionalCaseSensitiveMachting) { … }
TEST_F(SortIncludesTest, NegativePriorities) { … }
TEST_F(SortIncludesTest, PriorityGroupsAreSeparatedWhenRegroupping) { … }
TEST_F(SortIncludesTest, CalculatesCorrectCursorPosition) { … }
TEST_F(SortIncludesTest, CalculatesCorrectCursorPositionWithRegrouping) { … }
TEST_F(SortIncludesTest,
CalculatesCorrectCursorPositionWhenNoReplacementsWithRegroupingAndCRLF) { … }
TEST_F(
SortIncludesTest,
CalculatesCorrectCursorPositionWhenRemoveLinesReplacementsWithRegroupingAndCRLF) { … }
#if 0
TEST_F(
SortIncludesTest,
CalculatesCorrectCursorPositionWhenNewLineReplacementsWithRegroupingAndCRLF) {
Style.IncludeBlocks = Style.IBS_Regroup;
FmtStyle.LineEnding = FormatStyle::LE_CRLF;
Style.IncludeCategories = {
{"^\"a\"", 0, 0, false}, {"^\"b\"", 1, 1, false}, {".*", 2, 2, false}};
StringRef Code = "#include \"a\"\r\n"
"#include \"b\"\r\n"
"#include \"c\"\r\n"
"\r\n"
"int i;";
StringRef Expected = "#include \"a\"\r\n"
"\r\n"
"#include \"b\"\r\n"
"\r\n"
"#include \"c\"\r\n"
"\r\n"
"int i;";
verifyFormat(Expected, sort(Code));
EXPECT_EQ(0u, newCursor(Code, 0));
EXPECT_EQ(15u, newCursor(Code, 16));
EXPECT_EQ(30u, newCursor(Code, 32));
EXPECT_EQ(44u, newCursor(Code, 46));
EXPECT_EQ(46u, newCursor(Code, 48));
}
TEST_F(
SortIncludesTest,
CalculatesCorrectCursorPositionWhenNoNewLineReplacementsWithRegroupingAndCRLF) {
Style.IncludeBlocks = Style.IBS_Regroup;
FmtStyle.LineEnding = FormatStyle::LE_CRLF;
Style.IncludeCategories = {
{"^\"a\"", 0, 0, false}, {"^\"b\"", 1, 1, false}, {".*", 2, 2, false}};
StringRef Code = "#include \"a\"\r\n"
"\r\n"
"#include \"c\"\r\n"
"\r\n"
"#include \"b\"\r\n"
"\r\n"
"int i;";
StringRef Expected = "#include \"a\"\r\n"
"\r\n"
"#include \"b\"\r\n"
"\r\n"
"#include \"c\"\r\n"
"\r\n"
"int i;";
verifyFormat(Expected, sort(Code));
EXPECT_EQ(0u, newCursor(Code, 0));
EXPECT_EQ(14u, newCursor(Code, 14));
EXPECT_EQ(30u, newCursor(Code, 32));
EXPECT_EQ(30u, newCursor(Code, 30));
EXPECT_EQ(15u, newCursor(Code, 15));
EXPECT_EQ(44u, newCursor(Code, 46));
EXPECT_EQ(46u, newCursor(Code, 48));
}
#endif
TEST_F(SortIncludesTest, DeduplicateIncludes) { … }
TEST_F(SortIncludesTest, SortAndDeduplicateIncludes) { … }
TEST_F(SortIncludesTest, CalculatesCorrectCursorPositionAfterDeduplicate) { … }
TEST_F(SortIncludesTest, DeduplicateLocallyInEachBlock) { … }
TEST_F(SortIncludesTest, ValidAffactedRangesAfterDeduplicatingIncludes) { … }
TEST_F(SortIncludesTest, DoNotSortLikelyXml) { … }
TEST_F(SortIncludesTest, DoNotOutputReplacementsForSortedBlocksWithRegrouping) { … }
TEST_F(SortIncludesTest,
DoNotOutputReplacementsForSortedBlocksWithRegroupingWindows) { … }
TEST_F(SortIncludesTest, MainIncludeChar) { … }
TEST_F(SortIncludesTest, MainIncludeCharAnyPickQuote) { … }
TEST_F(SortIncludesTest, MainIncludeCharAnyPickAngleBracket) { … }
TEST_F(SortIncludesTest, MainIncludeCharQuoteAndRegroup) { … }
TEST_F(SortIncludesTest, MainIncludeCharAngleBracketAndRegroup) { … }
TEST_F(SortIncludesTest, DoNotRegroupGroupsInGoogleObjCStyle) { … }
TEST_F(SortIncludesTest, DoNotTreatPrecompiledHeadersAsFirstBlock) { … }
TEST_F(SortIncludesTest, skipUTF8ByteOrderMarkMerge) { … }
TEST_F(SortIncludesTest, skipUTF8ByteOrderMarkPreserve) { … }
TEST_F(SortIncludesTest, MergeLines) { … }
TEST_F(SortIncludesTest, DisableFormatDisablesIncludeSorting) { … }
TEST_F(SortIncludesTest, DisableRawStringLiteralSorting) { … }
TEST_F(SortIncludesTest, BlockCommentedOutIncludes) { … }
}
}
}