Skip to content

Commit a15da2a

Browse files
committed
Refactor tests for GetFunctionTemplatedDecls
1 parent 9f7f388 commit a15da2a

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

unittests/CppInterOp/FunctionReflectionTest.cpp

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,19 +296,50 @@ TEST(FunctionReflectionTest, GetClassDecls) {
296296
GetAllSubDecls(Decls[0], SubDecls);
297297

298298
std::vector<Cpp::TCppFunction_t> methods;
299-
std::vector<Cpp::TCppFunction_t> template_methods;
300-
301299
Cpp::GetClassMethods(Decls[0], methods);
300+
301+
EXPECT_EQ(methods.size(), 10); // includes structors and operators
302+
EXPECT_EQ(Cpp::GetName(methods[0]), Cpp::GetName(SubDecls[4]));
303+
EXPECT_EQ(Cpp::GetName(methods[1]), Cpp::GetName(SubDecls[5]));
304+
EXPECT_EQ(Cpp::GetName(methods[2]), Cpp::GetName(SubDecls[7]));
305+
EXPECT_EQ(Cpp::GetName(methods[3]), Cpp::GetName(SubDecls[8]));
306+
}
307+
308+
TEST(FunctionReflectionTest, GetFunctionTemplatedDecls) {
309+
std::vector<Decl*> Decls, SubDecls;
310+
std::string code = R"(
311+
class MyTemplatedMethodClass {
312+
template<class A, class B>
313+
long get_size(A, B, int i = 0) {}
314+
315+
template<class A = int, class B = char>
316+
long get_float_size(int i, A a = A(), B b = B()) {}
317+
318+
template<class A>
319+
void get_char_size(long k, A, char ch = 'a', double l = 0.0) {}
320+
321+
void f1() {}
322+
void f2(int i, double d, long l, char ch) {}
323+
324+
template<class A>
325+
void get_size(long k, A, char ch = 'a', double l = 0.0) {}
326+
327+
void f3(int i, double d, long l = 0, char ch = 'a') {}
328+
void f4(int i = 0, double d = 0.0, long l = 0, char ch = 'a') {}
329+
};
330+
)";
331+
332+
GetAllTopLevelDecls(code, Decls);
333+
GetAllSubDecls(Decls[0], SubDecls);
334+
335+
std::vector<Cpp::TCppFunction_t> template_methods;
302336
Cpp::GetFunctionTemplatedDecls(Decls[0], template_methods);
303337

338+
EXPECT_EQ(template_methods.size(), 4);
304339
EXPECT_EQ(Cpp::GetName(template_methods[0]), Cpp::GetName(SubDecls[1]));
305340
EXPECT_EQ(Cpp::GetName(template_methods[1]), Cpp::GetName(SubDecls[2]));
306341
EXPECT_EQ(Cpp::GetName(template_methods[2]), Cpp::GetName(SubDecls[3]));
307-
EXPECT_EQ(Cpp::GetName(methods[0]) , Cpp::GetName(SubDecls[4]));
308-
EXPECT_EQ(Cpp::GetName(methods[1]) , Cpp::GetName(SubDecls[5]));
309342
EXPECT_EQ(Cpp::GetName(template_methods[3]), Cpp::GetName(SubDecls[6]));
310-
EXPECT_EQ(Cpp::GetName(methods[2]) , Cpp::GetName(SubDecls[7]));
311-
EXPECT_EQ(Cpp::GetName(methods[3]) , Cpp::GetName(SubDecls[8]));
312343
}
313344

314345
TEST(FunctionReflectionTest, GetFunctionReturnType) {

0 commit comments

Comments
 (0)