szaszm commented on code in PR #1659:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1659#discussion_r1329751078
##########
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:
I don't mind replacing the mutable rvalue case with this, since it's what is
being tested in your example, but I'd still keep the const rvalue case, with
the NOLINT exclusion, to keep a full coverage of possible input reference types.
What do you think about replacing one or both mutable rvalue reference
blocks with ones similar to your example, while keeping the `const expected&&`
blocks that clang-tidy warns about?
--
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]