blob: 93bf62bba1d450534b8e12327adac5cf5ab7bf26 [file] [log] [blame]
Sam McCall8dc9dbb2018-10-15 13:34:10 +00001#include "SyncAPI.h"
2#include "TestFS.h"
3#include "index/Background.h"
4#include "gmock/gmock.h"
5#include "gtest/gtest.h"
6
7using testing::UnorderedElementsAre;
8
9namespace clang {
10namespace clangd {
11
12MATCHER_P(Named, N, "") { return arg.Name == N; }
13
14TEST(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 McCall8dc9dbb2018-10-15 13:34:10 +000035
36} // namespace clangd
37} // namespace clang