diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2026-09-22 16:27:21 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2026-09-22 16:27:21 +0200 |
| commit | 43e44bc35b18c7e6938d8b5103ae8a76dd06f5a0 (patch) | |
| tree | ee17a1616d3283ddac48a7c10e73b54bd455d81c | |
| parent | db2cf722c5e5b5399c8163a1d77cccf963c6fa78 (diff) | |
| download | ttwhy-43e44bc35b18c7e6938d8b5103ae8a76dd06f5a0.tar.xz ttwhy-43e44bc35b18c7e6938d8b5103ae8a76dd06f5a0.zip | |
lib/routers: introduce router concept
| -rw-r--r-- | CMakeLists.txt | 1 | ||||
| -rw-r--r-- | ttwhy/routers/echo.tests.cpp | 24 | ||||
| -rw-r--r-- | ttwhy/routers/mod.cppm | 1 | ||||
| -rw-r--r-- | ttwhy/routers/router_concepts.cppm | 20 |
4 files changed, 46 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 84d89a3..4228310 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,7 @@ target_sources("ttwhy-core" PUBLIC "ttwhy/routers/echo.cppm" "ttwhy/routers/mod.cppm" + "ttwhy/routers/router_concepts.cppm" "ttwhy/scanners/mod.cppm" "ttwhy/scanners/terminal_concepts.cppm" diff --git a/ttwhy/routers/echo.tests.cpp b/ttwhy/routers/echo.tests.cpp index f12d08b..c6ea10a 100644 --- a/ttwhy/routers/echo.tests.cpp +++ b/ttwhy/routers/echo.tests.cpp @@ -45,8 +45,32 @@ namespace token, buffers); } }; + + struct incomplete_router_no_policy + { + auto process(ttwhy::scanners::input_event) -> asio::awaitable<void>; + }; + + struct incomplete_router_no_process + { + using terminal_policy = ttwhy::scanners::xterm_policy; + }; + + struct incomplete_router_wrong_return + { + using terminal_policy = ttwhy::scanners::xterm_policy; + auto process(ttwhy::scanners::input_event) -> void; + }; } // namespace +TEST_CASE("The router concept validates router candidate interfaces", "[router][concept]") +{ + STATIC_REQUIRE(ttwhy::router<ttwhy::routers::echo<mock_stream>>); + STATIC_REQUIRE_FALSE(ttwhy::router<incomplete_router_no_policy>); + STATIC_REQUIRE_FALSE(ttwhy::router<incomplete_router_no_process>); + STATIC_REQUIRE_FALSE(ttwhy::router<incomplete_router_wrong_return>); +} + SCENARIO("The echo router handles terminal navigation within the valid printed area", "[router][echo]") { GIVEN("An initialized echo router with a mock stream") diff --git a/ttwhy/routers/mod.cppm b/ttwhy/routers/mod.cppm index fbab282..f5e151b 100644 --- a/ttwhy/routers/mod.cppm +++ b/ttwhy/routers/mod.cppm @@ -1,3 +1,4 @@ export module ttwhy.routers; export import :echo; +export import :router_concepts; diff --git a/ttwhy/routers/router_concepts.cppm b/ttwhy/routers/router_concepts.cppm new file mode 100644 index 0000000..ce143cb --- /dev/null +++ b/ttwhy/routers/router_concepts.cppm @@ -0,0 +1,20 @@ +module; + +#include <asio.hpp> + +#include <concepts> + +export module ttwhy.routers:router_concepts; + +import ttwhy.scanners; + +namespace ttwhy +{ + + export template<typename Candidate> + concept router = requires(Candidate candidate, scanners::input_event event) { + typename Candidate::terminal_policy; + { candidate.process(event) } -> std::same_as<asio::awaitable<void>>; + }; + +} // namespace ttwhy |
