1 //===-- SelectionTests.cpp - ----------------------------------------------===//
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 //===----------------------------------------------------------------------===//
8 #include "Annotations.h"
10 #include "SourceCode.h"
12 #include "support/TestTracer.h"
13 #include "clang/AST/Decl.h"
14 #include "llvm/Support/Casting.h"
15 #include "gmock/gmock.h"
16 #include "gtest/gtest.h"
21 using ::testing::ElementsAreArray
;
22 using ::testing::UnorderedElementsAreArray
;
24 // Create a selection tree corresponding to a point or pair of points.
25 // This uses the precisely-defined createRight semantics. The fuzzier
26 // createEach is tested separately.
27 SelectionTree
makeSelectionTree(const StringRef MarkedCode
, ParsedAST
&AST
) {
28 Annotations
Test(MarkedCode
);
29 switch (Test
.points().size()) {
30 case 1: { // Point selection.
31 unsigned Offset
= cantFail(positionToOffset(Test
.code(), Test
.point()));
32 return SelectionTree::createRight(AST
.getASTContext(), AST
.getTokens(),
35 case 2: // Range selection.
36 return SelectionTree::createRight(
37 AST
.getASTContext(), AST
.getTokens(),
38 cantFail(positionToOffset(Test
.code(), Test
.points()[0])),
39 cantFail(positionToOffset(Test
.code(), Test
.points()[1])));
41 ADD_FAILURE() << "Expected 1-2 points for selection.\n" << MarkedCode
;
42 return SelectionTree::createRight(AST
.getASTContext(), AST
.getTokens(), 0u,
47 Range
nodeRange(const SelectionTree::Node
*N
, ParsedAST
&AST
) {
50 const SourceManager
&SM
= AST
.getSourceManager();
51 const LangOptions
&LangOpts
= AST
.getLangOpts();
52 StringRef Buffer
= SM
.getBufferData(SM
.getMainFileID());
53 if (llvm::isa_and_nonnull
<TranslationUnitDecl
>(N
->ASTNode
.get
<Decl
>()))
54 return Range
{Position
{}, offsetToPosition(Buffer
, Buffer
.size())};
56 toHalfOpenFileRange(SM
, LangOpts
, N
->ASTNode
.getSourceRange());
57 assert(FileRange
&& "We should be able to get the File Range");
59 offsetToPosition(Buffer
, SM
.getFileOffset(FileRange
->getBegin())),
60 offsetToPosition(Buffer
, SM
.getFileOffset(FileRange
->getEnd()))};
63 std::string
nodeKind(const SelectionTree::Node
*N
) {
64 return N
? N
->kind() : "<null>";
67 std::vector
<const SelectionTree::Node
*> allNodes(const SelectionTree
&T
) {
68 std::vector
<const SelectionTree::Node
*> Result
= {&T
.root()};
69 for (unsigned I
= 0; I
< Result
.size(); ++I
) {
70 const SelectionTree::Node
*N
= Result
[I
];
71 Result
.insert(Result
.end(), N
->Children
.begin(), N
->Children
.end());
76 // Returns true if Common is a descendent of Root.
77 // Verifies nothing is selected above Common.
78 bool verifyCommonAncestor(const SelectionTree::Node
&Root
,
79 const SelectionTree::Node
*Common
,
80 StringRef MarkedCode
) {
84 ADD_FAILURE() << "Selected nodes outside common ancestor\n" << MarkedCode
;
86 for (const SelectionTree::Node
*Child
: Root
.Children
)
87 if (verifyCommonAncestor(*Child
, Common
, MarkedCode
)) {
89 ADD_FAILURE() << "Saw common ancestor twice\n" << MarkedCode
;
95 TEST(SelectionTest
, CommonAncestor
) {
97 // Selection is between ^marks^.
98 // common ancestor marked with a [[range]].
100 const char *CommonAncestorKind
;
105 template <typename T>
106 int x = [[T::^U::]]ccc();
108 "NestedNameSpecifierLoc",
112 struct AAA { struct BBB { static int ccc(); };};
113 int x = AAA::[[B^B^B]]::ccc();
119 struct AAA { struct BBB { static int ccc(); };};
120 int x = AAA::[[B^BB^]]::ccc();
126 struct AAA { struct BBB { static int ccc(); };};
127 int x = [[AAA::BBB::c^c^c]]();
133 struct AAA { struct BBB { static int ccc(); };};
134 int x = [[AAA::BBB::cc^c(^)]];
141 void foo() { [[if (1^11) { return; } else {^ }]] }
148 #define M(foo) x(foo)
157 #define CALL_FUNCTION(X) X()
158 void bar() { CALL_FUNCTION([[f^o^o]]); }
165 #define CALL_FUNCTION(X) X()
166 void bar() { [[CALL_FUNC^TION(fo^o)]]; }
173 #define CALL_FUNCTION(X) X()
174 void bar() { [[C^ALL_FUNC^TION(foo)]]; }
181 #^define CALL_FUNCTION(X) X(^)
182 void bar() { CALL_FUNCTION(foo); }
189 #define CALL_FUNCTION(X) X()
190 void bar() { CALL_FUNCTION(foo^)^; }
206 #define TARGET void foo()
207 [[TAR^GET{ return; }]]
213 struct S { S(const char*); };
216 // The AST says a CXXConstructExpr covers the = sign in C++14.
217 // But we consider CXXConstructExpr to only own brackets.
218 // (It's not the interesting constructor anyway, just S(&&)).
223 struct S { S(const char*); };
230 [[^void]] (*S)(int) = nullptr;
236 [[void (*S)^(int)]] = nullptr;
238 "FunctionProtoTypeLoc",
242 [[void (^*S)(int)]] = nullptr;
248 [[void (*^S)(int) = nullptr]];
254 [[void ^(*S)(int)]] = nullptr;
262 int bar() { return [[f^oo]](); }
265 "MemberExpr", // Not implicit CXXThisExpr, or its implicit cast!
269 auto lambda = [](const char*){ return 0; };
270 int x = lambda([["y
^"]]);
272 "StringLiteral", // Not DeclRefExpr to operator()!
277 struct Bar : [[v^ir^tual private Foo]] {};
284 struct Bar : private [[Fo^o]] {};
291 struct Bar : [[Fo^o]] {};
297 {"void foo() { [[^foo]](); }", "DeclRefExpr"},
298 {"void foo() { [[f^oo]](); }", "DeclRefExpr"},
299 {"void foo() { [[fo^o]](); }", "DeclRefExpr"},
300 {"void foo() { [[foo^()]]; }", "CallExpr"},
301 {"void foo() { [[foo^]] (); }", "DeclRefExpr"},
302 {"int bar; void foo() [[{ foo (); }]]^", "CompoundStmt"},
303 {"int x = [[42]]^;", "IntegerLiteral"},
305 // Ignores whitespace, comments, and semicolons in the selection.
306 {"void foo() { [[foo^()]]; /*comment*/^}", "CallExpr"},
308 // Tricky case: FunctionTypeLoc in FunctionDecl has a hole in it.
309 {"[[^void]] foo();", "BuiltinTypeLoc"},
310 {"[[void foo^()]];", "FunctionProtoTypeLoc"},
311 {"[[^void foo^()]];", "FunctionDecl"},
312 {"[[void ^foo()]];", "FunctionDecl"},
313 // Tricky case: two VarDecls share a specifier.
314 {"[[int ^a]], b;", "VarDecl"},
315 {"[[int a, ^b]];", "VarDecl"},
316 // Tricky case: CXXConstructExpr wants to claim the whole init range.
319 struct X { X(int); };
325 "CXXCtorInitializer", // Not the CXXConstructExpr!
327 // Tricky case: anonymous struct is a sibling of the VarDecl.
328 {"[[st^ruct {int x;}]] y;", "CXXRecordDecl"},
329 {"[[struct {int x;} ^y]];", "VarDecl"},
330 {"struct {[[int ^x]];} y;", "FieldDecl"},
332 // Tricky case: nested ArrayTypeLocs have the same token range.
333 {"const int x = 1, y = 2; int array[^[[x]]][10][y];", "DeclRefExpr"},
334 {"const int x = 1, y = 2; int array[x][10][^[[y]]];", "DeclRefExpr"},
335 {"const int x = 1, y = 2; int array[x][^[[10]]][y];", "IntegerLiteral"},
336 {"const int x = 1, y = 2; [[i^nt]] array[x][10][y];", "BuiltinTypeLoc"},
337 {"void func(int x) { int v_array[^[[x]]][10]; }", "DeclRefExpr"},
339 {"int (*getFunc([[do^uble]]))(int);", "BuiltinTypeLoc"},
341 // Member pointers and pack expansion use declarator syntax, but are
342 // restricted so they don't need special casing.
343 {"class X{}; [[int X::^*]]y[10];", "MemberPointerTypeLoc"},
344 {"template<typename ...T> void foo([[T*^...]]x);",
345 "PackExpansionTypeLoc"},
346 {"template<typename ...T> void foo([[^T]]*...x);",
347 "TemplateTypeParmTypeLoc"},
349 // FIXME: the AST has no location info for qualifiers.
350 {"const [[a^uto]] x = 42;", "AutoTypeLoc"},
351 {"co^nst auto x = 42;", nullptr},
354 {"void foo() { [[foo^^]] (); }", "DeclRefExpr"},
356 // FIXME: Ideally we'd get a declstmt or the VarDecl itself here.
357 // This doesn't happen now; the RAV doesn't traverse a node containing ;.
358 {"int x = 42;^", nullptr},
360 // Common ancestor is logically TUDecl, but we never return that.
361 {"^int x; int y;^", nullptr},
363 // Node types that have caused problems in the past.
364 {"template <typename T> void foo() { [[^T]] t; }",
365 "TemplateTypeParmTypeLoc"},
370 template <class T> struct Foo {};
371 template <[[template<class> class /*cursor here*/^U]]>
372 struct Foo<U<int>*> {};
374 "TemplateTemplateParmDecl"},
376 // Foreach has a weird AST, ensure we can select parts of the range init.
377 // This used to fail, because the DeclStmt for C claimed the whole range.
384 Str makeStr(const char*);
386 for (const char C : [[mak^eStr("foo
"^)]])
392 // User-defined literals are tricky: is 12_i one token or two?
393 // For now we treat it as one, and the UserDefinedLiteral as a leaf.
397 Foo operator""_ud(unsigned long long);
400 "UserDefinedLiteral"},
405 decltype([[^a]] + a) b;
408 {"[[decltype^(1)]] b;", "DecltypeTypeLoc"}, // Not the VarDecl.
409 // decltype(auto) is an AutoTypeLoc!
410 {"[[de^cltype(a^uto)]] a = 1;", "AutoTypeLoc"},
412 // Objective-C nullability attributes.
416 @property(nullable) [[^I]] *x;
419 "ObjCInterfaceTypeLoc"},
423 - (void)doSomething:(nonnull [[i^d]])argument;
428 // Objective-C OpaqueValueExpr/PseudoObjectExpr has weird ASTs.
429 // Need to traverse the contents of the OpaqueValueExpr to the POE,
430 // and ensure we traverse only the syntactic form of the PseudoObjectExpr.
434 @property(retain) I*x;
435 @property(retain) I*y;
437 void test(I *f) { [[^f]].x.y = 0; }
443 @property(retain) I*x;
444 @property(retain) I*y;
446 void test(I *f) { [[f.^x]].y = 0; }
448 "ObjCPropertyRefExpr"},
449 // Examples with implicit properties.
455 int test(I *f) { return 42 + [[^f]].foo; }
463 int test(I *f) { return 42 + [[f.^foo]]; }
465 "ObjCPropertyRefExpr"},
466 {"struct foo { [[int has^h<:32:>]]; };", "FieldDecl"},
467 {"struct foo { [[op^erator int()]]; };", "CXXConversionDecl"},
468 {"struct foo { [[^~foo()]]; };", "CXXDestructorDecl"},
469 {"struct foo { [[~^foo()]]; };", "CXXDestructorDecl"},
470 {"template <class T> struct foo { ~foo<[[^T]]>(){} };",
471 "TemplateTypeParmTypeLoc"},
472 {"struct foo {}; void bar(foo *f) { [[f->~^foo]](); }", "MemberExpr"},
473 {"struct foo { [[fo^o(){}]] };", "CXXConstructorDecl"},
476 struct S1 { void f(); };
477 struct S2 { S1 * operator->(); };
482 "DeclRefExpr"}, // DeclRefExpr to the "operator->" method.
484 // Template template argument.
486 template <typename> class Vector {};
487 template <template <typename> class Container> class A {};
490 "TemplateArgumentLoc"},
494 void f(int * __attribute__(([[no^nnull]])) );
499 // Digraph syntax for attributes to avoid accidental annotations.
500 class <:[gsl::Owner([[in^t]])]:> X{};
504 // This case used to crash - AST has a null Attr
507 [[@property(retain, nonnull) <:[My^Object2]:> *x]]; // error-ok
514 enum Bar : [[Fo^o]] {};
523 // lambda captured var-decl
526 auto l = [^[[foo = bar]]] { };
531 void func() [[{^]])cpp",
534 void func() { [[__^func__]]; }
540 namespace ns { enum class A {}; };
541 using enum ns::[[^A]];
545 namespace ns { enum class A {}; using B = A; };
546 using enum ns::[[^B]];
550 namespace ns { enum class A {}; };
551 using enum [[^ns::]]A;
553 "NestedNameSpecifierLoc"},
555 namespace ns { enum class A {}; };
556 [[using ^enum ns::A]];
560 namespace ns { enum class A {}; };
561 [[^using enum ns::A]];
567 template <class> concept C = true;
568 auto x = [[^C<int>]];
572 template <class> concept C = true;
577 template <class> concept C = true;
578 void foo([[^C]] auto x) {}
582 template <class> concept C = true;
583 template <[[^C]] x> int i = 0;
587 namespace ns { template <class> concept C = true; }
588 auto x = [[ns::^C<int>]];
593 for (const Case
&C
: Cases
) {
594 trace::TestTracer Tracer
;
595 Annotations
Test(C
.Code
);
598 TU
.Code
= std::string(Test
.code());
600 TU
.ExtraArgs
.push_back("-xobjective-c++");
601 TU
.ExtraArgs
.push_back("-std=c++20");
603 auto AST
= TU
.build();
604 auto T
= makeSelectionTree(C
.Code
, AST
);
605 EXPECT_EQ("TranslationUnitDecl", nodeKind(&T
.root())) << C
.Code
;
607 if (Test
.ranges().empty()) {
608 // If no [[range]] is marked in the example, there should be no selection.
609 EXPECT_FALSE(T
.commonAncestor()) << C
.Code
<< "\n" << T
;
610 EXPECT_THAT(Tracer
.takeMetric("selection_recovery", "C++"),
613 // If there is an expected selection, common ancestor should exist
614 // with the appropriate node type.
615 EXPECT_EQ(C
.CommonAncestorKind
, nodeKind(T
.commonAncestor()))
618 // Convert the reported common ancestor to a range and verify it.
619 EXPECT_EQ(nodeRange(T
.commonAncestor(), AST
), Test
.range())
623 // Check that common ancestor is reachable on exactly one path from root,
624 // and no nodes outside it are selected.
625 EXPECT_TRUE(verifyCommonAncestor(T
.root(), T
.commonAncestor(), C
.Code
))
627 EXPECT_THAT(Tracer
.takeMetric("selection_recovery", "C++"),
628 ElementsAreArray({0}));
633 // Regression test: this used to match the injected X, not the outer X.
634 TEST(SelectionTest
, InjectedClassName
) {
635 const char *Code
= "struct ^X { int x; };";
636 auto AST
= TestTU::withCode(Annotations(Code
).code()).build();
637 auto T
= makeSelectionTree(Code
, AST
);
638 ASSERT_EQ("CXXRecordDecl", nodeKind(T
.commonAncestor())) << T
;
639 auto *D
= dyn_cast
<CXXRecordDecl
>(T
.commonAncestor()->ASTNode
.get
<Decl
>());
640 EXPECT_FALSE(D
->isInjectedClassName());
643 TEST(SelectionTree
, Metrics
) {
644 const char *Code
= R
"cpp(
645 // error-ok: testing behavior on recovery expression
650 auto AST
= TestTU::withCode(Annotations(Code
).code()).build();
651 trace::TestTracer Tracer
;
652 auto T
= makeSelectionTree(Code
, AST
);
653 EXPECT_THAT(Tracer
.takeMetric("selection_recovery", "C++"),
654 ElementsAreArray({1}));
655 EXPECT_THAT(Tracer
.takeMetric("selection_recovery_type", "C++"),
656 ElementsAreArray({1}));
659 // FIXME: Doesn't select the binary operator node in
660 // #define FOO(X) X + 1
661 // int a, b = [[FOO(a)]];
662 TEST(SelectionTest
, Selected
) {
663 // Selection with ^marks^.
664 // Partially selected nodes marked with a [[range]].
665 // Completely selected nodes marked with a $C[[range]].
666 const char *Cases
[] = {
667 R
"cpp( int abc, xyz = [[^ab^c]]; )cpp",
668 R
"cpp( int abc, xyz = [[a^bc^]]; )cpp",
669 R
"cpp( int abc, xyz = $C[[^abc^]]; )cpp",
672 [[if ([[1^11]]) $C[[{
681 struct unique_ptr {};
682 void foo(^$C[[unique_ptr<$C[[unique_ptr<$C[[int]]>]]>]]^ a) {}
684 R
"cpp(int a = [[5 >^> 1]];)cpp",
687 ECHO(EC^HO($C[[int]]) EC^HO(a));
689 R
"cpp( $C[[^$C[[int]] a^]]; )cpp",
690 R
"cpp( $C[[^$C[[int]] a = $C[[5]]^]]; )cpp",
692 for (const char *C
: Cases
) {
694 auto AST
= TestTU::withCode(Test
.code()).build();
695 auto T
= makeSelectionTree(C
, AST
);
697 std::vector
<Range
> Complete
, Partial
;
698 for (const SelectionTree::Node
*N
: allNodes(T
))
699 if (N
->Selected
== SelectionTree::Complete
)
700 Complete
.push_back(nodeRange(N
, AST
));
701 else if (N
->Selected
== SelectionTree::Partial
)
702 Partial
.push_back(nodeRange(N
, AST
));
703 EXPECT_THAT(Complete
, UnorderedElementsAreArray(Test
.ranges("C"))) << C
;
704 EXPECT_THAT(Partial
, UnorderedElementsAreArray(Test
.ranges())) << C
;
708 TEST(SelectionTest
, PathologicalPreprocessor
) {
709 const char *Case
= R
"cpp(
710 #define MACRO while(1)
712 #include "Expand
.inc
"
716 Annotations
Test(Case
);
717 auto TU
= TestTU::withCode(Test
.code());
718 TU
.AdditionalFiles
["Expand.inc"] = "MACRO\n";
719 auto AST
= TU
.build();
720 EXPECT_THAT(AST
.getDiagnostics(), ::testing::IsEmpty());
721 auto T
= makeSelectionTree(Case
, AST
);
723 EXPECT_EQ("BreakStmt", T
.commonAncestor()->kind());
724 EXPECT_EQ("WhileStmt", T
.commonAncestor()->Parent
->kind());
727 TEST(SelectionTest
, IncludedFile
) {
728 const char *Case
= R
"cpp(
730 #include "Exp
^and.inc
"
734 Annotations
Test(Case
);
735 auto TU
= TestTU::withCode(Test
.code());
736 TU
.AdditionalFiles
["Expand.inc"] = "while(1)\n";
737 auto AST
= TU
.build();
738 auto T
= makeSelectionTree(Case
, AST
);
740 EXPECT_EQ(nullptr, T
.commonAncestor());
743 TEST(SelectionTest
, MacroArgExpansion
) {
744 // If a macro arg is expanded several times, we only consider the first one
746 const char *Case
= R
"cpp(
748 #define SQUARE(X) mul(X, X);
749 int nine = SQUARE(^3);
751 Annotations
Test(Case
);
752 auto AST
= TestTU::withCode(Test
.code()).build();
753 auto T
= makeSelectionTree(Case
, AST
);
754 EXPECT_EQ("IntegerLiteral", T
.commonAncestor()->kind());
755 EXPECT_TRUE(T
.commonAncestor()->Selected
);
757 // Verify that the common assert() macro doesn't suffer from this.
758 // (This is because we don't associate the stringified token with the arg).
760 void die(const char*);
761 #define assert(x) (x ? (void)0 : die(#x))
762 void foo() { assert(^42); }
764 Test
= Annotations(Case
);
765 AST
= TestTU::withCode(Test
.code()).build();
766 T
= makeSelectionTree(Case
, AST
);
767 EXPECT_EQ("IntegerLiteral", T
.commonAncestor()->kind());
769 // Reduced from private bug involving RETURN_IF_ERROR.
770 // Due to >>-splitting and a bug in isBeforeInTranslationUnit, the inner
771 // S<int> would claim way too many tokens.
774 template <typename T> class S {};
780 Test
= Annotations(Case
);
781 AST
= TestTU::withCode(Test
.code()).build();
782 T
= makeSelectionTree(Case
, AST
);
783 // not TemplateSpecializationTypeLoc!
784 EXPECT_EQ("VarDecl", T
.commonAncestor()->kind());
787 TEST(SelectionTest
, Implicit
) {
788 const char *Test
= R
"cpp(
789 struct S { S(const char*); };
793 auto TU
= TestTU::withCode(Annotations(Test
).code());
794 // C++14 AST contains some temporaries that C++17 elides.
795 TU
.ExtraArgs
.push_back("-std=c++17");
796 auto AST
= TU
.build();
797 auto T
= makeSelectionTree(Test
, AST
);
799 const SelectionTree::Node
*Str
= T
.commonAncestor();
800 EXPECT_EQ("StringLiteral", nodeKind(Str
)) << "Implicit selected?";
801 EXPECT_EQ("ImplicitCastExpr", nodeKind(Str
->Parent
));
802 EXPECT_EQ("CXXConstructExpr", nodeKind(Str
->Parent
->Parent
));
803 const SelectionTree::Node
*ICE
= Str
->Parent
->Parent
->Parent
;
804 EXPECT_EQ("ImplicitCastExpr", nodeKind(ICE
));
805 EXPECT_EQ("CallExpr", nodeKind(ICE
->Parent
));
806 EXPECT_EQ(Str
, &ICE
->ignoreImplicit())
807 << "Didn't unwrap " << nodeKind(&ICE
->ignoreImplicit());
809 EXPECT_EQ(ICE
, &Str
->outerImplicit());
812 TEST(SelectionTest
, CreateAll
) {
813 llvm::Annotations
Test("int$unique^ a=1$ambiguous^+1; $empty^");
814 auto AST
= TestTU::withCode(Test
.code()).build();
816 SelectionTree::createEach(
817 AST
.getASTContext(), AST
.getTokens(), Test
.point("ambiguous"),
818 Test
.point("ambiguous"), [&](SelectionTree T
) {
819 // Expect to see the right-biased tree first.
821 EXPECT_EQ("BinaryOperator", nodeKind(T
.commonAncestor()));
822 } else if (Seen
== 1) {
823 EXPECT_EQ("IntegerLiteral", nodeKind(T
.commonAncestor()));
831 SelectionTree::createEach(AST
.getASTContext(), AST
.getTokens(),
832 Test
.point("ambiguous"), Test
.point("ambiguous"),
833 [&](SelectionTree T
) {
837 EXPECT_EQ(1u, Seen
) << "Return true --> stop iterating";
840 SelectionTree::createEach(AST
.getASTContext(), AST
.getTokens(),
841 Test
.point("unique"), Test
.point("unique"),
842 [&](SelectionTree T
) {
846 EXPECT_EQ(1u, Seen
) << "no ambiguity --> only one tree";
849 SelectionTree::createEach(AST
.getASTContext(), AST
.getTokens(),
850 Test
.point("empty"), Test
.point("empty"),
851 [&](SelectionTree T
) {
852 EXPECT_FALSE(T
.commonAncestor());
856 EXPECT_EQ(1u, Seen
) << "empty tree still created";
859 SelectionTree::createEach(AST
.getASTContext(), AST
.getTokens(),
860 Test
.point("unique"), Test
.point("ambiguous"),
861 [&](SelectionTree T
) {
865 EXPECT_EQ(1u, Seen
) << "one tree for nontrivial selection";
868 TEST(SelectionTest
, DeclContextIsLexical
) {
869 llvm::Annotations
Test("namespace a { void $1^foo(); } void a::$2^foo();");
870 auto AST
= TestTU::withCode(Test
.code()).build();
872 auto ST
= SelectionTree::createRight(AST
.getASTContext(), AST
.getTokens(),
873 Test
.point("1"), Test
.point("1"));
874 EXPECT_FALSE(ST
.commonAncestor()->getDeclContext().isTranslationUnit());
877 auto ST
= SelectionTree::createRight(AST
.getASTContext(), AST
.getTokens(),
878 Test
.point("2"), Test
.point("2"));
879 EXPECT_TRUE(ST
.commonAncestor()->getDeclContext().isTranslationUnit());
884 } // namespace clangd