mirror of
https://github.com/Naios/continuable.git
synced 2025-12-06 16:56:44 +08:00
Move some experimental compilation tests to its own unit test
This commit is contained in:
parent
7189068037
commit
180380cfbc
@ -20,162 +20,8 @@
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <system_error>
|
|
||||||
#include <tuple>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <continuable/continuable.hpp>
|
#include <continuable/continuable.hpp>
|
||||||
|
|
||||||
#include <continuable/detail/flat-variant.hpp>
|
|
||||||
|
|
||||||
/*
|
|
||||||
static cti::continuable<std::string> http_request(std::string url) {
|
|
||||||
return [url = std::move(url)](cti::promise<std::string> promise) {
|
|
||||||
if (false) {
|
|
||||||
promise.set_value("");
|
|
||||||
std::forward<decltype(promise)>(promise)("");
|
|
||||||
}
|
|
||||||
promise.set_exception(std::error_condition{});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
static auto http_request2(std::string url) {
|
|
||||||
return cti::make_continuable<std::string>(
|
|
||||||
// ...
|
|
||||||
[url = std::move(url)](auto&& promise) {
|
|
||||||
if (false) {
|
|
||||||
promise.set_value("");
|
|
||||||
std::forward<decltype(promise)>(promise)("");
|
|
||||||
}
|
|
||||||
promise.set_exception(std::error_condition{});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static cti::continuable<std::string> http_request3(std::string url) {
|
|
||||||
return [url = std::move(url)](auto&& promise) {
|
|
||||||
if (false) {
|
|
||||||
promise.set_value("");
|
|
||||||
std::forward<decltype(promise)>(promise)("");
|
|
||||||
}
|
|
||||||
promise.set_exception(std::error_condition{});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
struct my_callable {
|
|
||||||
void operator()(std::string) && {
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
void operator()(cti::dispatch_error_tag, cti::error_type) && {
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void old() {
|
|
||||||
http_request("github.com").next(my_callable{});
|
|
||||||
|
|
||||||
http_request("github.com") | [](std::string) {
|
|
||||||
// ...
|
|
||||||
return 0;
|
|
||||||
} | [] {
|
|
||||||
// ...
|
|
||||||
};
|
|
||||||
|
|
||||||
http_request2("github.com")
|
|
||||||
.then([](std::string) {
|
|
||||||
// ...
|
|
||||||
return 0;
|
|
||||||
})
|
|
||||||
.then([](int) {
|
|
||||||
// ...
|
|
||||||
})
|
|
||||||
.fail([](std::error_condition) {
|
|
||||||
// ...
|
|
||||||
});
|
|
||||||
|
|
||||||
(http_request("github.com") && http_request3("github.com"))
|
|
||||||
.then([](std::string, std::string) {
|
|
||||||
// ...
|
|
||||||
})
|
|
||||||
.fail([](std::error_condition) {
|
|
||||||
// ...
|
|
||||||
})
|
|
||||||
.apply([](auto&& me) {
|
|
||||||
// ...
|
|
||||||
return std::forward<decltype(me)>(me);
|
|
||||||
});
|
|
||||||
|
|
||||||
(http_request("github.com") || http_request("github.com"))
|
|
||||||
.then([](std::string) {
|
|
||||||
// ...
|
|
||||||
})
|
|
||||||
.fail([](std::error_condition) {
|
|
||||||
// ...
|
|
||||||
});
|
|
||||||
|
|
||||||
(http_request("github.com") >> http_request("github.com"))
|
|
||||||
.then([](std::string, std::string) {
|
|
||||||
// ...
|
|
||||||
})
|
|
||||||
.fail([](std::error_condition) {
|
|
||||||
// ...
|
|
||||||
});
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
int main(int, char**) {
|
int main(int, char**) {
|
||||||
using namespace cti::detail;
|
// ...
|
||||||
|
|
||||||
{
|
|
||||||
cti::when_seq(
|
|
||||||
cti::make_ready_continuable(0, 1), 2, //< See this plain value
|
|
||||||
cti::populate(cti::make_ready_continuable(3),
|
|
||||||
cti::make_ready_continuable(4)),
|
|
||||||
std::make_tuple(std::make_tuple(cti::make_ready_continuable(5))))
|
|
||||||
.then([](int r0, int r1, int r2, std::vector<int> r34,
|
|
||||||
std::tuple<std::tuple<int>> r5) {
|
|
||||||
// ...
|
|
||||||
util::unused(r0, r1, r2, r34, r5);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
auto v = cti::populate(cti::make_ready_continuable(8),
|
|
||||||
cti::make_ready_continuable(9));
|
|
||||||
|
|
||||||
cti::when_seq(v.begin(), v.end()).then([](auto o2) {
|
|
||||||
// ...
|
|
||||||
util::unused(o2);
|
|
||||||
});
|
|
||||||
|
|
||||||
cti::when_seq(cti::make_ready_continuable()) // ...
|
|
||||||
.then([] {
|
|
||||||
// ...
|
|
||||||
});
|
|
||||||
|
|
||||||
cti::when_seq() // ...
|
|
||||||
.then([] {
|
|
||||||
// ...
|
|
||||||
});
|
|
||||||
|
|
||||||
cti::when_seq(cti::make_exceptional_continuable<void>(std::error_condition{}))
|
|
||||||
.fail([](auto) {
|
|
||||||
// ...
|
|
||||||
});
|
|
||||||
|
|
||||||
cti::when_all(
|
|
||||||
cti::make_ready_continuable(0, 1), 2, //< See this plain value
|
|
||||||
cti::populate(cti::make_ready_continuable(3),
|
|
||||||
cti::make_ready_continuable(4)),
|
|
||||||
std::make_tuple(std::make_tuple(cti::make_ready_continuable(5))))
|
|
||||||
.then([](int r0, int r1, int r2, std::vector<int> r34,
|
|
||||||
std::tuple<std::tuple<int>> r5) {
|
|
||||||
// ...
|
|
||||||
util::unused(r0, r1, r2, r34, r5);
|
|
||||||
});
|
|
||||||
|
|
||||||
cti::when_any(cti::make_ready_continuable(22),
|
|
||||||
cti::make_ready_continuable(44))
|
|
||||||
.then([](int) {
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,7 @@ target_link_libraries(test-continuable-base
|
|||||||
continuable-features-noexcept)
|
continuable-features-noexcept)
|
||||||
|
|
||||||
add_executable(test-continuable-single
|
add_executable(test-continuable-single
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/single/test-continuable-connection-noinst
|
||||||
${CMAKE_CURRENT_LIST_DIR}/single/test-continuable-flat-variant.cpp
|
${CMAKE_CURRENT_LIST_DIR}/single/test-continuable-flat-variant.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/single/test-continuable-expected.cpp
|
${CMAKE_CURRENT_LIST_DIR}/single/test-continuable-expected.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/single/test-continuable-traverse.cpp
|
${CMAKE_CURRENT_LIST_DIR}/single/test-continuable-traverse.cpp
|
||||||
|
|||||||
141
test/unit-test/single/test-continuable-connection-noinst.cpp
Normal file
141
test/unit-test/single/test-continuable-connection-noinst.cpp
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
Copyright(c) 2015 - 2018 Denis Blank <denis.blank at outlook dot com>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files(the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions :
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <test-continuable.hpp>
|
||||||
|
|
||||||
|
static cti::continuable<std::string> http_request(std::string) {
|
||||||
|
return cti::make_ready_continuable<std::string>("");
|
||||||
|
}
|
||||||
|
|
||||||
|
struct my_callable {
|
||||||
|
void operator()(std::string) && {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
void operator()(cti::dispatch_error_tag, cti::error_type) && {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(simple_compilation_tests, error_compile_tests) {
|
||||||
|
http_request("github.com").next(my_callable{});
|
||||||
|
|
||||||
|
http_request("github.com") | [](std::string) {
|
||||||
|
// ...
|
||||||
|
return 0;
|
||||||
|
} | [] {
|
||||||
|
// ...
|
||||||
|
};
|
||||||
|
|
||||||
|
http_request("github.com")
|
||||||
|
.then([](std::string) {
|
||||||
|
// ...
|
||||||
|
return 0;
|
||||||
|
})
|
||||||
|
.then([](int) {
|
||||||
|
// ...
|
||||||
|
})
|
||||||
|
.fail([](cti::error_type) {
|
||||||
|
// ...
|
||||||
|
});
|
||||||
|
|
||||||
|
(http_request("github.com") && http_request("github.com"))
|
||||||
|
.then([](std::string, std::string) {
|
||||||
|
// ...
|
||||||
|
})
|
||||||
|
.fail([](cti::error_type) {
|
||||||
|
// ...
|
||||||
|
})
|
||||||
|
.apply([](auto&& me) {
|
||||||
|
// ...
|
||||||
|
return std::forward<decltype(me)>(me);
|
||||||
|
});
|
||||||
|
|
||||||
|
(http_request("github.com") || http_request("github.com"))
|
||||||
|
.then([](std::string) {
|
||||||
|
// ...
|
||||||
|
})
|
||||||
|
.fail([](cti::error_type) {
|
||||||
|
// ...
|
||||||
|
});
|
||||||
|
|
||||||
|
(http_request("github.com") >> http_request("github.com"))
|
||||||
|
.then([](std::string, std::string) {
|
||||||
|
// ...
|
||||||
|
})
|
||||||
|
.fail([](cti::error_type) {
|
||||||
|
// ...
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(simple_compilation_tests, connection_compile_tests) {
|
||||||
|
|
||||||
|
cti::when_seq(
|
||||||
|
cti::make_ready_continuable(0, 1), 2, //< See this plain value
|
||||||
|
cti::populate(cti::make_ready_continuable(3),
|
||||||
|
cti::make_ready_continuable(4)),
|
||||||
|
std::make_tuple(std::make_tuple(cti::make_ready_continuable(5))))
|
||||||
|
.then([](int r0, int r1, int r2, std::vector<int> r34,
|
||||||
|
std::tuple<std::tuple<int>> r5) {
|
||||||
|
// ...
|
||||||
|
unused(r0, r1, r2, r34, r5);
|
||||||
|
});
|
||||||
|
|
||||||
|
auto v = cti::populate(cti::make_ready_continuable(8),
|
||||||
|
cti::make_ready_continuable(9));
|
||||||
|
|
||||||
|
cti::when_seq(v.begin(), v.end()).then([](auto) {
|
||||||
|
// ...
|
||||||
|
});
|
||||||
|
|
||||||
|
cti::when_seq(cti::make_ready_continuable()) // ...
|
||||||
|
.then([] {
|
||||||
|
// ...
|
||||||
|
});
|
||||||
|
|
||||||
|
cti::when_seq() // ...
|
||||||
|
.then([] {
|
||||||
|
// ...
|
||||||
|
});
|
||||||
|
|
||||||
|
cti::when_seq(cti::make_exceptional_continuable<void>(cti::error_type{}))
|
||||||
|
.fail([](auto) {
|
||||||
|
// ...
|
||||||
|
});
|
||||||
|
|
||||||
|
cti::when_all(
|
||||||
|
cti::make_ready_continuable(0, 1), 2, //< See this plain value
|
||||||
|
cti::populate(cti::make_ready_continuable(3),
|
||||||
|
cti::make_ready_continuable(4)),
|
||||||
|
std::make_tuple(std::make_tuple(cti::make_ready_continuable(5))))
|
||||||
|
.then([](int r0, int r1, int r2, std::vector<int> r34,
|
||||||
|
std::tuple<std::tuple<int>> r5) {
|
||||||
|
// ...
|
||||||
|
unused(r0, r1, r2, r34, r5);
|
||||||
|
});
|
||||||
|
|
||||||
|
cti::when_any(cti::make_ready_continuable(22),
|
||||||
|
cti::make_ready_continuable(44))
|
||||||
|
.then([](int) {
|
||||||
|
// ...
|
||||||
|
});
|
||||||
|
}
|
||||||
@ -35,6 +35,7 @@
|
|||||||
#include <continuable/continuable.hpp>
|
#include <continuable/continuable.hpp>
|
||||||
|
|
||||||
using cti::detail::traits::identity;
|
using cti::detail::traits::identity;
|
||||||
|
using cti::detail::util::unused;
|
||||||
|
|
||||||
inline auto to_hint(identity<> /*hint*/) {
|
inline auto to_hint(identity<> /*hint*/) {
|
||||||
return identity<void>{};
|
return identity<void>{};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user