@@ -134,6 +134,15 @@ TEST(SelectionTest, CommonAncestor) {
134
134
)cpp" ,
135
135
" IfStmt" ,
136
136
},
137
+ {
138
+ R"cpp(
139
+ int x(int);
140
+ #define M(foo) x(foo)
141
+ int a = 42;
142
+ int b = M([[^a]]);
143
+ )cpp" ,
144
+ " DeclRefExpr" ,
145
+ },
137
146
{
138
147
R"cpp(
139
148
void foo();
@@ -378,6 +387,7 @@ TEST(SelectionTest, Selected) {
378
387
$C[[return]];
379
388
}]] else [[{^
380
389
}]]]]
390
+ char z;
381
391
}
382
392
)cpp" ,
383
393
R"cpp(
@@ -386,10 +396,10 @@ TEST(SelectionTest, Selected) {
386
396
void foo(^$C[[unique_ptr<$C[[unique_ptr<$C[[int]]>]]>]]^ a) {}
387
397
)cpp" ,
388
398
R"cpp( int a = [[5 >^> 1]];)cpp" ,
389
- R"cpp( [[
399
+ R"cpp(
390
400
#define ECHO(X) X
391
- ECHO(EC^HO([[ $C[[int]]) EC^HO(a]] ));
392
- ]] )cpp" ,
401
+ ECHO(EC^HO($C[[int]]) EC^HO(a));
402
+ )cpp" ,
393
403
R"cpp( $C[[^$C[[int]] a^]]; )cpp" ,
394
404
R"cpp( $C[[^$C[[int]] a = $C[[5]]^]]; )cpp" ,
395
405
};
@@ -428,6 +438,56 @@ TEST(SelectionTest, PathologicalPreprocessor) {
428
438
EXPECT_EQ (" WhileStmt" , T.commonAncestor ()->Parent ->kind ());
429
439
}
430
440
441
+ TEST (SelectionTest, IncludedFile) {
442
+ const char *Case = R"cpp(
443
+ void test() {
444
+ #include "Exp^and.inc"
445
+ break;
446
+ }
447
+ )cpp" ;
448
+ Annotations Test (Case);
449
+ auto TU = TestTU::withCode (Test.code ());
450
+ TU.AdditionalFiles [" Expand.inc" ] = " while(1)\n " ;
451
+ auto AST = TU.build ();
452
+ auto T = makeSelectionTree (Case, AST);
453
+
454
+ EXPECT_EQ (" WhileStmt" , T.commonAncestor ()->kind ());
455
+ }
456
+
457
+ TEST (SelectionTest, MacroArgExpansion) {
458
+ // If a macro arg is expanded several times, we consider them all selected.
459
+ const char *Case = R"cpp(
460
+ int mul(int, int);
461
+ #define SQUARE(X) mul(X, X);
462
+ int nine = SQUARE(^3);
463
+ )cpp" ;
464
+ Annotations Test (Case);
465
+ auto AST = TestTU::withCode (Test.code ()).build ();
466
+ auto T = makeSelectionTree (Case, AST);
467
+ // Unfortunately, this makes the common ancestor the CallExpr...
468
+ // FIXME: hack around this by picking one?
469
+ EXPECT_EQ (" CallExpr" , T.commonAncestor ()->kind ());
470
+ EXPECT_FALSE (T.commonAncestor ()->Selected );
471
+ EXPECT_EQ (2u , T.commonAncestor ()->Children .size ());
472
+ for (const auto * N : T.commonAncestor ()->Children ) {
473
+ EXPECT_EQ (" IntegerLiteral" , N->kind ());
474
+ EXPECT_TRUE (N->Selected );
475
+ }
476
+
477
+ // Verify that the common assert() macro doesn't suffer from this.
478
+ // (This is because we don't associate the stringified token with the arg).
479
+ Case = R"cpp(
480
+ void die(const char*);
481
+ #define assert(x) (x ? (void)0 : die(#x)
482
+ void foo() { assert(^42); }
483
+ )cpp" ;
484
+ Test = Annotations (Case);
485
+ AST = TestTU::withCode (Test.code ()).build ();
486
+ T = makeSelectionTree (Case, AST);
487
+
488
+ EXPECT_EQ (" IntegerLiteral" , T.commonAncestor ()->kind ());
489
+ }
490
+
431
491
TEST (SelectionTest, Implicit) {
432
492
const char * Test = R"cpp(
433
493
struct S { S(const char*); };
0 commit comments