Skip to content

Commit

Permalink
More tests for optional comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
karzhenkov committed Jan 8, 2023
1 parent 9026493 commit 7745f59
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/src/unit-optional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ TEST_CASE("nlohmann::optional comparison")
CHECK_FALSE(nullopt == opt_int(0));
CHECK_FALSE(opt_int(0) == opt_int(1));

CHECK(opt_int() == std_opt_int());
CHECK(opt_int(0) == std_opt_int(0));
CHECK_FALSE(opt_int(0) == std_opt_int(1));

CHECK(std_opt_int() == opt_int());
CHECK(std_opt_int(0) == opt_int(0));
CHECK_FALSE(std_opt_int(0) == opt_int(1));

CHECK(opt_int(0) != nullopt);
CHECK(nullopt != opt_int(0));
CHECK(opt_int(0) != opt_int(1));
Expand All @@ -43,25 +51,45 @@ TEST_CASE("nlohmann::optional comparison")
CHECK_FALSE(opt_int() != opt_int(nullopt));
CHECK_FALSE(opt_int(0) != opt_int(0));

CHECK_FALSE(opt_int() != std_opt_int());
CHECK_FALSE(opt_int(0) != std_opt_int(0));
CHECK(opt_int(0) != std_opt_int(1));

CHECK_FALSE(std_opt_int() != opt_int());
CHECK_FALSE(std_opt_int(0) != opt_int(0));
CHECK(std_opt_int(0) != opt_int(1));

CHECK(opt_int(0) > nullopt);
CHECK(opt_int(1) > opt_int(0));
CHECK_FALSE(nullopt > opt_int(0));
CHECK_FALSE(opt_int(0) > opt_int(1));

CHECK(opt_int(0) > std_opt_int());
CHECK(std_opt_int(0) > opt_int());

CHECK(opt_int(0) >= nullopt);
CHECK(opt_int(1) >= opt_int(0));
CHECK_FALSE(nullopt >= opt_int(0));
CHECK_FALSE(opt_int(0) >= opt_int(1));

CHECK(opt_int(0) >= std_opt_int());
CHECK(std_opt_int(0) >= opt_int());

CHECK(nullopt < opt_int(0));
CHECK(opt_int(0) < opt_int(1));
CHECK_FALSE(opt_int(0) < nullopt);
CHECK_FALSE(opt_int(1) < opt_int(0));

CHECK_FALSE(opt_int(0) < std_opt_int());
CHECK_FALSE(std_opt_int(0) < opt_int());

CHECK(nullopt <= opt_int(0));
CHECK(opt_int(0) <= opt_int(1));
CHECK_FALSE(opt_int(0) <= nullopt);
CHECK_FALSE(opt_int(1) <= opt_int(0));

CHECK_FALSE(opt_int(0) <= std_opt_int());
CHECK_FALSE(std_opt_int(0) <= opt_int());
}

TEST_CASE("nlohmann::optional constructors")
Expand Down

0 comments on commit 7745f59

Please sign in to comment.