swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 1 | #include <QCoreApplication> |
| 2 | #include <QDebug> |
| 3 | |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame^] | 4 | #include "Matcher.h" |
| 5 | #include "Token.h" |
| 6 | |
| 7 | int g_numFailed = 0; |
| 8 | |
| 9 | void 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 | |
| 18 | int 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 | |
| 28 | void 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 | |
swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 56 | int main(int argc, char *argv[]) { |
| 57 | QCoreApplication a(argc, argv); |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame^] | 58 | |
| 59 | runTests(); |
| 60 | |
| 61 | return testResults(); |
swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 62 | } |