diff options
| author | Danilo M. <danix@danix.xyz> | 2026-10-31 11:41:08 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-17 10:26:18 +0100 |
| commit | 4161ac9a31e160c0dbdd8b1998a1895fe95dcf93 (patch) | |
| tree | b3cfc27e16cae1a7d649bc6648108f56db09996c /tests | |
| parent | c608ce2bfb5e4a6aba319e23d4a8bd299ebb4a3b (diff) | |
| download | qtmaildir-4161ac9a31e160c0dbdd8b1998a1895fe95dcf93.tar.gz qtmaildir-4161ac9a31e160c0dbdd8b1998a1895fe95dcf93.zip | |
feat: build the query for what a tag change would move
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_searchterm.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/test_searchterm.cpp b/tests/test_searchterm.cpp index 7a0dfd7..b704529 100644 --- a/tests/test_searchterm.cpp +++ b/tests/test_searchterm.cpp @@ -18,6 +18,7 @@ #include <QtTest> +#include "config.h" #include "searchterm.h" /// The query grammar of the right-click search actions. @@ -30,6 +31,9 @@ class TestSearchTerm : public QObject { Q_OBJECT private slots: + void changesNarrowsToMessagesTheTagsWouldMove(); + void changesKeepsADisjunctionInsideItsScope(); + void changesWithNothingToDoMatchesNothing(); void quotesAPlainValue(); void escapesEmbeddedQuotes(); void collapsesWhitespaceAndNewlines(); @@ -185,5 +189,45 @@ void TestSearchTerm::excludeWithNothingToExcludeLeavesTheQuery() QVERIFY(SearchTerm::exclude(QString(), QString()).isEmpty()); } +void TestSearchTerm::changesNarrowsToMessagesTheTagsWouldMove() +{ + // Item 212. A message already carrying every added tag and none of the + // removed ones would not change, so it must not be counted or written. + QCOMPARE(SearchTerm::changes(QStringLiteral("from:a@example.org"), + { QStringLiteral("promo") }, + { QStringLiteral("inbox") }), + QStringLiteral("(from:a@example.org) AND " + "(not tag:promo or tag:inbox)")); + QCOMPARE(SearchTerm::changes(QStringLiteral("from:a@example.org"), + { QStringLiteral("x"), QStringLiteral("y") }, + {}), + QStringLiteral("(from:a@example.org) AND " + "(not tag:x or not tag:y)")); + QCOMPARE(SearchTerm::changes(QStringLiteral("from:a@example.org"), {}, + { QStringLiteral("inbox") }), + QStringLiteral("(from:a@example.org) AND (tag:inbox)")); +} + +void TestSearchTerm::changesKeepsADisjunctionInsideItsScope() +{ + // `a or b AND c` binds as `a or (b AND c)`, which would write to every + // message matching `a` whatever its tags. extend() parenthesises both. + QCOMPARE(SearchTerm::changes(QStringLiteral("from:a@example.org or " + "from:b@example.org"), + { QStringLiteral("promo") }, {}), + QStringLiteral("(from:a@example.org or from:b@example.org) AND " + "(not tag:promo)")); +} + +void TestSearchTerm::changesWithNothingToDoMatchesNothing() +{ + // notmuch reads an EMPTY query as "match everything". A caller writing + // through this must never be handed one. + QCOMPARE(SearchTerm::changes(QString(), { QStringLiteral("x") }, {}), + Config::matchNothingQuery()); + QCOMPARE(SearchTerm::changes(QStringLiteral("from:a@example.org"), {}, {}), + Config::matchNothingQuery()); +} + QTEST_MAIN(TestSearchTerm) #include "test_searchterm.moc" |
