Finish pattern matcher
diff --git a/main.cpp b/main.cpp
index 6c07880..a343682 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,8 +1,62 @@
#include <QCoreApplication>
#include <QDebug>
+#include "Matcher.h"
+#include "Token.h"
+
+int g_numFailed = 0;
+
+void printResult(const QString &test, bool shouldBe, const MatchResult &result) {
+ if (result.success != shouldBe) {
+ g_numFailed++;
+ qDebug() << "TEST FAILS:";
+ }
+
+ qDebug() << "MatchResult" << test << result.success;
+}
+
+int testResults() {
+ if (g_numFailed == 0) {
+ qDebug() << "ALL TESTS SUCCEEDED";
+ } else {
+ qDebug() << g_numFailed << "TESTS FAILED";
+ }
+
+ return g_numFailed;
+}
+
+void runTests() {
+ printResult("a = a", true, match({Token('a')}, {Token('a')}, VarContext()));
+
+ LTok sameTwo = {Token('s', "a"), Token('s', "a")};
+ printResult("s.a s.a = aa", true, match({Token('a'), Token('a')}, sameTwo, VarContext()));
+ printResult("s.a s.a = ab", false, match({Token('a'), Token('b')}, sameTwo, VarContext()));
+
+ LTok sameStartEnd = {
+ Token('s', "a"),
+ Token('e', "middle"),
+ Token('s', "a")
+ };
+ printResult("s.a e.middle s.a = aea", true,
+ match({
+ Token('a'), Token('e'), Token('a')
+ }, sameStartEnd, VarContext()));
+
+ printResult("s.a e.middle s.a = aef Hi a", true,
+ match({
+ Token('a'), Token('e'), Token('f'), Token("Hi"), Token('a')
+ }, sameStartEnd, VarContext()));
+
+ printResult("s.a e.middle s.a = aef Hi c", false,
+ match({
+ Token('a'), Token('e'), Token('f'), Token("Hi"), Token('c')
+ }, sameStartEnd, VarContext()));
+}
+
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
- qDebug() << "Hello World";
- return QCoreApplication::exec();
+
+ runTests();
+
+ return testResults();
}