mirror of
https://github.com/red0124/ssp.git
synced 2025-01-23 13:05:20 +01:00
make on_error accept lambda without arguments, update tests
This commit is contained in:
parent
371da072be
commit
16f4648cb3
@ -120,9 +120,14 @@ class parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Fun>
|
template <typename Fun>
|
||||||
auto on_error(Fun fun) {
|
auto on_error(Fun&& fun) {
|
||||||
if (!parser_.valid()) {
|
if (!parser_.valid()) {
|
||||||
fun(parser_.error_msg());
|
if constexpr (std::is_invocable_v<Fun>) {
|
||||||
|
fun();
|
||||||
|
} else {
|
||||||
|
std::invoke(std::forward<Fun>(fun),
|
||||||
|
parser_.error_msg());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,6 @@ TEST_CASE("testing composite conversion") {
|
|||||||
|
|
||||||
ss::parser p{f.name, ","};
|
ss::parser p{f.name, ","};
|
||||||
auto fail = [] { FAIL(""); };
|
auto fail = [] { FAIL(""); };
|
||||||
auto fail_if_error = [](auto& error) { CHECK(error.empty()); };
|
|
||||||
auto expect_error = [](auto error) { CHECK(!error.empty()); };
|
auto expect_error = [](auto error) { CHECK(!error.empty()); };
|
||||||
|
|
||||||
REQUIRE(p.valid());
|
REQUIRE(p.valid());
|
||||||
@ -203,7 +202,7 @@ TEST_CASE("testing composite conversion") {
|
|||||||
.or_else<test_struct>(fail)
|
.or_else<test_struct>(fail)
|
||||||
.or_else<int, char, double>(
|
.or_else<int, char, double>(
|
||||||
[](auto&& data) { CHECK(data == expectedData); })
|
[](auto&& data) { CHECK(data == expectedData); })
|
||||||
.on_error(fail_if_error)
|
.on_error(fail)
|
||||||
.or_else<test_tuple>(fail)
|
.or_else<test_tuple>(fail)
|
||||||
.values();
|
.values();
|
||||||
|
|
||||||
@ -224,11 +223,11 @@ TEST_CASE("testing composite conversion") {
|
|||||||
[](auto& i1, auto i2, double d) {
|
[](auto& i1, auto i2, double d) {
|
||||||
CHECK(std::tie(i1, i2, d) == expectedData);
|
CHECK(std::tie(i1, i2, d) == expectedData);
|
||||||
})
|
})
|
||||||
.on_error(fail_if_error)
|
.on_error(fail)
|
||||||
.or_else_object<test_struct, int, double, char>(fail)
|
.or_else_object<test_struct, int, double, char>(fail)
|
||||||
.on_error(fail_if_error)
|
.on_error(fail)
|
||||||
.or_else<test_tuple>(fail)
|
.or_else<test_tuple>(fail)
|
||||||
.on_error(fail_if_error)
|
.on_error(fail)
|
||||||
.or_else<int, char, double>(fail)
|
.or_else<int, char, double>(fail)
|
||||||
.values();
|
.values();
|
||||||
|
|
||||||
@ -313,9 +312,9 @@ TEST_CASE("testing composite conversion") {
|
|||||||
REQUIRE(!p.eof());
|
REQUIRE(!p.eof());
|
||||||
|
|
||||||
auto [d1, d2] = p.try_next<int, std::optional<int>>()
|
auto [d1, d2] = p.try_next<int, std::optional<int>>()
|
||||||
.on_error(fail_if_error)
|
.on_error(fail)
|
||||||
.or_else<std::tuple<int, std::string>>(fail)
|
.or_else<std::tuple<int, std::string>>(fail)
|
||||||
.on_error(fail_if_error)
|
.on_error(fail)
|
||||||
.values();
|
.values();
|
||||||
|
|
||||||
REQUIRE(p.valid());
|
REQUIRE(p.valid());
|
||||||
@ -329,9 +328,9 @@ TEST_CASE("testing composite conversion") {
|
|||||||
|
|
||||||
auto [d1, d2] =
|
auto [d1, d2] =
|
||||||
p.try_next<int, std::variant<int, std::string>>()
|
p.try_next<int, std::variant<int, std::string>>()
|
||||||
.on_error(fail_if_error)
|
.on_error(fail)
|
||||||
.or_else<std::tuple<int, std::string>>(fail)
|
.or_else<std::tuple<int, std::string>>(fail)
|
||||||
.on_error(fail_if_error)
|
.on_error(fail)
|
||||||
.values();
|
.values();
|
||||||
|
|
||||||
REQUIRE(p.valid());
|
REQUIRE(p.valid());
|
||||||
|
Loading…
Reference in New Issue
Block a user