diff --git a/include/Continuable.h b/include/Continuable.h index 1023fe5..2e54bb1 100644 --- a/include/Continuable.h +++ b/include/Continuable.h @@ -274,7 +274,7 @@ namespace detail { /// Corrects functionals with non expected signatures /// to match the expected ones. - /// Used in `partialized_signature_corrector` + /// Used in `partial_signature_corrector` template struct partial_signature_corrector { @@ -361,7 +361,7 @@ namespace detail } template - static inline auto partialized_signature_corrector(_CTy&& functional) + static inline auto partial_signature_corrector(_CTy&& functional) -> _CTy// decltype(correctors::partial_signature_corrector<_ATy...>::correct(std::declval<_CTy>())) { // return correctors::partial_signature_corrector<_ATy...>::correct(std::forward<_CTy>(functional)); @@ -408,7 +408,7 @@ namespace detail return unboxed_continuable_corrector(std::forward<_CTy>(functional)); } - /// `partialized_signature_corrector`: Converts functionals with not matching args signature. + /// `partial_signature_corrector`: Converts functionals with not matching args signature. /// `void_returning_corrector`: Converts void return to empty continuable. template static auto correct_stage(_CTy&& functional) @@ -416,10 +416,10 @@ namespace detail !detail::is_continuable< typename std::decay<_CTy>::type >::value, - decltype(void_returning_corrector(partialized_signature_corrector(std::declval<_CTy>()))) + decltype(void_returning_corrector(partial_signature_corrector(std::declval<_CTy>()))) >::type { - return void_returning_corrector(partialized_signature_corrector(std::forward<_CTy>(functional))); + return void_returning_corrector(partial_signature_corrector(std::forward<_CTy>(functional))); } /// Accepts and corrects user given functionals through several stages into the form: diff --git a/test.cpp b/test.cpp index 310be32..5f8b854 100644 --- a/test.cpp +++ b/test.cpp @@ -19,6 +19,8 @@ #include "catch.hpp" +#include "Continuable.h" + void test_mockup(); void test_incubator(); @@ -93,3 +95,68 @@ TEST_CASE("CrossForward tests", "[CrossForward]") REQUIRE_FALSE(con.ptr.get()); } } + +Continuable http_request(std::string const& /*url*/) +{ + return make_continuable([=](std::function&& callback) + { + // Do request... + std::string result = "some HTTP content"; + + callback(std::move(result)); + }); +} + +struct ResultSet +{ + std::size_t rows; +}; + +Continuable mysql_query(std::string const& /*query*/) +{ + return make_continuable([=](std::function&& callback) + { + callback(ResultSet{5}); + }); +} + +Continuable<> defect_continuable() +{ + return make_continuable([=](std::function&& /*callback*/) + { + // Callback is never called + }); +} + +TEST_CASE("Continuable invocation on destruct", "[Continuable]") +{ + bool invoked = false; + + std::function&&)> invokeable = [&](Callback<>&& callback) + { + invoked = true; + callback(); + }; + + SECTION("Continuables are not invoked before destruct") + { + Continuable<> continuable = make_continuable(std::move(invokeable)); + + REQUIRE_FALSE(invoked); + } + + SECTION("Continuables are invoked on destruct") + { + make_continuable(std::move(invokeable)); + + REQUIRE(invoked); + } +} + +TEST_CASE("Continuable continuation chaining using Continuable::then", "[Continuable]") +{ + SECTION("Continuables are invalidated on chaining (no duplicated call)") + { + std::size_t invoked = 0; + } +}