aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_querycompleter.cpp
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-08-03 20:41:21 +0200
committerDanilo M. <danix@danix.xyz>2026-08-04 12:54:04 +0200
commitffe78f9c626ddb8d661930f911e8c1622cddfabb (patch)
tree2412840f58cc407592e68fe1324e16372b1d7fa1 /tests/test_querycompleter.cpp
parentba3931bc84fc046484949a99b3d8d2562f4ca2b2 (diff)
downloadqtmaildir-ffe78f9c626ddb8d661930f911e8c1622cddfabb.tar.gz
qtmaildir-ffe78f9c626ddb8d661930f911e8c1622cddfabb.zip
feat(completion): recognise value context after a prefix
The replace span covers the value only, so accepting a completion never overwrites the prefix that selected it.
Diffstat (limited to 'tests/test_querycompleter.cpp')
-rw-r--r--tests/test_querycompleter.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/test_querycompleter.cpp b/tests/test_querycompleter.cpp
index 9278a1e..4621b19 100644
--- a/tests/test_querycompleter.cpp
+++ b/tests/test_querycompleter.cpp
@@ -29,6 +29,10 @@ private slots:
void bareWordCompletesPrefix();
void wordAfterOperatorCompletesPrefix();
void prefixReplaceSpanCoversTheWord();
+ void colonSwitchesToValue();
+ void valueReplaceSpanExcludesThePrefix();
+ void prefixIsLowercased();
+ void emptyValueAfterColonStillCompletes();
};
void TestQueryCompleter::emptyTextCompletesPrefix()
@@ -62,5 +66,42 @@ void TestQueryCompleter::prefixReplaceSpanCoversTheWord()
QCOMPARE(ctx.replaceLength, 2);
}
+void TestQueryCompleter::colonSwitchesToValue()
+{
+ const QString text = QStringLiteral("tag:sho");
+ const CompletionContext ctx = completionContext(text, text.size());
+ QCOMPARE(ctx.kind, CompletionContext::Value);
+ QCOMPARE(ctx.prefix, QStringLiteral("tag"));
+ QCOMPARE(ctx.stem, QStringLiteral("sho"));
+}
+
+void TestQueryCompleter::valueReplaceSpanExcludesThePrefix()
+{
+ // Accepting must overwrite "sho" only, never "tag:".
+ const QString text = QStringLiteral("tag:sho");
+ const CompletionContext ctx = completionContext(text, text.size());
+ QCOMPARE(ctx.replaceFrom, 4);
+ QCOMPARE(ctx.replaceLength, 3);
+}
+
+void TestQueryCompleter::prefixIsLowercased()
+{
+ const QString text = QStringLiteral("TAG:sho");
+ const CompletionContext ctx = completionContext(text, text.size());
+ QCOMPARE(ctx.prefix, QStringLiteral("tag"));
+}
+
+void TestQueryCompleter::emptyValueAfterColonStillCompletes()
+{
+ // "tag:" with the cursor at the end offers every tag.
+ const QString text = QStringLiteral("tag:");
+ const CompletionContext ctx = completionContext(text, text.size());
+ QCOMPARE(ctx.kind, CompletionContext::Value);
+ QCOMPARE(ctx.prefix, QStringLiteral("tag"));
+ QCOMPARE(ctx.stem, QString());
+ QCOMPARE(ctx.replaceFrom, 4);
+ QCOMPARE(ctx.replaceLength, 0);
+}
+
QTEST_MAIN(TestQueryCompleter)
#include "test_querycompleter.moc"