Sam McCall | 8dc9dbb | 2018-10-15 13:34:10 +0000 | [diff] [blame] | 1 | #include "SyncAPI.h" |
| 2 | #include "TestFS.h" |
| 3 | #include "index/Background.h" |
| 4 | #include "gmock/gmock.h" |
| 5 | #include "gtest/gtest.h" |
| 6 | |
| 7 | using testing::UnorderedElementsAre; |
| 8 | |
| 9 | namespace clang { |
| 10 | namespace clangd { |
| 11 | |
| 12 | MATCHER_P(Named, N, "") { return arg.Name == N; } |
| 13 | |
| 14 | TEST(BackgroundIndexTest, IndexTwoFiles) { |
| 15 | MockFSProvider FS; |
| 16 | // a.h yields different symbols when included by A.cc vs B.cc. |
| 17 | // Currently we store symbols for each TU, so we get both. |
| 18 | FS.Files[testPath("root/A.h")] = "void a_h(); void NAME(){}"; |
| 19 | FS.Files[testPath("root/A.cc")] = "#include \"A.h\""; |
| 20 | FS.Files[testPath("root/B.cc")] = "#define NAME bar\n#include \"A.h\""; |
| 21 | BackgroundIndex Idx(Context::empty(), "", FS); |
| 22 | |
| 23 | tooling::CompileCommand Cmd; |
| 24 | Cmd.Filename = testPath("root/A.cc"); |
| 25 | Cmd.Directory = testPath("root"); |
| 26 | Cmd.CommandLine = {"clang++", "-DNAME=foo", testPath("root/A.cc")}; |
| 27 | Idx.enqueue(testPath("root"), Cmd); |
| 28 | Cmd.CommandLine.back() = Cmd.Filename = testPath("root/B.cc"); |
| 29 | Idx.enqueue(testPath("root"), Cmd); |
| 30 | |
| 31 | Idx.blockUntilIdleForTest(); |
| 32 | EXPECT_THAT(runFuzzyFind(Idx, ""), |
| 33 | UnorderedElementsAre(Named("a_h"), Named("foo"), Named("bar"))); |
| 34 | } |
Sam McCall | 8dc9dbb | 2018-10-15 13:34:10 +0000 | [diff] [blame] | 35 | |
| 36 | } // namespace clangd |
| 37 | } // namespace clang |