Skip to content

Commit 07436e2

Browse files
committed
More callable tests
1 parent 18fd4d4 commit 07436e2

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/callable_tests.cc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,38 @@ TEST_CASE("Callable Function") {
1313
CHECK(func(10, 10) == 40);
1414
CHECK(capture == 20);
1515
}
16+
17+
TEST_CASE("Callable Function mixed params") {
18+
auto capture{0};
19+
auto func = Function<int(int, float)>{[&capture](int a, float b) {
20+
capture += 10;
21+
return a + b + capture;
22+
}};
23+
24+
CHECK(func(10, 10.f) == 30);
25+
CHECK(capture == 10);
26+
CHECK(func(10, 10.f) == 40);
27+
CHECK(capture == 20);
28+
}
29+
30+
TEST_CASE("Callable Function lots of params") {
31+
struct A {
32+
int a;
33+
char b;
34+
float d;
35+
double e;
36+
};
37+
auto capture{0};
38+
auto func = Function<int(int, float, char, A, A)>{[&capture](int a, float b, char x, A aa, A bb) {
39+
capture += 10;
40+
if (x == 'a')
41+
return aa.a + bb.b + capture * 2.f;
42+
else
43+
return a + b + capture;
44+
}};
45+
46+
CHECK(func(10, 10.f, 'x', {}, {2, 'b', 1.2f, 1.4}) == 30);
47+
CHECK(capture == 10);
48+
CHECK(func(10, 10.f, 'a', {}, {2, 'a', 1.2f, 1.4}) == 137);
49+
CHECK(capture == 20);
50+
}

0 commit comments

Comments
 (0)