blob: a3436824f8507c45ea078fd1ecbe362b3a78c3fa [file] [log] [blame]
swissChili7babd922021-12-02 22:46:48 -08001#include <QCoreApplication>
2#include <QDebug>
3
swissChili3e98c062021-12-04 22:07:38 -08004#include "Matcher.h"
5#include "Token.h"
6
7int g_numFailed = 0;
8
9void printResult(const QString &test, bool shouldBe, const MatchResult &result) {
10 if (result.success != shouldBe) {
11 g_numFailed++;
12 qDebug() << "TEST FAILS:";
13 }
14
15 qDebug() << "MatchResult" << test << result.success;
16}
17
18int testResults() {
19 if (g_numFailed == 0) {
20 qDebug() << "ALL TESTS SUCCEEDED";
21 } else {
22 qDebug() << g_numFailed << "TESTS FAILED";
23 }
24
25 return g_numFailed;
26}
27
28void runTests() {
29 printResult("a = a", true, match({Token('a')}, {Token('a')}, VarContext()));
30
31 LTok sameTwo = {Token('s', "a"), Token('s', "a")};
32 printResult("s.a s.a = aa", true, match({Token('a'), Token('a')}, sameTwo, VarContext()));
33 printResult("s.a s.a = ab", false, match({Token('a'), Token('b')}, sameTwo, VarContext()));
34
35 LTok sameStartEnd = {
36 Token('s', "a"),
37 Token('e', "middle"),
38 Token('s', "a")
39 };
40 printResult("s.a e.middle s.a = aea", true,
41 match({
42 Token('a'), Token('e'), Token('a')
43 }, sameStartEnd, VarContext()));
44
45 printResult("s.a e.middle s.a = aef Hi a", true,
46 match({
47 Token('a'), Token('e'), Token('f'), Token("Hi"), Token('a')
48 }, sameStartEnd, VarContext()));
49
50 printResult("s.a e.middle s.a = aef Hi c", false,
51 match({
52 Token('a'), Token('e'), Token('f'), Token("Hi"), Token('c')
53 }, sameStartEnd, VarContext()));
54}
55
swissChili7babd922021-12-02 22:46:48 -080056int main(int argc, char *argv[]) {
57 QCoreApplication a(argc, argv);
swissChili3e98c062021-12-04 22:07:38 -080058
59 runTests();
60
61 return testResults();
swissChili7babd922021-12-02 22:46:48 -080062}