153 stringToInt.insert(bar, 456); |
155 stringToInt.insert(bar, 456); |
154 QCOMPARE(stringToInt.value(bar), 456); |
156 QCOMPARE(stringToInt.value(bar), 456); |
155 QCOMPARE(stringToInt.value(foo), 123); |
157 QCOMPARE(stringToInt.value(foo), 123); |
156 } |
158 } |
157 |
159 |
|
160 void tst_QScriptString::toArrayIndex_data() |
|
161 { |
|
162 QTest::addColumn<QString>("input"); |
|
163 QTest::addColumn<bool>("expectSuccess"); |
|
164 QTest::addColumn<quint32>("expectedIndex"); |
|
165 QTest::newRow("foo") << QString::fromLatin1("foo") << false << quint32(0xffffffff); |
|
166 QTest::newRow("empty") << QString::fromLatin1("") << false << quint32(0xffffffff); |
|
167 QTest::newRow("0") << QString::fromLatin1("0") << true << quint32(0); |
|
168 QTest::newRow("00") << QString::fromLatin1("00") << false << quint32(0xffffffff); |
|
169 QTest::newRow("1") << QString::fromLatin1("1") << true << quint32(1); |
|
170 QTest::newRow("123") << QString::fromLatin1("123") << true << quint32(123); |
|
171 QTest::newRow("-1") << QString::fromLatin1("-1") << false << quint32(0xffffffff); |
|
172 QTest::newRow("0a") << QString::fromLatin1("0a") << false << quint32(0xffffffff); |
|
173 QTest::newRow("0x1") << QString::fromLatin1("0x1") << false << quint32(0xffffffff); |
|
174 QTest::newRow("01") << QString::fromLatin1("01") << false << quint32(0xffffffff); |
|
175 QTest::newRow("4294967294") << QString::fromLatin1("4294967294") << true << quint32(0xfffffffe); |
|
176 QTest::newRow("4294967295") << QString::fromLatin1("4294967295") << false << quint32(0xffffffff); |
|
177 } |
|
178 |
|
179 void tst_QScriptString::toArrayIndex() |
|
180 { |
|
181 QFETCH(QString, input); |
|
182 QFETCH(bool, expectSuccess); |
|
183 QFETCH(quint32, expectedIndex); |
|
184 QScriptEngine engine; |
|
185 for (int x = 0; x < 2; ++x) { |
|
186 bool isArrayIndex; |
|
187 bool *ptr = (x == 0) ? &isArrayIndex : (bool*)0; |
|
188 quint32 result = engine.toStringHandle(input).toArrayIndex(ptr); |
|
189 if (x == 0) |
|
190 QCOMPARE(isArrayIndex, expectSuccess); |
|
191 QCOMPARE(result, expectedIndex); |
|
192 } |
|
193 } |
|
194 |
158 QTEST_MAIN(tst_QScriptString) |
195 QTEST_MAIN(tst_QScriptString) |
159 #include "tst_qscriptstring.moc" |
196 #include "tst_qscriptstring.moc" |