summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-02-18 15:03:22 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-02-18 15:03:22 (GMT)
commit26c367b9b9e220056af3a47eced366d6d187a890 (patch)
tree64862462a066629e55ef0cbc29b2e9ade1e67622 /tests
parent4145038db1e87f3438233ea7822a3a81f657c334 (diff)
downloadQt-26c367b9b9e220056af3a47eced366d6d187a890.zip
Qt-26c367b9b9e220056af3a47eced366d6d187a890.tar.gz
Qt-26c367b9b9e220056af3a47eced366d6d187a890.tar.bz2
optimize qstring::simplified()
- avoid detaching if the string is already simplified - avoid calling isSpace() multiple times on the same character Reviewed-by: joao
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qstring/tst_qstring.cpp50
1 files changed, 43 insertions, 7 deletions
diff --git a/tests/auto/qstring/tst_qstring.cpp b/tests/auto/qstring/tst_qstring.cpp
index c9b3436..9c9524a 100644
--- a/tests/auto/qstring/tst_qstring.cpp
+++ b/tests/auto/qstring/tst_qstring.cpp
@@ -120,6 +120,7 @@ private slots:
void operator_eqeq_nullstring();
void operator_smaller();
void insert();
+ void simplified_data();
void simplified();
void trimmed();
void toLower();
@@ -1592,16 +1593,51 @@ void tst_QString::trimmed()
QCOMPARE(a.trimmed(),(QString)"a");
}
+void tst_QString::simplified_data()
+{
+ QTest::addColumn<QString>("full" );
+ QTest::addColumn<QString>("simple" );
+
+ QTest::newRow("null") << QString() << QString();
+ QTest::newRow("empty") << "" << "";
+ QTest::newRow("one char") << "a" << "a";
+ QTest::newRow("one word") << "foo" << "foo";
+ QTest::newRow("chars trivial") << "a b" << "a b";
+ QTest::newRow("words trivial") << "foo bar" << "foo bar";
+ QTest::newRow("allspace") << " \t\v " << "";
+ QTest::newRow("char trailing") << "a " << "a";
+ QTest::newRow("char trailing tab") << "a\t" << "a";
+ QTest::newRow("char multitrailing") << "a " << "a";
+ QTest::newRow("char multitrailing tab") << "a \t" << "a";
+ QTest::newRow("char leading") << " a" << "a";
+ QTest::newRow("char leading tab") << "\ta" << "a";
+ QTest::newRow("char multileading") << " a" << "a";
+ QTest::newRow("char multileading tab") << "\t a" << "a";
+ QTest::newRow("chars apart") << "a b" << "a b";
+ QTest::newRow("words apart") << "foo bar" << "foo bar";
+ QTest::newRow("enclosed word") << " foo \t " << "foo";
+ QTest::newRow("enclosed chars apart") << " a b " << "a b";
+ QTest::newRow("enclosed words apart") << " foo bar " << "foo bar";
+ QTest::newRow("chars apart posttab") << "a \tb" << "a b";
+ QTest::newRow("chars apart pretab") << "a\t b" << "a b";
+ QTest::newRow("many words") << " just some random\ttext here" << "just some random text here";
+}
+
void tst_QString::simplified()
{
- QString j;
- j.simplified();
+ QFETCH(QString, full);
+ QFETCH(QString, simple);
- QString a;
- a = "a ";
- QCOMPARE(a.simplified(),(QString)"a");
- a=" a b ";
- QCOMPARE(a.simplified(),(QString)"a b");
+ QString result = full.simplified();
+ if (simple.isNull()) {
+ QVERIFY2(result.isNull(), qPrintable("'" + full + "' did not yield null: " + result));
+ } else if (simple.isEmpty()) {
+ QVERIFY2(result.isEmpty() && !result.isNull(), qPrintable("'" + full + "' did not yield empty: " + result));
+ } else {
+ QCOMPARE(result, simple);
+ if (full == simple)
+ QVERIFY(result.isSharedWith(full));
+ }
}
void tst_QString::insert()