summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qtextboundaryfinder
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2012-09-25 23:55:54 +0300
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-09-26 03:09:57 +0200
commita798b956b9786240a06142de078f56c28962a535 (patch)
tree2c96818276618e64fffda7e469ae54641c717a1b /tests/auto/corelib/tools/qtextboundaryfinder
parentaeb21c73c5e4fc585340145374800a5e285e7ab7 (diff)
QCharAttributes: add wordStart/wordEnd flags
A simple heuristic is used to detect the word beginning and ending by looking at the word break property value of surrounding characters. This behaves better than the white-spaces based implementation used before and makes it possible to tailor the default algorithm for complex scripts. BIG FAT WARNING: The QCharAttributes buffer now has to have a length of string length + 1 for the flags at end of text. Task-Id: QTBUG-6498 Change-Id: I5589b191ffde6a50d2af0c14a00430d3852c67b4 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Diffstat (limited to 'tests/auto/corelib/tools/qtextboundaryfinder')
-rw-r--r--tests/auto/corelib/tools/qtextboundaryfinder/tst_qtextboundaryfinder.cpp64
1 files changed, 63 insertions, 1 deletions
diff --git a/tests/auto/corelib/tools/qtextboundaryfinder/tst_qtextboundaryfinder.cpp b/tests/auto/corelib/tools/qtextboundaryfinder/tst_qtextboundaryfinder.cpp
index 26de0f2c5a..56409447ff 100644
--- a/tests/auto/corelib/tools/qtextboundaryfinder/tst_qtextboundaryfinder.cpp
+++ b/tests/auto/corelib/tools/qtextboundaryfinder/tst_qtextboundaryfinder.cpp
@@ -72,6 +72,7 @@ private slots:
void lineBoundaries_manual();
void fastConstructor();
+ void wordBoundaries_qtbug6498();
void isAtSoftHyphen_data();
void isAtSoftHyphen();
void thaiLineBreak();
@@ -544,6 +545,67 @@ void tst_QTextBoundaryFinder::fastConstructor()
QCOMPARE(finder.boundaryReasons(), QTextBoundaryFinder::NotAtBoundary);
}
+void tst_QTextBoundaryFinder::wordBoundaries_qtbug6498()
+{
+ // text with trailing space
+ QString text("Please test me. Finish ");
+ QTextBoundaryFinder finder(QTextBoundaryFinder::Word, text);
+
+ QCOMPARE(finder.position(), 0);
+ QVERIFY(finder.isAtBoundary());
+ QVERIFY(finder.boundaryReasons() & QTextBoundaryFinder::StartWord);
+
+ QCOMPARE(finder.toNextBoundary(), 6);
+ QCOMPARE(finder.position(), 6);
+ QVERIFY(finder.isAtBoundary());
+ QVERIFY(finder.boundaryReasons() & QTextBoundaryFinder::EndWord);
+
+ QCOMPARE(finder.toNextBoundary(), 7);
+ QCOMPARE(finder.position(), 7);
+ QVERIFY(finder.isAtBoundary());
+ QVERIFY(finder.boundaryReasons() & QTextBoundaryFinder::StartWord);
+
+ QCOMPARE(finder.toNextBoundary(), 11);
+ QCOMPARE(finder.position(), 11);
+ QVERIFY(finder.isAtBoundary());
+ QVERIFY(finder.boundaryReasons() & QTextBoundaryFinder::EndWord);
+
+ QCOMPARE(finder.toNextBoundary(), 12);
+ QCOMPARE(finder.position(), 12);
+ QVERIFY(finder.isAtBoundary());
+ QVERIFY(finder.boundaryReasons() & QTextBoundaryFinder::StartWord);
+
+ QCOMPARE(finder.toNextBoundary(), 14);
+ QCOMPARE(finder.position(), 14);
+ QVERIFY(finder.isAtBoundary());
+ QVERIFY(finder.boundaryReasons() & QTextBoundaryFinder::EndWord);
+
+ QCOMPARE(finder.toNextBoundary(), 15);
+ QCOMPARE(finder.position(), 15);
+ QVERIFY(finder.isAtBoundary());
+ QVERIFY(finder.boundaryReasons() == QTextBoundaryFinder::NotAtBoundary);
+
+ QCOMPARE(finder.toNextBoundary(), 16);
+ QCOMPARE(finder.position(), 16);
+ QVERIFY(finder.isAtBoundary());
+ QVERIFY(finder.boundaryReasons() & QTextBoundaryFinder::StartWord);
+
+ QCOMPARE(finder.toNextBoundary(), 22);
+ QCOMPARE(finder.position(), 22);
+ QVERIFY(finder.isAtBoundary());
+ QVERIFY(finder.boundaryReasons() & QTextBoundaryFinder::EndWord);
+
+ QCOMPARE(finder.toNextBoundary(), 23);
+ QCOMPARE(finder.position(), 23);
+ QVERIFY(finder.isAtBoundary());
+ QVERIFY(finder.boundaryReasons() == QTextBoundaryFinder::NotAtBoundary);
+
+ QCOMPARE(finder.toNextBoundary(), -1);
+ QCOMPARE(finder.position(), -1);
+ QVERIFY(!finder.isAtBoundary());
+ QVERIFY(finder.boundaryReasons() == QTextBoundaryFinder::NotAtBoundary);
+}
+
void tst_QTextBoundaryFinder::isAtSoftHyphen_data()
{
QTest::addColumn<QString>("testString");
@@ -568,7 +630,7 @@ void tst_QTextBoundaryFinder::isAtSoftHyphen()
QVERIFY(expectedBreakPositions.contains(i + 1));
boundaryFinder.setPosition(i + 1);
QVERIFY(boundaryFinder.isAtBoundary());
- QVERIFY(boundaryFinder.boundaryReasons() == QTextBoundaryFinder::SoftHyphen);
+ QVERIFY(boundaryFinder.boundaryReasons() & QTextBoundaryFinder::SoftHyphen);
}
}