Skip to content

Commit a0e5ce4

Browse files
committed
add additional Result constructor checks
1 parent 7aa02d7 commit a0e5ce4

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

tests/result.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
#include "common/result.hpp"
22

3+
#include <string>
4+
35
// there'll be a lot of unused variables, since we just want to see if it compiles
46
#pragma GCC diagnostic ignored "-Wunused-variable"
57

6-
class MyError {};
8+
class MyError {
9+
public:
10+
constexpr MyError(std::string) {}
11+
12+
constexpr MyError() {}
13+
};
714

815
class MyError2 {};
916

@@ -22,7 +29,17 @@ zest::Result<int, MyError> test_function_2() {
2229
}
2330

2431
constexpr void compile_time_tests() {
25-
// test sentinel values
32+
{
33+
// check constructors
34+
zest::Result<int, MyError> a(MyError{});
35+
zest::Result<int, MyError> b("test_MyError_conversion");
36+
zest::Result<int, MyError> c(2);
37+
zest::Result<int, MyError> d(2.0);
38+
zest::Result<int, MyError> e;
39+
zest::Result<void, MyError> f(MyError{});
40+
zest::Result<void, MyError> g("test_MyError_conversion");
41+
}
42+
2643
{
2744
// test comparison operator
2845
static_assert(zest::Result<int, MyError>(2) == zest::Result<int, MyError>(2));
@@ -42,10 +59,6 @@ constexpr void compile_time_tests() {
4259
const int&& e = zest::Result<int, MyError>(2);
4360
int f = a;
4461
}
45-
46-
{
47-
// test error getting
48-
}
4962
}
5063

5164
void runtime_tests() {}

0 commit comments

Comments
 (0)