summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2013-04-27 20:33:59 -0700
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-04-29 16:56:58 +0200
commit586fb6d6320a28b0573ffb6bf14dcc140d677c0c (patch)
tree4a1d30c9de370d9bfd7fb2dd6189e0482a643ea3 /tests
parent62eb4d7f3d8557fb4545b251b12d87679062cbaf (diff)
Add some extra tests for QString::arg
Test locale-based formatting of numbers when we pass field width, base and fill characters. This now tests the fact that we replace a '0' for the locale's zero character. Change-Id: Ib872a592fd9a754e3ef11495a9497a6947056631 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/tools/qstring/tst_qstring.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
index 0a1af0a058..e7ad52a257 100644
--- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
@@ -4082,8 +4082,22 @@ void tst_QString::arg()
QCOMPARE( QString("%2 %L1").arg(12345.6789).arg(12345.6789),
QString("12345.7 12.345,7") );
+ QCOMPARE( QString("[%2] [%L1]").arg(12345.6789, 9).arg(12345.6789, 9),
+ QString("[ 12345.7] [ 12.345,7]") );
+ QCOMPARE( QString("[%2] [%L1]").arg(12345.6789, 9, 'g', 7).arg(12345.6789, 9, 'g', 7),
+ QString("[ 12345.68] [12.345,68]") );
+ QCOMPARE( QString("[%2] [%L1]").arg(12345.6789, 10, 'g', 7, QLatin1Char('0')).arg(12345.6789, 10, 'g', 7, QLatin1Char('0')),
+ QString("[0012345.68] [012.345,68]") );
+
QCOMPARE( QString("%2 %L1").arg(123456789).arg(123456789),
QString("123456789 123.456.789") );
+ QCOMPARE( QString("[%2] [%L1]").arg(123456789, 12).arg(123456789, 12),
+ QString("[ 123456789] [ 123.456.789]") );
+ QCOMPARE( QString("[%2] [%L1]").arg(123456789, 13, 10, QLatin1Char('0')).arg(123456789, 12, 10, QLatin1Char('0')),
+ QString("[000123456789] [00123.456.789]") );
+ QCOMPARE( QString("[%2] [%L1]").arg(123456789, 13, 16, QLatin1Char('0')).arg(123456789, 12, 16, QLatin1Char('0')),
+ QString("[0000075bcd15] [00000075bcd15]") );
+
QCOMPARE( QString("%L2 %L1 %3").arg(12345.7).arg(123456789).arg('c'),
QString("123.456.789 12.345,7 c") );
@@ -4125,6 +4139,14 @@ void tst_QString::arg()
QCOMPARE(QString("%1").arg(1000., 3, 'g', -1, QChar('x')), QString("1000"));
QCOMPARE(QString("%1").arg(-1., 3, 'g', -1, QChar('x')), QString("x-1"));
QCOMPARE(QString("%1").arg(-100., 3, 'g', -1, QChar('x')), QString("-100"));
+
+ QLocale::setDefault(QString("ar"));
+ QCOMPARE( QString("%L1").arg(12345.6789, 10, 'g', 7, QLatin1Char('0')),
+ QString::fromUtf8("\xd9\xa0\xd9\xa1\xd9\xa2\xd9\xac\xd9\xa3\xd9\xa4\xd9\xa5\xd9\xab\xd9\xa6\xd9\xa8") ); // "٠١٢٬٣٤٥٫٦٨"
+ QCOMPARE( QString("%L1").arg(123456789, 13, 10, QLatin1Char('0')),
+ QString("\xd9\xa0\xd9\xa0\xd9\xa1\xd9\xa2\xd9\xa3\xd9\xac\xd9\xa4\xd9\xa5\xd9\xa6\xd9\xac\xd9\xa7\xd9\xa8\xd9\xa9") ); // ٠٠١٢٣٬٤٥٦٬٧٨٩
+
+ QLocale::setDefault(QLocale::system());
}
void tst_QString::number()