Files
Library/tests/standalone/Core/FlagsReflect.cpp
T

34 lines
970 B
C++

// @requires-reflection
#include <Void/Core/Flags.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <string>
namespace
{
enum class Perm : unsigned { Read = 1, Write = 2, Exec = 4 };
} // namespace
// @tag reflection
Void::Testing::Test flags_to_string_lists_set_names()
{
const auto f = Void::Flags::Flags<Perm>{Perm::Read} | Perm::Exec;
Void::Testing::expect_eq(Void::Flags::to_string(f),
std::string{"Read|Exec"});
Void::Testing::expect_eq(Void::Flags::to_string(Void::Flags::Flags<Perm>{}),
std::string{});
}
// @tag reflection
Void::Testing::Test flags_parse_names()
{
const auto f = Void::Flags::parse<Perm>("Read|Write");
Void::Testing::expect(f.test(Perm::Read));
Void::Testing::expect(f.test(Perm::Write));
Void::Testing::expect(!f.test(Perm::Exec));
// unknown names ignored
const auto g = Void::Flags::parse<Perm>("Exec|Nope");
Void::Testing::expect(g.test(Perm::Exec) && !g.test(Perm::Read));
}