#include "input/TextRules.h" #include using namespace Qt::StringLiterals; class TestTextRules : public QObject { Q_OBJECT private Q_SLOTS: void startsSentence_data() { QTest::addColumn("text"); QTest::addColumn("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"