tst_QHash: verify that {}-style initialization drops duplicates
No actual reason for this test, except my curiority. Then again, it's good to have this check, too. Also checks that the last entry in the init_list "wins", which is not how std:: containers work. Change-Id: Ia284d093cd0029432372630e81657fb687b9516f Reviewed-by: Olivier Goffart <ogoffart@woboq.com>bb10
parent
b99fa32d70
commit
8b0cc9db9b
|
|
@ -1327,11 +1327,16 @@ void tst_QHash::twoArguments_qHash()
|
|||
void tst_QHash::initializerList()
|
||||
{
|
||||
#ifdef Q_COMPILER_INITIALIZER_LISTS
|
||||
QHash<int, QString> hash{{1, "hello"}, {2, "initializer_list"}};
|
||||
QHash<int, QString> hash = {{1, "bar"}, {1, "hello"}, {2, "initializer_list"}};
|
||||
QCOMPARE(hash.count(), 2);
|
||||
QVERIFY(hash[1] == "hello");
|
||||
QVERIFY(hash[2] == "initializer_list");
|
||||
|
||||
// note the difference to std::unordered_map:
|
||||
// std::unordered_map<int, QString> stdh = {{1, "bar"}, {1, "hello"}, {2, "initializer_list"}};
|
||||
// QCOMPARE(stdh.size(), 2UL);
|
||||
// QCOMPARE(stdh[1], QString("bar"));
|
||||
|
||||
QMultiHash<QString, int> multiHash{{"il", 1}, {"il", 2}, {"il", 3}};
|
||||
QCOMPARE(multiHash.count(), 3);
|
||||
QList<int> values = multiHash.values("il");
|
||||
|
|
|
|||
Loading…
Reference in New Issue