2021-09-11 14:41:18 +02:00
|
|
|
#pragma once
|
2021-09-11 14:40:53 +02:00
|
|
|
|
2021-09-11 14:41:18 +02:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2021-09-11 14:40:53 +02:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
#include <hex/pattern_language/patterns/pattern.hpp>
|
2021-09-11 14:41:18 +02:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
#define TEST(name) (hex::test::TestPattern *)new hex::test::TestPattern##name()
|
2021-09-11 23:13:49 +02:00
|
|
|
|
2021-09-11 14:41:18 +02:00
|
|
|
namespace hex::test {
|
|
|
|
|
2021-09-11 23:13:49 +02:00
|
|
|
using namespace pl;
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
enum class Mode
|
|
|
|
{
|
2021-09-11 23:13:49 +02:00
|
|
|
Succeeding,
|
|
|
|
Failing
|
|
|
|
};
|
|
|
|
|
2021-09-11 14:41:18 +02:00
|
|
|
class TestPattern {
|
|
|
|
public:
|
2021-09-11 23:13:49 +02:00
|
|
|
explicit TestPattern(const std::string &name, Mode mode = Mode::Succeeding) : m_mode(mode) {
|
|
|
|
TestPattern::s_tests.insert({ name, this });
|
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
virtual ~TestPattern() = default;
|
2021-09-11 14:41:18 +02:00
|
|
|
|
|
|
|
template<typename T>
|
2022-02-27 23:25:39 +01:00
|
|
|
static std::unique_ptr<T> create(const std::string &typeName, const std::string &varName, auto... args) {
|
|
|
|
auto pattern = std::make_unique<T>(nullptr, args...);
|
2021-09-11 14:41:18 +02:00
|
|
|
pattern->setTypeName(typeName);
|
|
|
|
pattern->setVariableName(varName);
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
return std::move(pattern);
|
2021-09-11 14:41:18 +02:00
|
|
|
}
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
[[nodiscard]] virtual std::string getSourceCode() const = 0;
|
2021-09-11 14:41:18 +02:00
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
[[nodiscard]] virtual const std::vector<std::unique_ptr<Pattern>> &getPatterns() const final { return this->m_patterns; }
|
|
|
|
virtual void addPattern(std::unique_ptr<Pattern> &&pattern) final {
|
|
|
|
this->m_patterns.push_back(std::move(pattern));
|
2021-09-11 14:41:18 +02:00
|
|
|
}
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
[[nodiscard]] auto failing() {
|
2021-09-11 23:13:49 +02:00
|
|
|
this->m_mode = Mode::Failing;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
[[nodiscard]] Mode getMode() {
|
2021-09-11 23:13:49 +02:00
|
|
|
return this->m_mode;
|
|
|
|
}
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
[[nodiscard]] static auto &getTests() {
|
2021-09-11 23:13:49 +02:00
|
|
|
return TestPattern::s_tests;
|
|
|
|
}
|
|
|
|
|
2021-09-11 14:41:18 +02:00
|
|
|
private:
|
2022-02-27 23:25:39 +01:00
|
|
|
std::vector<std::unique_ptr<Pattern>> m_patterns;
|
2021-09-11 23:13:49 +02:00
|
|
|
Mode m_mode;
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
static inline std::map<std::string, TestPattern *> s_tests;
|
2021-09-11 14:41:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|