Skip to content

Commit

Permalink
Refactor result creation in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoryKogan committed Dec 23, 2023
1 parent 9812953 commit f152e40
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions tests/is_ok.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

TEST(IsOk, Ok) {
const int value = 5;
res::Result<int, std::string> result = res::Result<int, std::string>::Ok(value);
res::Result<int, std::string> result = res::Ok(value);
EXPECT_TRUE(result.is_ok());
EXPECT_FALSE(result.is_err());
}

TEST(IsOk, Err) {
res::Result<int, std::string> result = res::Result<int, std::string>::Err(std::string("Something went wrong"));
res::Result<int, std::string> result = res::Err(std::string("Something went wrong"));
EXPECT_FALSE(result.is_ok());
EXPECT_TRUE(result.is_err());
}
12 changes: 6 additions & 6 deletions tests/type_edgecases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
TEST(Types, SameInt) {
const int value = 42;
const int error = 43;
auto ok_result = res::Result<int, int>::Ok(value);
auto err_result = res::Result<int, int>::Err(error);
res::Result<int, int> ok_result = res::Ok(value);
res::Result<int, int> err_result = res::Err(error);

EXPECT_TRUE(ok_result.is_ok());
EXPECT_FALSE(ok_result.is_err());
Expand All @@ -22,8 +22,8 @@ TEST(Types, SameInt) {
TEST(Types, SameString) {
const std::string value = "Hello";
const std::string error = "World";
auto ok_result = res::Result<std::string, std::string>::Ok(value);
auto err_result = res::Result<std::string, std::string>::Err(error);
res::Result<std::string, std::string> ok_result = res::Ok(value);
res::Result<std::string, std::string> err_result = res::Err(error);

EXPECT_TRUE(ok_result.is_ok());
EXPECT_FALSE(ok_result.is_err());
Expand All @@ -37,8 +37,8 @@ TEST(Types, SameString) {
}

TEST(Types, EmptyValue) {
auto empty_ok_result = res::Result<std::monostate, std::string>::Ok();
auto empty_err_result = res::Result<std::monostate, std::string>::Err("Hello");
res::Result<std::monostate, std::string> empty_ok_result = res::Ok();
res::Result<std::monostate, std::string> empty_err_result = res::Err(std::string("Hello"));

EXPECT_TRUE(empty_ok_result.is_ok());
EXPECT_FALSE(empty_ok_result.is_err());
Expand Down
4 changes: 2 additions & 2 deletions tests/unwrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

TEST(Unwrap, Ok) {
const int value = 5;
res::Result<int, std::string> result = res::Result<int, std::string>::Ok(value);
res::Result<int, std::string> result = res::Ok(value);

EXPECT_EQ(result.unwrap(), value);
EXPECT_THROW(auto res = result.unwrap_err(), std::runtime_error);
}

TEST(Unwrap, Err) {
const std::string value = "Something went wrong";
res::Result<int, std::string> result = res::Result<int, std::string>::Err(value);
res::Result<int, std::string> result = res::Err(value);

EXPECT_EQ(result.unwrap_err(), value);
EXPECT_THROW(auto res = result.unwrap(), std::runtime_error);
Expand Down

0 comments on commit f152e40

Please sign in to comment.