diff options
| author | Danilo M. <danix@danix.xyz> | 2026-08-13 11:16:18 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-08-13 11:16:18 +0200 |
| commit | d8bb09415630c219271a01478393d43c1a2f28f0 (patch) | |
| tree | 10090e8e102cc90c767bd5ddf26e403a0d64227f /tests/test_rulequery.cpp | |
| parent | e2ec7263a65a44beb807374e8ec1a136bf5c3d88 (diff) | |
| download | qtmaildir-d8bb09415630c219271a01478393d43c1a2f28f0.tar.gz qtmaildir-d8bb09415630c219271a01478393d43c1a2f28f0.zip | |
test(rulequery): round-trip the real rule shapes
Diffstat (limited to 'tests/test_rulequery.cpp')
| -rw-r--r-- | tests/test_rulequery.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/test_rulequery.cpp b/tests/test_rulequery.cpp index 7a34403..54f9477 100644 --- a/tests/test_rulequery.cpp +++ b/tests/test_rulequery.cpp @@ -50,6 +50,7 @@ private slots: void anOrGroupWithExclusionsParses(); void anUnrepresentableQueryRejectsWhole(); void aParenBearingValueIsARowNotAShape(); + void theRuleCorpusRoundTripsByteForByte(); }; void TestRuleQuery::aSingleContainsTermCompiles() @@ -372,5 +373,43 @@ void TestRuleQuery::aParenBearingValueIsARowNotAShape() QCOMPARE(q.compile(), QStringLiteral("from:((((")); } +void TestRuleQuery::theRuleCorpusRoundTripsByteForByte() +{ + // Every query SHAPE present in a real rules file, with placeholder + // values. Verified by hand against the live file when this was written: + // all seventeen rules parsed and compiled back byte for byte, none fell + // to text mode. + // + // A compile that differs by so much as a paren would rewrite the shared + // file on the next save, which the companion tool then sees as a diff + // nobody made. + const QStringList corpus = { + QString(), // a rule with no query yet + QStringLiteral("path:\"account-one/**\""), + QStringLiteral("path:\"account-two/Inbox/topic/**\""), + QStringLiteral("subject:\"[list-name]\""), + QStringLiteral("from:notifications@service.example.org"), + QStringLiteral("from:one@jobs.example.org or " + "from:two@jobs.example.org or " + "from:three@jobs.example.org"), + QStringLiteral("from:mail.vendor.example.org and " + "subject:\"Secure link\""), + QStringLiteral("(from:vendor.example.org or from:vendor.example.net) " + "and not subject:receipt and not subject:refund " + "and not subject:EUR"), + }; + + for (const QString &query : corpus) { + const RuleQuery parsed = RuleQuery::parse(query); + QVERIFY2(parsed.parsed, qPrintable(query)); + QCOMPARE(parsed.compile(), query); + + // And the value itself round-trips, which is what the dialog's + // "was this edited" comparison depends on. + QVERIFY2(RuleQuery::parse(parsed.compile()) == parsed, + qPrintable(query)); + } +} + QTEST_MAIN(TestRuleQuery) #include "test_rulequery.moc" |
