Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/router/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ namespace router {
* @param endpoint The endpoint to route
* @param parameters The arguments to give to the callback
* @return The result of the callback
* @throws std::out_of_range
* @throws std::out_of_range If no matching route and no not_found handler is available
*/
return_type route(std::string_view endpoint, arguments... parameters) const
{
Expand Down Expand Up @@ -302,7 +302,7 @@ namespace router {
* @param method The method to proxy to
* @param parameters The arguments to give to the callback
* @return The result of the callback
* @throws std::out_of_range
* @throws std::out_of_range If no matching route or not_found handler is found
*/
return_type route(std::string_view endpoint, decltype(first) method, arguments... parameters) const
{
Expand Down
30 changes: 30 additions & 0 deletions tests/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,36 @@ TEST_CASE("paths can be matched", "[path]") {
REQUIRE(tester.callback4_invoked == true);
}

SECTION("invoking a lambda") {
bool callback1_invoked{false};
bool callback2_invoked{false};
std::size_t number{};

auto callback1 = [&callback1_invoked]() { callback1_invoked = true; };
auto callback2 = [&callback2_invoked, &number](std::size_t input) {
callback2_invoked = true;
number = input;
};

table.add<&decltype(callback1)::operator()>("/callback/1", &callback1);
table.add<&decltype(callback2)::operator()>("/callback/2/{\\d+}",
&callback2);

REQUIRE(callback1_invoked == false);
REQUIRE(callback2_invoked == false);

table.route("/callback/1");

REQUIRE(callback1_invoked == true);
REQUIRE(callback2_invoked == false);

table.route("/callback/2/5");

REQUIRE(callback1_invoked == true);
REQUIRE(callback2_invoked == true);
REQUIRE(number == 5);
}

SECTION("invoking a member function with slug") {
struct slug_data {
std::size_t number;
Expand Down
Loading