mirror of
https://github.com/Naios/continuable.git
synced 2026-02-09 03:06:41 +08:00
Add some invokation tests
This commit is contained in:
parent
b8e6edfbe8
commit
f70efcfc01
@ -274,7 +274,7 @@ namespace detail
|
|||||||
{
|
{
|
||||||
/// Corrects functionals with non expected signatures
|
/// Corrects functionals with non expected signatures
|
||||||
/// to match the expected ones.
|
/// to match the expected ones.
|
||||||
/// Used in `partialized_signature_corrector`
|
/// Used in `partial_signature_corrector`
|
||||||
template<typename... _ATy>
|
template<typename... _ATy>
|
||||||
struct partial_signature_corrector
|
struct partial_signature_corrector
|
||||||
{
|
{
|
||||||
@ -361,7 +361,7 @@ namespace detail
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename _CTy>
|
template<typename _CTy>
|
||||||
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>()))
|
-> _CTy// decltype(correctors::partial_signature_corrector<_ATy...>::correct(std::declval<_CTy>()))
|
||||||
{
|
{
|
||||||
// return correctors::partial_signature_corrector<_ATy...>::correct(std::forward<_CTy>(functional));
|
// 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));
|
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.
|
/// `void_returning_corrector`: Converts void return to empty continuable.
|
||||||
template<typename _CTy>
|
template<typename _CTy>
|
||||||
static auto correct_stage(_CTy&& functional)
|
static auto correct_stage(_CTy&& functional)
|
||||||
@ -416,10 +416,10 @@ namespace detail
|
|||||||
!detail::is_continuable<
|
!detail::is_continuable<
|
||||||
typename std::decay<_CTy>::type
|
typename std::decay<_CTy>::type
|
||||||
>::value,
|
>::value,
|
||||||
decltype(void_returning_corrector(partialized_signature_corrector(std::declval<_CTy>())))
|
decltype(void_returning_corrector(partial_signature_corrector(std::declval<_CTy>())))
|
||||||
>::type
|
>::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:
|
/// Accepts and corrects user given functionals through several stages into the form:
|
||||||
|
|||||||
67
test.cpp
67
test.cpp
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
|
|
||||||
|
#include "Continuable.h"
|
||||||
|
|
||||||
void test_mockup();
|
void test_mockup();
|
||||||
void test_incubator();
|
void test_incubator();
|
||||||
|
|
||||||
@ -93,3 +95,68 @@ TEST_CASE("CrossForward tests", "[CrossForward]")
|
|||||||
REQUIRE_FALSE(con.ptr.get());
|
REQUIRE_FALSE(con.ptr.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Continuable<std::string> http_request(std::string const& /*url*/)
|
||||||
|
{
|
||||||
|
return make_continuable([=](std::function<void(std::string)>&& callback)
|
||||||
|
{
|
||||||
|
// Do request...
|
||||||
|
std::string result = "some HTTP content";
|
||||||
|
|
||||||
|
callback(std::move(result));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ResultSet
|
||||||
|
{
|
||||||
|
std::size_t rows;
|
||||||
|
};
|
||||||
|
|
||||||
|
Continuable<ResultSet> mysql_query(std::string const& /*query*/)
|
||||||
|
{
|
||||||
|
return make_continuable([=](std::function<void(ResultSet)>&& callback)
|
||||||
|
{
|
||||||
|
callback(ResultSet{5});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Continuable<> defect_continuable()
|
||||||
|
{
|
||||||
|
return make_continuable([=](std::function<void()>&& /*callback*/)
|
||||||
|
{
|
||||||
|
// Callback is never called
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Continuable invocation on destruct", "[Continuable]")
|
||||||
|
{
|
||||||
|
bool invoked = false;
|
||||||
|
|
||||||
|
std::function<void(Callback<>&&)> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user