From 586fb6d6320a28b0573ffb6bf14dcc140d677c0c Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 27 Apr 2013 20:33:59 -0700 Subject: 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 Reviewed-by: Olivier Goffart --- tests/auto/corelib/tools/qstring/tst_qstring.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests/auto/corelib') 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() -- cgit v1.2.3