Testing module

Signed-off-by: faumaray <faumaray@gmail.com>
This commit is contained in:
faumaray committed 2026-04-29 22:49:33 +03:00
1 parent 4fc129fb7e
commit e7186f17f0
42 files changed
+1816 -413

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
#pragma once
#include <Void/Testing/Assert.hpp>
#include <string>
#include <functional>
#include <memory>
namespace Void::TestingMock {
template<typename T> class Matcher { public: virtual ~Matcher() = default; virtual bool matches(const T& value) const = 0; virtual std::string describe() const = 0; };
template<typename T> class EqMatcher : public Matcher<T> { T expected_; public: explicit EqMatcher(T expected) : expected_(std::move(expected)) {} bool matches(const T& v) const override { return v == expected_; } std::string describe() const override { return std::format("eq({})", Void::Testing::Detail::repr(expected_)); } };
template<typename T> class AnyMatcher : public Matcher<T> { public: bool matches(const T&) const override { return true; } std::string describe() const override { return "_"; } };
template<typename T> auto Eq(T v) { return std::make_unique<EqMatcher<T>>(std::move(v)); }
template<typename T> auto _() { return std::make_unique<AnyMatcher<T>>(); }
template<typename T>
class MatcherHolder {
std::unique_ptr<Matcher<T>> matcher_;
public:
MatcherHolder() : matcher_(std::make_unique<AnyMatcher<T>>()) {}
MatcherHolder(std::unique_ptr<Matcher<T>> m) : matcher_(std::move(m)) {}
MatcherHolder(T exact_value) : matcher_(std::make_unique<EqMatcher<T>>(std::move(exact_value))) {}
bool matches(const T& v) const { return matcher_->matches(v); }
std::string describe() const { return matcher_->describe(); }
};
} // namespace Void::TestingMock