2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/expected.hpp>
|
2019-02-07 17:12:59 +11:00
|
|
|
|
2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/tap.hpp>
|
2019-02-07 17:12:59 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main ()
|
|
|
|
{
|
|
|
|
cruft::TAP::logger tap;
|
|
|
|
|
2020-02-17 17:40:03 +11:00
|
|
|
tap.expect_nothrow (
|
|
|
|
[] () { (void)cruft::expected<std::string,int> { "foo" }; },
|
|
|
|
"value construction succeeds"
|
|
|
|
);
|
|
|
|
|
|
|
|
tap.expect_nothrow (
|
|
|
|
[] () { (void)cruft::expected<std::string,int> { EPERM }; },
|
|
|
|
"error construction succeeds"
|
|
|
|
);
|
2019-02-07 17:12:59 +11:00
|
|
|
|
|
|
|
tap.expect_eq (cruft::expected<std::string,int> { "foo" }.value (), "foo", "value matches");
|
|
|
|
tap.expect_eq (cruft::expected<std::string,int> { EPERM }.error (), EPERM, "error matches");
|
|
|
|
|
|
|
|
tap.expect_throw<cruft::bad_expected_access> (
|
|
|
|
[] () {
|
|
|
|
cruft::expected<std::string,int> val { EPERM };
|
|
|
|
val.value ();
|
|
|
|
},
|
|
|
|
"value access fails when holding an error"
|
|
|
|
);
|
|
|
|
|
|
|
|
tap.expect_throw<cruft::bad_expected_access> (
|
|
|
|
[] () {
|
|
|
|
cruft::expected<std::string,int> val { "foo" };
|
|
|
|
val.error ();
|
|
|
|
},
|
|
|
|
"error access fails when holding a value"
|
|
|
|
);
|
|
|
|
|
|
|
|
return tap.status ();
|
|
|
|
}
|