llvm/clang/unittests/Format/SortIncludesTest.cpp

//===- unittest/Format/SortIncludesTest.cpp - Include sort unit tests -----===//
//
// 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
//
//===----------------------------------------------------------------------===//

#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) {}

// FIXME: the tests below should pass.
#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"     // Start of line: 0
                   "#include \"b\"\r\n"     // Start of line: 14
                   "#include \"c\"\r\n"     // Start of line: 28
                   "\r\n"                   // Start of line: 42
                   "int i;";                // Start of line: 44
  StringRef Expected = "#include \"a\"\r\n" // Start of line: 0
                       "\r\n"               // Start of line: 14
                       "#include \"b\"\r\n" // Start of line: 16
                       "\r\n"               // Start of line: 30
                       "#include \"c\"\r\n" // Start of line: 32
                       "\r\n"               // Start of line: 46
                       "int i;";            // Start of line: 48
  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"     // Start of line: 0
                   "\r\n"                   // Start of line: 14
                   "#include \"c\"\r\n"     // Start of line: 16
                   "\r\n"                   // Start of line: 30
                   "#include \"b\"\r\n"     // Start of line: 32
                   "\r\n"                   // Start of line: 46
                   "int i;";                // Start of line: 48
  StringRef Expected = "#include \"a\"\r\n" // Start of line: 0
                       "\r\n"               // Start of line: 14
                       "#include \"b\"\r\n" // Start of line: 16
                       "\r\n"               // Start of line: 30
                       "#include \"c\"\r\n" // Start of line: 32
                       "\r\n"               // Start of line: 46
                       "int i;";            // Start of line: 48
  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) {}

} // end namespace
} // end namespace format
} // end namespace clang