Skip to content

Commit 7b18e28

Browse files
committed
fix: Fix extra brackets in warnings (#1519)
Fixes #1518
1 parent 4940d46 commit 7b18e28

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/rpc/common/Types.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ struct ReturnType {
9494
* @param warnings The warnings generated by the RPC call
9595
*/
9696
ReturnType(std::expected<boost::json::value, Status> result, boost::json::array warnings = {})
97-
: result{std::move(result)}, warnings{std::move(warnings)}
97+
: result{std::move(result)}, warnings(std::move(warnings))
9898
{
9999
}
100100

tests/unit/rpc/common/TypesTests.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "rpc/Errors.hpp"
2121
#include "rpc/common/Types.hpp"
2222

23+
#include <boost/json/array.hpp>
24+
#include <boost/json/value.hpp>
2325
#include <gtest/gtest.h>
2426

2527
#include <expected>
@@ -34,3 +36,46 @@ TEST(MaybeErrorTest, OperatorEquals)
3436
EXPECT_EQ(MaybeError{std::unexpected{Status{"Error"}}}, MaybeError{std::unexpected{Status{"Error"}}});
3537
EXPECT_NE(MaybeError{std::unexpected{Status{"Error"}}}, MaybeError{std::unexpected{Status{"Another_error"}}});
3638
}
39+
40+
TEST(ReturnTypeTests, Constructor)
41+
{
42+
boost::json::value const value{42};
43+
44+
{
45+
ReturnType const r{value};
46+
ASSERT_TRUE(r.result);
47+
EXPECT_EQ(r.result.value(), value);
48+
EXPECT_EQ(r.warnings, boost::json::array{});
49+
}
50+
51+
{
52+
boost::json::array const warnings{1, 2, 3};
53+
ReturnType const r{value, warnings};
54+
ASSERT_TRUE(r.result);
55+
EXPECT_EQ(r.result.value(), value);
56+
EXPECT_EQ(r.warnings, warnings);
57+
}
58+
59+
{
60+
Status const status{"Error"};
61+
62+
ReturnType const r{std::unexpected{status}};
63+
ASSERT_FALSE(r.result);
64+
EXPECT_EQ(r.result.error(), status);
65+
EXPECT_EQ(r.warnings, boost::json::array{});
66+
}
67+
}
68+
69+
TEST(ReturnTypeTests, operatorBool)
70+
{
71+
{
72+
boost::json::value const value{42};
73+
ReturnType const r{value};
74+
EXPECT_TRUE(r);
75+
}
76+
{
77+
Status const status{"Error"};
78+
ReturnType const r{std::unexpected{status}};
79+
EXPECT_FALSE(r);
80+
}
81+
}

0 commit comments

Comments
 (0)