diff options
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qml/qjsengine/tst_qjsengine.cpp | 27 | ||||
-rw-r--r-- | tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp | 2 |
2 files changed, 28 insertions, 1 deletions
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp index 85b4484403..911da1b20c 100644 --- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp @@ -212,6 +212,9 @@ private slots: void deleteInsideForIn(); + void functionToString_data(); + void functionToString(); + signals: void testSignal(); }; @@ -4220,6 +4223,30 @@ void tst_QJSEngine::deleteInsideForIn() QCOMPARE(iterationCount.toInt(), 4); } +void tst_QJSEngine::functionToString_data() +{ + QTest::addColumn<QString>("source"); + QTest::addColumn<QString>("expectedString"); + + QTest::newRow("named function") << QString::fromLatin1("function f() {}; f.toString()") + << QString::fromLatin1("function f() { [code] }"); + QTest::newRow("anonymous function") << QString::fromLatin1("(function() {}).toString()") + << QString::fromLatin1("function() { [code] }"); +} + +// Tests that function.toString() prints the function's name. +void tst_QJSEngine::functionToString() +{ + QFETCH(QString, source); + QFETCH(QString, expectedString); + + QJSEngine engine; + engine.installExtensions(QJSEngine::AllExtensions); + QJSValue evaluationResult = engine.evaluate(source); + QVERIFY(!evaluationResult.isError()); + QCOMPARE(evaluationResult.toString(), expectedString); +} + QTEST_MAIN(tst_QJSEngine) #include "tst_qjsengine.moc" diff --git a/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp b/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp index 5391e19f50..40a9295e50 100644 --- a/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp +++ b/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp @@ -75,7 +75,7 @@ void tst_qqmlconsole::logging() QTest::ignoreMessage(QtDebugMsg, "{\"a\":\"hello\",\"d\":1}"); QTest::ignoreMessage(QtDebugMsg, "undefined"); QTest::ignoreMessage(QtDebugMsg, "12"); - QTest::ignoreMessage(QtDebugMsg, "function() { [code] }"); + QTest::ignoreMessage(QtDebugMsg, "function e() { [code] }"); QTest::ignoreMessage(QtDebugMsg, "true"); // Printing QML object prints out the class/type of QML object with the memory address // QTest::ignoreMessage(QtDebugMsg, "QtObject_QML_0(0xABCD..)"); |