1 //===-- ASTSignalsTests.cpp -------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "ASTSignals.h"
10 #include "TestIndex.h"
12 #include "llvm/ADT/StringRef.h"
13 #include "gmock/gmock.h"
14 #include "gtest/gtest.h"
21 using ::testing::Pair
;
22 using ::testing::UnorderedElementsAre
;
24 TEST(ASTSignals
, Derive
) {
25 TestTU TU
= TestTU::withCode(R
"cpp(
32 return ADD(tar::kConst, a.Y, tar::foo()) + fooInNS2() + tar::foo();
39 TU
.HeaderCode
= R
"cpp(
40 #define ADD(x, y, z) (x + y + z)
41 namespace tar { // A related namespace.
44 void bar(); // Unused symbols are not recorded.
49 namespace ns1::ns2 { int fooInNS2(); }}
51 ASTSignals Signals
= ASTSignals::derive(TU
.build());
52 std::vector
<std::pair
<StringRef
, int>> NS
;
53 for (const auto &P
: Signals
.RelatedNamespaces
)
54 NS
.emplace_back(P
.getKey(), P
.getValue());
55 EXPECT_THAT(NS
, UnorderedElementsAre(Pair("ns1::", 1), Pair("ns1::ns2::", 1),
56 Pair("tar::", /*foo, kConst, X*/ 3)));
58 std::vector
<std::pair
<SymbolID
, int>> Sym
;
59 for (const auto &P
: Signals
.ReferencedSymbols
)
60 Sym
.emplace_back(P
.getFirst(), P
.getSecond());
64 Pair(ns("tar").ID
, 4), Pair(ns("ns1").ID
, 1),
65 Pair(ns("ns1::ns2").ID
, 1), Pair(_
/*int func();*/, 1),
66 Pair(cls("tar::X").ID
, 1), Pair(var("tar::kConst").ID
, 1),
67 Pair(func("tar::foo").ID
, 2), Pair(func("ns1::ns2::fooInNS2").ID
, 1),
68 Pair(sym("Y", index::SymbolKind::Variable
, "@N@tar@S@X@FI@\\0").ID
,
71 EXPECT_EQ(Signals
.InsertionDirective
, Symbol::IncludeDirective::Include
);