#include "clang/Tooling/Refactoring.h"
#include "ReplacementTest.h"
#include "RewriterTestContext.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclGroup.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Format/Format.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Rewrite/Core/Rewriter.h"
#include "clang/Tooling/Refactoring/AtomicChange.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "gtest/gtest.h"
#include <optional>
namespace clang {
namespace tooling {
TEST_F(ReplacementTest, CanDeleteAllText) { … }
TEST_F(ReplacementTest, CanDeleteAllTextInTextWithNewlines) { … }
TEST_F(ReplacementTest, CanAddText) { … }
TEST_F(ReplacementTest, CanReplaceTextAtPosition) { … }
TEST_F(ReplacementTest, CanReplaceTextAtPositionMultipleTimes) { … }
TEST_F(ReplacementTest, ApplyFailsForNonExistentLocation) { … }
TEST_F(ReplacementTest, CanRetrivePath) { … }
TEST_F(ReplacementTest, ReturnsInvalidPath) { … }
static bool checkReplacementError(llvm::Error &&Error,
replacement_error ExpectedErr,
std::optional<Replacement> ExpectedExisting,
std::optional<Replacement> ExpectedNew) { … }
TEST_F(ReplacementTest, FailAddReplacements) { … }
TEST_F(ReplacementTest, DeletionInReplacements) { … }
TEST_F(ReplacementTest, OverlappingReplacements) { … }
TEST_F(ReplacementTest, AddAdjacentInsertionAndReplacement) { … }
TEST_F(ReplacementTest, MergeNewDeletions) { … }
TEST_F(ReplacementTest, MergeOverlappingButNotAdjacentReplacement) { … }
TEST_F(ReplacementTest, InsertionBeforeMergedDeletions) { … }
TEST_F(ReplacementTest, MergeOverlappingDeletions) { … }
TEST_F(ReplacementTest, FailedMergeExistingDeletions) { … }
TEST_F(ReplacementTest, FailAddRegression) { … }
TEST_F(ReplacementTest, InsertAtOffsetOfReplacement) { … }
TEST_F(ReplacementTest, AddInsertAtOtherInsertWhenOderIndependent) { … }
TEST_F(ReplacementTest, InsertBetweenAdjacentReplacements) { … }
TEST_F(ReplacementTest, CanApplyReplacements) { … }
TEST_F(ReplacementTest, InsertAndDelete) { … }
TEST_F(ReplacementTest, AdjacentReplacements) { … }
TEST_F(ReplacementTest, AddDuplicateReplacements) { … }
TEST_F(ReplacementTest, FailOrderDependentReplacements) { … }
TEST_F(ReplacementTest, InvalidSourceLocationFailsApplyAll) { … }
TEST_F(ReplacementTest, MultipleFilesReplaceAndFormat) { … }
TEST(ShiftedCodePositionTest, FindsNewCodePosition) { … }
TEST(ShiftedCodePositionTest, FindsNewCodePositionWithInserts) { … }
TEST(ShiftedCodePositionTest, FindsNewCodePositionInReplacedText) { … }
TEST(ShiftedCodePositionTest, NoReplacementText) { … }
class FlushRewrittenFilesTest : public ::testing::Test { … };
TEST_F(FlushRewrittenFilesTest, StoresChangesOnDisk) { … }
namespace {
template <typename T>
class TestVisitor : public clang::RecursiveASTVisitor<T> { … };
}
void expectReplacementAt(const Replacement &Replace,
StringRef File, unsigned Offset, unsigned Length) { … }
class ClassDeclXVisitor : public TestVisitor<ClassDeclXVisitor> { … };
TEST(Replacement, CanBeConstructedFromNode) { … }
TEST(Replacement, ReplacesAtSpellingLocation) { … }
class CallToFVisitor : public TestVisitor<CallToFVisitor> { … };
TEST(Replacement, FunctionCall) { … }
TEST(Replacement, TemplatedFunctionCall) { … }
class NestedNameSpecifierAVisitor
: public TestVisitor<NestedNameSpecifierAVisitor> { … };
TEST(Replacement, ColonColon) { … }
TEST(Range, overlaps) { … }
TEST(Range, contains) { … }
TEST(Range, CalculateRangesOfReplacements) { … }
TEST(Range, CalculateRangesOfInsertionAroundReplacement) { … }
TEST(Range, RangesAfterEmptyReplacements) { … }
TEST(Range, RangesAfterReplacements) { … }
TEST(Range, RangesBeforeReplacements) { … }
TEST(Range, NotAffectedByReplacements) { … }
TEST(Range, RangesWithNonOverlappingReplacements) { … }
TEST(Range, RangesWithOverlappingReplacements) { … }
TEST(Range, MergeIntoOneRange) { … }
TEST(Range, ReplacementsStartingAtRangeOffsets) { … }
TEST(Range, ReplacementsEndingAtRangeEnds) { … }
TEST(Range, AjacentReplacements) { … }
TEST(Range, MergeRangesAfterReplacements) { … }
TEST(Range, ConflictingRangesBeforeReplacements) { … }
class MergeReplacementsTest : public ::testing::Test { … };
TEST_F(MergeReplacementsTest, Offsets) { … }
TEST_F(MergeReplacementsTest, Concatenations) { … }
TEST_F(MergeReplacementsTest, NotChangingLengths) { … }
TEST_F(MergeReplacementsTest, OverlappingRanges) { … }
static constexpr bool usesWindowsPaths() { … }
TEST(DeduplicateByFileTest, PathsWithDots) { … }
TEST(DeduplicateByFileTest, PathWithDotSlash) { … }
TEST(DeduplicateByFileTest, NonExistingFilePath) { … }
class AtomicChangeTest : public ::testing::Test { … };
TEST_F(AtomicChangeTest, AtomicChangeToYAML) { … }
TEST_F(AtomicChangeTest, YAMLToAtomicChange) { … }
TEST_F(AtomicChangeTest, CheckKeyAndKeyFile) { … }
TEST_F(AtomicChangeTest, Replace) { … }
TEST_F(AtomicChangeTest, ReplaceWithRange) { … }
TEST_F(AtomicChangeTest, InsertBefore) { … }
TEST_F(AtomicChangeTest, InsertAfter) { … }
TEST_F(AtomicChangeTest, InsertBeforeWithInvalidLocation) { … }
TEST_F(AtomicChangeTest, InsertBeforeToWrongFile) { … }
TEST_F(AtomicChangeTest, InsertAfterWithInvalidLocation) { … }
TEST_F(AtomicChangeTest, Metadata) { … }
TEST_F(AtomicChangeTest, NoMetadata) { … }
class ApplyAtomicChangesTest : public ::testing::Test { … };
TEST_F(ApplyAtomicChangesTest, BasicRefactoring) { … }
TEST_F(ApplyAtomicChangesTest, SeveralRefactorings) { … }
TEST_F(ApplyAtomicChangesTest, IgnorePathsInRefactorings) { … }
TEST_F(ApplyAtomicChangesTest, AppliesDuplicateInsertions) { … }
TEST_F(ApplyAtomicChangesTest, BailsOnOverlappingRefactorings) { … }
TEST_F(ApplyAtomicChangesTest, BasicReformatting) { … }
TEST_F(ApplyAtomicChangesTest, OnlyFormatWhenViolateColumnLimits) { … }
TEST_F(ApplyAtomicChangesTest, LastLineViolateColumnLimits) { … }
TEST_F(ApplyAtomicChangesTest, LastLineWithNewlineViolateColumnLimits) { … }
TEST_F(ApplyAtomicChangesTest, Longer) { … }
TEST_F(ApplyAtomicChangesTest, Shorter) { … }
TEST_F(ApplyAtomicChangesTest, OnlyFormatChangedLines) { … }
TEST_F(ApplyAtomicChangesTest, DisableFormatting) { … }
TEST_F(ApplyAtomicChangesTest, AdaptsToLocalPointerStyle) { … }
TEST_F(ApplyAtomicChangesTest, AcceptsSurroundingFormatting) { … }
TEST_F(ApplyAtomicChangesTest, BailsOutOnConflictingChanges) { … }
TEST_F(ApplyAtomicChangesTest, InsertsNewIncludesInRightOrder) { … }
TEST_F(ApplyAtomicChangesTest, RemoveAndSortIncludes) { … }
TEST_F(ApplyAtomicChangesTest, InsertsSystemIncludes) { … }
TEST_F(ApplyAtomicChangesTest, RemoveSystemIncludes) { … }
TEST_F(ApplyAtomicChangesTest,
DoNotFormatFollowingLinesIfSeparatedWithNewline) { … }
TEST_F(ApplyAtomicChangesTest, FormatsCorrectLineWhenHeaderIsRemoved) { … }
TEST_F(ApplyAtomicChangesTest, CleansUpCtorInitializers) { … }
TEST_F(ApplyAtomicChangesTest, CleansUpParameterLists) { … }
TEST_F(ApplyAtomicChangesTest, DisableCleanup) { … }
TEST_F(ApplyAtomicChangesTest, EverythingDeleted) { … }
TEST_F(ApplyAtomicChangesTest, DoesNotDeleteInserts) { … }
}
}