Also fixes Diff/Memo/PriorityQueue from previous session: LineDiff is now an alias for Edit<string> so count_op/apply work on line diffs; Memoized uses std::apply instead of type-based get to handle duplicate arg types. 874/877 tests pass (3 are platform-gated plugin tests). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
144 lines
4.6 KiB
C++
144 lines
4.6 KiB
C++
#include <Void/Flags/Flags.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
using namespace Void::Flags;
|
|
|
|
enum class Perm : unsigned { Read = 1, Write = 2, Exec = 4 };
|
|
|
|
// ── construction ──────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test flags_default_is_empty()
|
|
{
|
|
const Flags<Perm> f;
|
|
Void::Testing::expect(f.none());
|
|
Void::Testing::expect(!f.any());
|
|
}
|
|
|
|
Void::Testing::Test flags_single_bit()
|
|
{
|
|
const Flags<Perm> f{Perm::Read};
|
|
Void::Testing::expect(f.test(Perm::Read));
|
|
Void::Testing::expect(!f.test(Perm::Write));
|
|
}
|
|
|
|
Void::Testing::Test flags_initializer_list()
|
|
{
|
|
const Flags<Perm> f{Perm::Read, Perm::Write};
|
|
Void::Testing::expect(f.test(Perm::Read));
|
|
Void::Testing::expect(f.test(Perm::Write));
|
|
Void::Testing::expect(!f.test(Perm::Exec));
|
|
}
|
|
|
|
Void::Testing::Test flags_make_flags()
|
|
{
|
|
const auto f = make_flags({Perm::Read, Perm::Exec});
|
|
Void::Testing::expect(f.test(Perm::Read));
|
|
Void::Testing::expect(!f.test(Perm::Write));
|
|
Void::Testing::expect(f.test(Perm::Exec));
|
|
}
|
|
|
|
// ── query ─────────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test flags_all()
|
|
{
|
|
const Flags<Perm> f{Perm::Read, Perm::Write};
|
|
Void::Testing::expect(f.all(Flags<Perm>{Perm::Read}));
|
|
Void::Testing::expect(f.all(Flags<Perm>{Perm::Read, Perm::Write}));
|
|
Void::Testing::expect(!f.all(Flags<Perm>{Perm::Read, Perm::Write, Perm::Exec}));
|
|
}
|
|
|
|
Void::Testing::Test flags_any_of()
|
|
{
|
|
const Flags<Perm> f{Perm::Read};
|
|
Void::Testing::expect(f.any_of(Flags<Perm>{Perm::Read, Perm::Exec}));
|
|
Void::Testing::expect(!f.any_of(Flags<Perm>{Perm::Write, Perm::Exec}));
|
|
}
|
|
|
|
// ── mutation ──────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test flags_set_unset()
|
|
{
|
|
Flags<Perm> f;
|
|
f.set(Perm::Read);
|
|
Void::Testing::expect(f.test(Perm::Read));
|
|
f.unset(Perm::Read);
|
|
Void::Testing::expect(!f.test(Perm::Read));
|
|
}
|
|
|
|
Void::Testing::Test flags_toggle()
|
|
{
|
|
Flags<Perm> f{Perm::Write};
|
|
f.toggle(Perm::Write);
|
|
Void::Testing::expect(!f.test(Perm::Write));
|
|
f.toggle(Perm::Write);
|
|
Void::Testing::expect(f.test(Perm::Write));
|
|
}
|
|
|
|
Void::Testing::Test flags_clear()
|
|
{
|
|
Flags<Perm> f{Perm::Read, Perm::Write, Perm::Exec};
|
|
f.clear();
|
|
Void::Testing::expect(f.none());
|
|
}
|
|
|
|
// ── operators ─────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test flags_or_operator()
|
|
{
|
|
const auto f = Flags<Perm>{Perm::Read} | Perm::Write;
|
|
Void::Testing::expect(f.test(Perm::Read));
|
|
Void::Testing::expect(f.test(Perm::Write));
|
|
}
|
|
|
|
Void::Testing::Test flags_and_operator()
|
|
{
|
|
const Flags<Perm> a{Perm::Read, Perm::Write};
|
|
const Flags<Perm> b{Perm::Write, Perm::Exec};
|
|
const auto c = a & b;
|
|
Void::Testing::expect(!c.test(Perm::Read));
|
|
Void::Testing::expect(c.test(Perm::Write));
|
|
Void::Testing::expect(!c.test(Perm::Exec));
|
|
}
|
|
|
|
Void::Testing::Test flags_xor_operator()
|
|
{
|
|
const Flags<Perm> a{Perm::Read, Perm::Write};
|
|
const Flags<Perm> b{Perm::Write, Perm::Exec};
|
|
const auto c = a ^ b;
|
|
Void::Testing::expect(c.test(Perm::Read));
|
|
Void::Testing::expect(!c.test(Perm::Write));
|
|
Void::Testing::expect(c.test(Perm::Exec));
|
|
}
|
|
|
|
Void::Testing::Test flags_or_two_enums()
|
|
{
|
|
const auto f = Perm::Read | Perm::Exec;
|
|
Void::Testing::expect(f.test(Perm::Read));
|
|
Void::Testing::expect(!f.test(Perm::Write));
|
|
Void::Testing::expect(f.test(Perm::Exec));
|
|
}
|
|
|
|
Void::Testing::Test flags_equality()
|
|
{
|
|
const Flags<Perm> a{Perm::Read, Perm::Write};
|
|
const Flags<Perm> b{Perm::Read, Perm::Write};
|
|
const Flags<Perm> c{Perm::Read};
|
|
Void::Testing::expect(a == b);
|
|
Void::Testing::expect(!(a == c));
|
|
}
|
|
|
|
Void::Testing::Test flags_bool_conversion()
|
|
{
|
|
const Flags<Perm> empty;
|
|
const Flags<Perm> nonempty{Perm::Read};
|
|
Void::Testing::expect(!static_cast<bool>(empty));
|
|
Void::Testing::expect(static_cast<bool>(nonempty));
|
|
}
|
|
|
|
Void::Testing::Test flags_raw_value()
|
|
{
|
|
const Flags<Perm> f{Perm::Read, Perm::Exec};
|
|
Void::Testing::expect_eq(f.raw(), unsigned{5});
|
|
}
|