Add parenthesis matching
diff --git a/main.cpp b/main.cpp
index a343682..ebf886f 100644
--- a/main.cpp
+++ b/main.cpp
@@ -9,10 +9,15 @@
void printResult(const QString &test, bool shouldBe, const MatchResult &result) {
if (result.success != shouldBe) {
g_numFailed++;
- qDebug() << "TEST FAILS:";
+ qDebug() << "\nTEST FAILS:";
+ qDebug() << "with context" << result.context;
}
qDebug() << "MatchResult" << test << result.success;
+
+ if (result.success != shouldBe) {
+ qDebug() << "";
+ }
}
int testResults() {
@@ -28,6 +33,8 @@
void runTests() {
printResult("a = a", true, match({Token('a')}, {Token('a')}, VarContext()));
+ printResult("s.a = y", true, match({Token('y')}, {Token('s', "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()));
@@ -51,6 +58,28 @@
match({
Token('a'), Token('e'), Token('f'), Token("Hi"), Token('c')
}, sameStartEnd, VarContext()));
+
+ LTok parenthesized = {
+ Token(LTok({
+ Token('s', "a")
+ })),
+ Token('e', "Middle"),
+ Token('s', "a"),
+ };
+ LTok parenTest1 = {
+ Token(LTok({
+ Token('y')
+ })),
+ Token('f'),
+ Token("MiddleStuff"),
+ Token('y')
+ };
+
+ printResult("(s.a) e.Middle s.a = (y)f MiddleStuff y", true,
+ match(parenTest1, parenthesized, VarContext()));
+
+ printResult("(a) = (a)", true,
+ match({Token({Token('a')})}, {Token({Token('a')})}, VarContext()));
}
int main(int argc, char *argv[]) {