@@ -254,17 +254,20 @@ TEST(ASTEntityMappingTest, VarRedeclaration) {
254254 auto Matches = match (Matcher, Ctx);
255255 ASSERT_EQ (Matches.size (), 2u );
256256
257- const auto *Decl1 = Matches[0 ].getNodeAs <VarDecl>(" decl" );
258- const auto *Decl2 = Matches[1 ].getNodeAs <VarDecl>(" decl" );
259- ASSERT_NE (Decl1, nullptr );
260- ASSERT_NE (Decl2, nullptr );
257+ const auto *FirstDecl = Matches[0 ].getNodeAs <VarDecl>(" decl" );
258+ ASSERT_NE (FirstDecl, nullptr );
261259
262- auto Name1 = getLocalEntityNameForDecl (Decl1);
263- auto Name2 = getLocalEntityNameForDecl (Decl2);
264- ASSERT_TRUE (Name1.has_value ());
265- ASSERT_TRUE (Name2.has_value ());
260+ auto FirstName = getLocalEntityNameForDecl (FirstDecl);
261+ ASSERT_TRUE (FirstName.has_value ());
262+
263+ for (size_t I = 1 ; I < Matches.size (); ++I) {
264+ const auto *Decl = Matches[I].getNodeAs <VarDecl>(" decl" );
265+ ASSERT_NE (Decl, nullptr );
266266
267- EXPECT_EQ (*Name1, *Name2);
267+ auto Name = getLocalEntityNameForDecl (Decl);
268+ ASSERT_TRUE (Name.has_value ());
269+ EXPECT_EQ (*FirstName, *Name);
270+ }
268271}
269272
270273TEST (ASTEntityMappingTest, RecordRedeclaration) {
@@ -274,22 +277,24 @@ TEST(ASTEntityMappingTest, RecordRedeclaration) {
274277 )" );
275278 auto &Ctx = AST->getASTContext ();
276279
277- // Use recordDecl(isStruct()) to avoid matching implicit typedefs
278- auto Matcher = recordDecl (hasName (" S" ), isStruct ()).bind (" decl" );
280+ auto Matcher = recordDecl (hasName (" S" ), unless (isImplicit ())).bind (" decl" );
279281 auto Matches = match (Matcher, Ctx);
280282 ASSERT_GE (Matches.size (), 2u );
281283
282- const auto *Decl1 = Matches[0 ].getNodeAs <RecordDecl>(" decl" );
283- const auto *Decl2 = Matches[1 ].getNodeAs <RecordDecl>(" decl" );
284- ASSERT_NE (Decl1, nullptr );
285- ASSERT_NE (Decl2, nullptr );
284+ const auto *FirstDecl = Matches[0 ].getNodeAs <RecordDecl>(" decl" );
285+ ASSERT_NE (FirstDecl, nullptr );
286286
287- auto Name1 = getLocalEntityNameForDecl (Decl1);
288- auto Name2 = getLocalEntityNameForDecl (Decl2);
289- ASSERT_TRUE (Name1.has_value ());
290- ASSERT_TRUE (Name2.has_value ());
287+ auto FirstName = getLocalEntityNameForDecl (FirstDecl);
288+ ASSERT_TRUE (FirstName.has_value ());
289+
290+ for (size_t I = 1 ; I < Matches.size (); ++I) {
291+ const auto *Decl = Matches[I].getNodeAs <RecordDecl>(" decl" );
292+ ASSERT_NE (Decl, nullptr );
291293
292- EXPECT_EQ (*Name1, *Name2);
294+ auto Name = getLocalEntityNameForDecl (Decl);
295+ ASSERT_TRUE (Name.has_value ());
296+ EXPECT_EQ (*FirstName, *Name);
297+ }
293298}
294299
295300TEST (ASTEntityMappingTest, ParmVarDeclRedeclaration) {
@@ -303,24 +308,21 @@ TEST(ASTEntityMappingTest, ParmVarDeclRedeclaration) {
303308 auto Matches = match (Matcher, Ctx);
304309 ASSERT_EQ (Matches.size (), 2u );
305310
306- const auto *Func1 = Matches[0 ].getNodeAs <FunctionDecl>(" decl" );
307- const auto *Func2 = Matches[1 ].getNodeAs <FunctionDecl>(" decl" );
308- ASSERT_NE (Func1, nullptr );
309- ASSERT_NE (Func2, nullptr );
310- ASSERT_GT (Func1->param_size (), 0u );
311- ASSERT_GT (Func2->param_size (), 0u );
311+ const auto *FirstFuncDecl = Matches[0 ].getNodeAs <FunctionDecl>(" decl" );
312+ ASSERT_NE (FirstFuncDecl, nullptr );
313+ ASSERT_GT (FirstFuncDecl->param_size (), 0u );
312314
313- const auto *Param1 = Func1->getParamDecl (0 );
314- const auto *Param2 = Func2->getParamDecl (0 );
315- ASSERT_NE (Param1, nullptr );
316- ASSERT_NE (Param2, nullptr );
315+ auto ParamEName = getLocalEntityNameForDecl (FirstFuncDecl->getParamDecl (0 ));
316+ ASSERT_TRUE (ParamEName.has_value ());
317317
318- auto Name1 = getLocalEntityNameForDecl (Param1);
319- auto Name2 = getLocalEntityNameForDecl (Param2 );
320- ASSERT_TRUE (Name1. has_value () );
321- ASSERT_TRUE (Name2. has_value () );
318+ for ( size_t I = 1 ; I < Matches. size (); ++I) {
319+ const auto *FDecl = Matches[I]. getNodeAs <FunctionDecl>( " decl " );
320+ ASSERT_NE (FDecl, nullptr );
321+ ASSERT_GT (FDecl-> param_size (), 0u );
322322
323- EXPECT_EQ (*Name1, *Name2);
323+ auto ParamRedeclEName = getLocalEntityNameForDecl (FDecl->getParamDecl (0 ));
324+ EXPECT_EQ (*ParamEName, *ParamRedeclEName);
325+ }
324326}
325327
326328TEST (ASTEntityMappingTest, FunctionReturnRedeclaration) {
@@ -335,16 +337,18 @@ TEST(ASTEntityMappingTest, FunctionReturnRedeclaration) {
335337 ASSERT_EQ (Matches.size (), 2u );
336338
337339 const auto *Decl1 = Matches[0 ].getNodeAs <FunctionDecl>(" decl" );
338- const auto *Decl2 = Matches[1 ].getNodeAs <FunctionDecl>(" decl" );
339340 ASSERT_NE (Decl1, nullptr );
340- ASSERT_NE (Decl2, nullptr );
341-
342341 auto Name1 = getLocalEntityNameForFunctionReturn (Decl1);
343- auto Name2 = getLocalEntityNameForFunctionReturn (Decl2);
344342 ASSERT_TRUE (Name1.has_value ());
345- ASSERT_TRUE (Name2.has_value ());
346343
347- EXPECT_EQ (*Name1, *Name2);
344+ for (size_t I = 1 ; I < Matches.size (); ++I) {
345+ const auto *FDecl = Matches[I].getNodeAs <FunctionDecl>(" decl" );
346+ ASSERT_NE (FDecl, nullptr );
347+
348+ auto Name = getLocalEntityNameForFunctionReturn (Decl1);
349+ ASSERT_TRUE (Name.has_value ());
350+ EXPECT_EQ (*Name1, *Name);
351+ }
348352}
349353
350354} // namespace
0 commit comments