From 4961e7265f57ce372f124a2f8829ad74215fe4b3 Mon Sep 17 00:00:00 2001 From: Martijn Otto Date: Wed, 27 Aug 2025 16:38:07 +0200 Subject: [PATCH 1/2] Add missing documentation about thrown exceptions --- include/router/table.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/router/table.h b/include/router/table.h index 1c0f639..a1563a5 100644 --- a/include/router/table.h +++ b/include/router/table.h @@ -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 { @@ -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 { From 047895445cb9d2daef08be70ed091865a9df011d Mon Sep 17 00:00:00 2001 From: Martijn Otto Date: Wed, 27 Aug 2025 16:38:35 +0200 Subject: [PATCH 2/2] Add test with lambda as callback --- tests/table.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/table.cpp b/tests/table.cpp index 9353a1e..8694c0d 100644 --- a/tests/table.cpp +++ b/tests/table.cpp @@ -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;