szaszm commented on code in PR #1659:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1659#discussion_r1329598353
##########
libminifi/test/unit/ExpectedTest.cpp:
##########
@@ -484,3 +484,63 @@ TEST_CASE("expected valueOrElse",
"[expected][valueOrElse]") {
REQUIRE_THROWS_AS(ex | utils::valueOrElse([](const std::string&) -> int {
throw std::exception(); }), std::exception);
REQUIRE_THROWS_AS(std::move(ex) | utils::valueOrElse([](std::string&&) ->
int { throw std::exception(); }), std::exception);
}
+
+TEST_CASE("expected transformError", "[expected][transformError]") {
+ auto mul2 = [](int a) { return a * 2; };
+
+ {
+ nonstd::expected<int, int> e = nonstd::make_unexpected(21);
+ auto ret = e | utils::transformError(mul2);
+ REQUIRE(!ret);
+ REQUIRE(ret.error() == 42);
+ }
+
+ {
+ const nonstd::expected<int, int> e = nonstd::make_unexpected(21);
+ auto ret = e | utils::transformError(mul2);
+ REQUIRE(!ret);
+ REQUIRE(ret.error() == 42);
+ }
+
+ {
+ nonstd::expected<int, int> e = nonstd::make_unexpected(21);
+ auto ret = std::move(e) | utils::transformError(mul2);
+ REQUIRE(!ret);
+ REQUIRE(ret.error() == 42);
+ }
+
+ {
+ const nonstd::expected<int, int> e = nonstd::make_unexpected(21);
+ auto ret = std::move(e) | utils::transformError(mul2); //
NOLINT(performance-move-const-arg)
+ REQUIRE(!ret);
+ REQUIRE(ret.error() == 42);
+ }
Review Comment:
It doesn't make much sense to use const rvalue refs, but this still checks
that the implementation matches the expectations in this unlikely case. I just
copy pasted the transform tests from above, which were copy pasted from
TartanLlama's test suite.
How would you structure the suggested new test case, that ends up testing
the expected implementation, and not the C++ language itself?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]