[AMDGPU][AsmParser][NFC] Translate parsed MIMG instructions to MCInsts automatically.
[llvm-project.git] / clang-tools-extra / include-cleaner / unittests / TypesTest.cpp
blob554de211ac0e6e6de1c64a23c550b62002e65429
1 //===-- RecordTest.cpp ----------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "clang-include-cleaner/Types.h"
10 #include "clang/Basic/FileManager.h"
11 #include "clang/Tooling/Inclusions/StandardLibrary.h"
12 #include "llvm/ADT/IntrusiveRefCntPtr.h"
13 #include "llvm/Support/VirtualFileSystem.h"
14 #include "gmock/gmock.h"
15 #include "gtest/gtest.h"
17 namespace clang::include_cleaner {
18 namespace {
19 using testing::ElementsAre;
21 // Matches an Include* on the specified line;
22 MATCHER_P(line, N, "") { return arg->Line == (unsigned)N; }
24 TEST(RecordedIncludesTest, Match) {
25 // We're using synthetic data, but need a FileManager to obtain FileEntry*s.
26 // Ensure it doesn't do any actual IO.
27 auto FS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
28 FileManager FM(FileSystemOptions{});
29 const FileEntry *A = FM.getVirtualFile("/path/a", /*Size=*/0, time_t{});
30 const FileEntry *B = FM.getVirtualFile("/path/b", /*Size=*/0, time_t{});
32 Includes Inc;
33 Inc.add(Include{"a", A, SourceLocation(), 1});
34 Inc.add(Include{"a2", A, SourceLocation(), 2});
35 Inc.add(Include{"b", B, SourceLocation(), 3});
36 Inc.add(Include{"vector", B, SourceLocation(), 4});
37 Inc.add(Include{"vector", B, SourceLocation(), 5});
38 Inc.add(Include{"missing", nullptr, SourceLocation(), 6});
40 EXPECT_THAT(Inc.match(A), ElementsAre(line(1), line(2)));
41 EXPECT_THAT(Inc.match(B), ElementsAre(line(3), line(4), line(5)));
42 EXPECT_THAT(Inc.match(*tooling::stdlib::Header::named("<vector>")),
43 ElementsAre(line(4), line(5)));
46 } // namespace
47 } // namespace clang::include_cleaner