Files
sloposk/tests/tst_textrules.cpp
T
ericek111andClaude Opus 5.5 d44aab7772 Keep the user's shift; trust the text guess less
- A tapped shift (on or off) survives the field re-reporting its context:
  it lasts until a character is typed, the hint changes or a field is focused
- An input-method reset forgets the guessed text and pending dead key, so
  double-space can't delete a character the keyboard never saw
- Fields that state typing preferences only get capitals if they ask
- Trackpad moves in fields without surrounding text make the guess unknown;
  Backspace removes a whole grapheme cluster from it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 10:13:27 +02:00

57 lines
2.0 KiB
C++

#include "input/TextRules.h"
#include <QTest>
using namespace Qt::StringLiterals;
class TestTextRules : public QObject
{
Q_OBJECT
private Q_SLOTS:
void startsSentence_data()
{
QTest::addColumn<QString>("text");
QTest::addColumn<bool>("expected");
QTest::newRow("empty") << QString() << true;
QTest::newRow("after period and space") << u"Hi. "_s << true;
QTest::newRow("after question, two spaces") << u"Why? "_s << true;
QTest::newRow("after newline") << u"Hi\n"_s << true;
QTest::newRow("only spaces") << u" "_s << true;
QTest::newRow("period without space") << u"Hi."_s << false;
QTest::newRow("mid sentence") << u"Hi there "_s << false;
QTest::newRow("after comma") << u"Hi, "_s << false;
QTest::newRow("mid word") << u"Hel"_s << false;
}
void startsSentence()
{
QFETCH(QString, text);
QFETCH(bool, expected);
QCOMPARE(TextRules::startsSentence(text), expected);
}
void doubleSpacePeriod()
{
QVERIFY(TextRules::wantsDoubleSpacePeriod(u"word "_s));
QVERIFY(TextRules::wantsDoubleSpacePeriod(u"42 "_s));
QVERIFY(!TextRules::wantsDoubleSpacePeriod(u"word. "_s));
QVERIFY(!TextRules::wantsDoubleSpacePeriod(u"word "_s));
QVERIFY(!TextRules::wantsDoubleSpacePeriod(u" "_s));
}
void deletion()
{
QCOMPARE(TextRules::withoutLastCharacter(u"ab"_s), u"a");
QCOMPARE(TextRules::withoutLastCharacter(u"a👍"_s), u"a");
QCOMPARE(TextRules::withoutLastCharacter(u"ae\u0301"_s), u"a"); // e + combining acute
QCOMPARE(TextRules::withoutLastCharacter(u"a👍🏽"_s), u"a"); // with a skin tone
QCOMPARE(TextRules::withoutLastCharacter(QString()), QString());
QCOMPARE(TextRules::withoutLastWord(u"one two "_s), u"one ");
QCOMPARE(TextRules::withoutLastWord(u"one"_s), QString());
}
};
QTEST_GUILESS_MAIN(TestTextRules)
#include "tst_textrules.moc"