diff options
| author | Danilo M. <danix@danix.xyz> | 2026-08-24 19:54:27 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-08-24 19:54:27 +0200 |
| commit | be2534ab60d362b2f685130265f727190ccf867a (patch) | |
| tree | be7e6f2bbdd12686a2c2ac71523e34a6f7030539 /tests/test_signatures.cpp | |
| parent | 861628a75049002683f777baf837afe434d2f7db (diff) | |
| download | qtmaildir-be2534ab60d362b2f685130265f727190ccf867a.tar.gz qtmaildir-be2534ab60d362b2f685130265f727190ccf867a.zip | |
feat(signatures): splice a signature into a buffer
Both placements over one implementation. above_quote inserts before the
attribution rather than before the first quoted line: the attribution
introduces the quote and belongs with it, and a signature between the two
would read as part of the quoted message.
A buffer with no quote makes above_quote identical to end, so a new
message needs no branch of its own.
Part of item 152.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KEcn3u19xPqv6ggD15PG4c
Diffstat (limited to 'tests/test_signatures.cpp')
| -rw-r--r-- | tests/test_signatures.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/test_signatures.cpp b/tests/test_signatures.cpp index 2a75067..30085fb 100644 --- a/tests/test_signatures.cpp +++ b/tests/test_signatures.cpp @@ -31,6 +31,10 @@ private slots: void aMissingDirectoryHasNoNames(); void textIsTheFileContent(); void textOfAnUnknownNameIsEmpty(); + void insertingAtTheEndAppendsAfterADelimiter(); + void insertingAboveTheQuotePutsItBeforeTheFirstQuotedLine(); + void insertingAboveTheQuoteWithNoQuoteIsTheSameAsEnd(); + void insertingNothingLeavesTheBufferAlone(); private: /// Writes \p files as name -> content into a fresh temporary directory. @@ -100,5 +104,63 @@ void TestSignatures::textOfAnUnknownNameIsEmpty() QVERIFY(Signatures::text(dir.path(), QStringLiteral("absent")).isEmpty()); } +void TestSignatures::insertingAtTheEndAppendsAfterADelimiter() +{ + const QString buffer = QStringLiteral("Hello.\n"); + + const QString result = Signatures::replace( + buffer, QStringLiteral("Jane Doe"), {}, Signatures::Position::End); + + QCOMPARE(result, QStringLiteral("Hello.\n\n-- \nJane Doe")); +} + +void TestSignatures::insertingAboveTheQuotePutsItBeforeTheFirstQuotedLine() +{ + const QString buffer = QStringLiteral( + "My reply.\n" + "\n" + "On Mon, someone wrote:\n" + "> the original\n" + "> second line\n"); + + const QString result = Signatures::replace( + buffer, QStringLiteral("Jane Doe"), {}, + Signatures::Position::AboveQuote); + + // Before the QUOTED lines, and the attribution stays with the quote it + // introduces: it is the line the quote hangs from, not part of the reply. + QCOMPARE(result, QStringLiteral( + "My reply.\n" + "\n" + "-- \n" + "Jane Doe\n" + "\n" + "On Mon, someone wrote:\n" + "> the original\n" + "> second line\n")); +} + +void TestSignatures::insertingAboveTheQuoteWithNoQuoteIsTheSameAsEnd() +{ + const QString buffer = QStringLiteral("A new message.\n"); + + const QString above = Signatures::replace( + buffer, QStringLiteral("Jane Doe"), {}, + Signatures::Position::AboveQuote); + const QString end = Signatures::replace( + buffer, QStringLiteral("Jane Doe"), {}, Signatures::Position::End); + + QCOMPARE(above, end); +} + +void TestSignatures::insertingNothingLeavesTheBufferAlone() +{ + const QString buffer = QStringLiteral("Hello.\n"); + + QCOMPARE(Signatures::replace(buffer, QString(), {}, + Signatures::Position::End), + buffer); +} + QTEST_MAIN(TestSignatures) #include "test_signatures.moc" |
