summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-01-25 13:22:55 +0100
committerMarc Mutz <marc.mutz@kdab.com>2016-02-19 18:16:38 +0000
commit1da975cdc5297ddde584981c4bf301b288ccaca9 (patch)
tree188ad7a00c8f1f8a53f627a59f7664013ce603fc /tests/auto/corelib/tools
parent342acf66fe640c72e1a7c8837ba5cdefae06f9c9 (diff)
QLatin1String: add at()/op[]/mid()/right()/left()
QLatin1String can be used as a string-view-like type. When attempting to do so in uic, mid() and at() were found to be missing. Added the others for completeness. Use the new functions in uic, for which they were originally conceived. [ChangeLog][QtCore][QLatin1String] Added at(), operator[](), mid(), right(), left(). Change-Id: I4cfe3e9ed1157dedee754b2012d9678fe72b161e Reviewed-by: Milian Wolff <milian.wolff@kdab.com> Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r--tests/auto/corelib/tools/qlatin1string/tst_qlatin1string.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qlatin1string/tst_qlatin1string.cpp b/tests/auto/corelib/tools/qlatin1string/tst_qlatin1string.cpp
index 1295a36c1a..3c22770fba 100644
--- a/tests/auto/corelib/tools/qlatin1string/tst_qlatin1string.cpp
+++ b/tests/auto/corelib/tools/qlatin1string/tst_qlatin1string.cpp
@@ -35,10 +35,40 @@ class tst_QLatin1String : public QObject
Q_OBJECT
private Q_SLOTS:
+ void at();
+ void midLeftRight();
void nullString();
void emptyString();
};
+
+void tst_QLatin1String::at()
+{
+ const QLatin1String l1("Hello World");
+ QCOMPARE(l1.at(0), QLatin1Char('H'));
+ QCOMPARE(l1.at(l1.size() - 1), QLatin1Char('d'));
+ QCOMPARE(l1[0], QLatin1Char('H'));
+ QCOMPARE(l1[l1.size() - 1], QLatin1Char('d'));
+}
+
+void tst_QLatin1String::midLeftRight()
+{
+ const QLatin1String l1("Hello World");
+ QCOMPARE(l1.mid(0), l1);
+ QCOMPARE(l1.mid(0, l1.size()), l1);
+ QCOMPARE(l1.left(l1.size()), l1);
+ QCOMPARE(l1.right(l1.size()), l1);
+
+ QCOMPARE(l1.mid(6), QLatin1String("World"));
+ QCOMPARE(l1.mid(6, 5), QLatin1String("World"));
+ QCOMPARE(l1.right(5), QLatin1String("World"));
+
+ QCOMPARE(l1.mid(6, 1), QLatin1String("W"));
+ QCOMPARE(l1.right(5).left(1), QLatin1String("W"));
+
+ QCOMPARE(l1.left(5), QLatin1String("Hello"));
+}
+
void tst_QLatin1String::nullString()
{
// default ctor