Skip to content

Commit

Permalink
Simplify rsl::Overload tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisThrasher committed Dec 6, 2023
1 parent fe4c165 commit 4f5d286
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions tests/overload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,14 @@
#include <variant>

TEST_CASE("rsl::Overload") {
enum class Type { INT, FLOAT, STRING } type = Type::INT;
enum class Type { INT, FLOAT, STRING };

auto const overload =
rsl::Overload{[&type](int) { type = Type::INT; }, [&type](float) { type = Type::FLOAT; },
[&type](std::string const&) { type = Type::STRING; }};
rsl::Overload{[](int) { return Type::INT; }, [](float) { return Type::FLOAT; },
[](std::string const&) { return Type::STRING; }};

auto variant = std::variant<int, float, std::string>();

variant = 12;
std::visit(overload, variant);
CHECK(type == Type::INT);

variant = 42.f;
std::visit(overload, variant);
CHECK(type == Type::FLOAT);

variant = "PickNik";
std::visit(overload, variant);
CHECK(type == Type::STRING);
CHECK(std::visit(overload, variant = 12) == Type::INT);
CHECK(std::visit(overload, variant = 42.f) == Type::FLOAT);
CHECK(std::visit(overload, variant = "PickNik") == Type::STRING);
}

0 comments on commit 4f5d286

Please sign in to comment.