forked from WerWolv/PatternLanguage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pattern.hpp
More file actions
70 lines (49 loc) · 1.91 KB
/
Copy pathtest_pattern.hpp
File metadata and controls
70 lines (49 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#pragma once
#include <string>
#include <vector>
#include <pl/patterns/pattern.hpp>
#define TEST(name) (pl::test::TestPattern *)new pl::test::TestPattern##name(&s_evaluator)
namespace pl::test {
using namespace pl::ptrn;
enum class Mode
{
Succeeding,
Failing
};
class TestPattern {
public:
explicit TestPattern(core::Evaluator *evaluator, const std::string &name, Mode mode = Mode::Succeeding) : m_evaluator(evaluator), m_mode(mode) {
TestPattern::s_tests.insert({ name, this });
}
PatternLanguage *m_runtime;
virtual void setup() {};
virtual ~TestPattern() = default;
template<typename T>
std::shared_ptr<T> create(const std::string &typeName, const std::string &varName, auto... args) {
auto pattern = std::make_shared<T>(m_evaluator, args...);
pattern->setTypeName(typeName);
pattern->setVariableName(varName);
return pattern;
}
[[nodiscard]] virtual std::string getSourceCode() const = 0;
[[nodiscard]] virtual const std::vector<std::shared_ptr<ptrn::Pattern>> &getPatterns() const final { return this->m_patterns; }
virtual void addPattern(std::shared_ptr<ptrn::Pattern> &&pattern) final {
this->m_patterns.push_back(std::move(pattern));
}
[[nodiscard]] Mode getMode() {
return this->m_mode;
}
[[nodiscard]] static auto &getTests() {
return TestPattern::s_tests;
}
[[nodiscard]] virtual bool runChecks(const std::vector<std::shared_ptr<ptrn::Pattern>> &patterns) const {
wolv::util::unused(patterns);
return true;
}
private:
std::vector<std::shared_ptr<ptrn::Pattern>> m_patterns;
core::Evaluator *m_evaluator;
Mode m_mode;
static inline std::map<std::string, TestPattern *> s_tests;
};
}