Changeset View
Changeset View
Standalone View
Standalone View
autotests/test_highlighter.cpp
| Show All 18 Lines | |||||
| 19 | { | 19 | { | ||
| 20 | Q_OBJECT | 20 | Q_OBJECT | ||
| 21 | 21 | | |||
| 22 | private Q_SLOTS: | 22 | private Q_SLOTS: | ||
| 23 | void initTestCase(); | 23 | void initTestCase(); | ||
| 24 | void testEnglish(); | 24 | void testEnglish(); | ||
| 25 | void testFrench(); | 25 | void testFrench(); | ||
| 26 | void testMultipleLanguages(); | 26 | void testMultipleLanguages(); | ||
| 27 | void testForceLanguage(); | ||||
| 27 | }; | 28 | }; | ||
| 28 | 29 | | |||
| 29 | void HighlighterTest::initTestCase() | 30 | void HighlighterTest::initTestCase() | ||
| 30 | { | 31 | { | ||
| 31 | QStandardPaths::setTestModeEnabled(true); | 32 | QStandardPaths::setTestModeEnabled(true); | ||
| 32 | 33 | | |||
| 33 | Speller speller(QStringLiteral("en_US")); | 34 | Speller speller(QStringLiteral("en_US")); | ||
| 34 | if (!speller.availableBackends().contains(QLatin1String("ASpell"))) { | 35 | if (!speller.availableBackends().contains(QLatin1String("ASpell"))) { | ||
| ▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | 78 | { | |||
| 90 | cursor.setPosition(37); | 91 | cursor.setPosition(37); | ||
| 91 | const QStringList suggestionsForDict = highlighter.suggestionsForWord(QStringLiteral("dictionnare"), cursor); | 92 | const QStringList suggestionsForDict = highlighter.suggestionsForWord(QStringLiteral("dictionnare"), cursor); | ||
| 92 | 93 | | |||
| 93 | // THEN | 94 | // THEN | ||
| 94 | QVERIFY2(suggestionsForBnjour.contains(QLatin1String("Bonjour")), qPrintable(suggestionsForBnjour.join(QLatin1Char(',')))); | 95 | QVERIFY2(suggestionsForBnjour.contains(QLatin1String("Bonjour")), qPrintable(suggestionsForBnjour.join(QLatin1Char(',')))); | ||
| 95 | QVERIFY2(suggestionsForDict.contains(QLatin1String("dictionnaire")), qPrintable(suggestionsForDict.join(QLatin1Char(',')))); | 96 | QVERIFY2(suggestionsForDict.contains(QLatin1String("dictionnaire")), qPrintable(suggestionsForDict.join(QLatin1Char(',')))); | ||
| 96 | } | 97 | } | ||
| 97 | 98 | | |||
| 99 | void HighlighterTest::testForceLanguage() | ||||
| 100 | { | ||||
| 101 | // GIVEN | ||||
| 102 | QPlainTextEdit textEdit; | ||||
| 103 | textEdit.setPlainText(QString::fromLatin1(s_frenchSentence)); | ||||
| 104 | Sonnet::Highlighter highlighter(&textEdit); | ||||
| 105 | highlighter.setCurrentLanguage(QStringLiteral("en")); | ||||
| 106 | QVERIFY(highlighter.spellCheckerFound()); | ||||
| 107 | QVERIFY(highlighter.autoDetectLanguageDisabled()); | ||||
| 108 | highlighter.rehighlight(); | ||||
| 109 | QCOMPARE(highlighter.currentLanguage(), QStringLiteral("en")); | ||||
| 110 | QTextCursor cursor(textEdit.document()); | ||||
| 111 | | ||||
| 112 | // WHEN | ||||
| 113 | cursor.setPosition(0); | ||||
| 114 | const QStringList suggestionsForBnjour = highlighter.suggestionsForWord(QStringLiteral("Bnjour"), cursor); | ||||
| 115 | cursor.setPosition(37); | ||||
| 116 | const QStringList suggestionsForDict = highlighter.suggestionsForWord(QStringLiteral("dictionnare"), cursor); | ||||
| 117 | | ||||
| 118 | // THEN | ||||
| 119 | QVERIFY2(!suggestionsForBnjour.contains(QLatin1String("Bonjour")), qPrintable(suggestionsForBnjour.join(QLatin1Char(',')))); | ||||
| 120 | QVERIFY2(!suggestionsForDict.contains(QLatin1String("dictionnaire")), qPrintable(suggestionsForDict.join(QLatin1Char(',')))); | ||||
| 121 | } | ||||
| 122 | | ||||
| 98 | void HighlighterTest::testMultipleLanguages() | 123 | void HighlighterTest::testMultipleLanguages() | ||
| 99 | { | 124 | { | ||
| 100 | // GIVEN | 125 | // GIVEN | ||
| 101 | QPlainTextEdit textEdit; | 126 | QPlainTextEdit textEdit; | ||
| 102 | const QString englishSentence = QString::fromLatin1(s_englishSentence) + QLatin1Char('\n'); | 127 | const QString englishSentence = QString::fromLatin1(s_englishSentence) + QLatin1Char('\n'); | ||
| 103 | textEdit.setPlainText(englishSentence + QString::fromLatin1(s_frenchSentence)); | 128 | textEdit.setPlainText(englishSentence + QString::fromLatin1(s_frenchSentence)); | ||
| 104 | Sonnet::Highlighter highlighter(&textEdit); | 129 | Sonnet::Highlighter highlighter(&textEdit); | ||
| 105 | highlighter.rehighlight(); | 130 | highlighter.rehighlight(); | ||
| Show All 22 Lines | |||||