llvm/clang/unittests/ASTMatchers/ASTMatchersTest.h

//===- unittest/Tooling/ASTMatchersTest.h - Matcher tests helpers ------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_UNITTESTS_ASTMATCHERS_ASTMATCHERSTEST_H
#define LLVM_CLANG_UNITTESTS_ASTMATCHERS_ASTMATCHERSTEST_H

#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Frontend/ASTUnit.h"
#include "clang/Testing/CommandLineArgs.h"
#include "clang/Testing/TestClangConfig.h"
#include "clang/Tooling/Tooling.h"
#include "gtest/gtest.h"

namespace clang {
namespace ast_matchers {

buildASTFromCodeWithArgs;
FileContentMappings;
FrontendActionFactory;
newFrontendActionFactory;
runToolOnCodeWithArgs;

class BoundNodesCallback {};

// If 'FindResultVerifier' is not NULL, sets *Verified to the result of
// running 'FindResultVerifier' with the bound nodes as argument.
// If 'FindResultVerifier' is NULL, sets *Verified to true when Run is called.
class VerifyMatch : public MatchFinder::MatchCallback {};

inline ArrayRef<TestLanguage> langCxx11OrLater() {}

inline ArrayRef<TestLanguage> langCxx14OrLater() {}

inline ArrayRef<TestLanguage> langCxx17OrLater() {}

inline ArrayRef<TestLanguage> langCxx20OrLater() {}

inline ArrayRef<TestLanguage> langCxx23OrLater() {}

template <typename T>
testing::AssertionResult matchesConditionally(
    const Twine &Code, const T &AMatcher, bool ExpectMatch,
    ArrayRef<std::string> CompileArgs,
    const FileContentMappings &VirtualMappedFiles = FileContentMappings(),
    StringRef Filename = "input.cc") {}

template <typename T>
testing::AssertionResult
matchesConditionally(const Twine &Code, const T &AMatcher, bool ExpectMatch,
                     ArrayRef<TestLanguage> TestLanguages) {}

template <typename T>
testing::AssertionResult
matches(const Twine &Code, const T &AMatcher,
        ArrayRef<TestLanguage> TestLanguages = {}

template <typename T>
testing::AssertionResult
notMatches(const Twine &Code, const T &AMatcher,
           ArrayRef<TestLanguage> TestLanguages = {}

template <typename T>
testing::AssertionResult matchesObjC(const Twine &Code, const T &AMatcher,
                                     bool ExpectMatch = true) {}

template <typename T>
testing::AssertionResult matchesC(const Twine &Code, const T &AMatcher) {}

template <typename T>
testing::AssertionResult notMatchesObjC(const Twine &Code, const T &AMatcher) {}

// Function based on matchesConditionally with "-x cuda" argument added and
// small CUDA header prepended to the code string.
template <typename T>
testing::AssertionResult
matchesConditionallyWithCuda(const Twine &Code, const T &AMatcher,
                             bool ExpectMatch, llvm::StringRef CompileArg) {}

template <typename T>
testing::AssertionResult matchesWithCuda(const Twine &Code, const T &AMatcher) {}

template <typename T>
testing::AssertionResult notMatchesWithCuda(const Twine &Code,
                                            const T &AMatcher) {}

template <typename T>
testing::AssertionResult matchesWithOpenMP(const Twine &Code,
                                           const T &AMatcher) {}

template <typename T>
testing::AssertionResult notMatchesWithOpenMP(const Twine &Code,
                                              const T &AMatcher) {}

template <typename T>
testing::AssertionResult matchesWithOpenMP51(const Twine &Code,
                                             const T &AMatcher) {}

template <typename T>
testing::AssertionResult notMatchesWithOpenMP51(const Twine &Code,
                                                const T &AMatcher) {}

template <typename T>
testing::AssertionResult matchAndVerifyResultConditionally(
    const Twine &Code, const T &AMatcher,
    std::unique_ptr<BoundNodesCallback> FindResultVerifier, bool ExpectResult,
    ArrayRef<std::string> Args = {}

// FIXME: Find better names for these functions (or document what they
// do more precisely).
template <typename T>
testing::AssertionResult
matchAndVerifyResultTrue(const Twine &Code, const T &AMatcher,
                         std::unique_ptr<BoundNodesCallback> FindResultVerifier,
                         ArrayRef<std::string> Args = {}

template <typename T>
testing::AssertionResult matchAndVerifyResultFalse(
    const Twine &Code, const T &AMatcher,
    std::unique_ptr<BoundNodesCallback> FindResultVerifier,
    ArrayRef<std::string> Args = {}

// Implements a run method that returns whether BoundNodes contains a
// Decl bound to Id that can be dynamically cast to T.
// Optionally checks that the check succeeded a specific number of times.
template <typename T> class VerifyIdIsBoundTo : public BoundNodesCallback {};

class ASTMatchersTest : public ::testing::Test,
                        public ::testing::WithParamInterface<TestClangConfig> {};

} // namespace ast_matchers
} // namespace clang

#endif // LLVM_CLANG_UNITTESTS_AST_MATCHERS_AST_MATCHERS_TEST_H