diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2014-01-20 14:32:26 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-20 16:10:33 +0100 |
commit | 19025ab3422658ab27415cee99336d88a4ae19fa (patch) | |
tree | 48be7ca9b74b73ce5f68b265ac4bdb485dc827c3 /tests/auto/qml/qjsengine/tst_qjsengine.cpp | |
parent | 46ffd0e470b66e8cc501d5caf4ba92022d1ee474 (diff) |
Add support for deprecated RegExp (constructor) properties
These were apparently part of ancient EcmaScript specs, aren't even listed
anymore in any recent spec (not even as deprecated), but apparently they
are part of what the web supports as well as previous versions of Qml. So
this patch implements them.
Task-number: QTBUG-36244
Change-Id: I1b9ea7ea09fceb6a486f615837a71e41aae12de4
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tests/auto/qml/qjsengine/tst_qjsengine.cpp')
-rw-r--r-- | tests/auto/qml/qjsengine/tst_qjsengine.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp index a1662b495c..ba99b34935 100644 --- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp @@ -148,6 +148,8 @@ private slots: void functionDeclarationsInConditionals(); void arrayPop_QTBUG_35979(); + + void regexpLastMatch(); }; tst_QJSEngine::tst_QJSEngine() @@ -2705,6 +2707,68 @@ void tst_QJSEngine::arrayPop_QTBUG_35979() QCOMPARE(result.toString(), QString("1,3")); } +void tst_QJSEngine::regexpLastMatch() +{ + QJSEngine eng; + + QCOMPARE(eng.evaluate("RegExp.input").toString(), QString()); + + QJSValue hasProperty; + + for (int i = 1; i < 9; ++i) { + hasProperty = eng.evaluate("RegExp.hasOwnProperty(\"$" + QString::number(i) + "\")"); + QVERIFY(hasProperty.isBool()); + QVERIFY(hasProperty.toBool()); + } + + hasProperty = eng.evaluate("RegExp.hasOwnProperty(\"$0\")"); + QVERIFY(hasProperty.isBool()); + QVERIFY(!hasProperty.toBool()); + + hasProperty = eng.evaluate("RegExp.hasOwnProperty(\"$10\")"); + QVERIFY(!hasProperty.toBool()); + + hasProperty = eng.evaluate("RegExp.hasOwnProperty(\"lastMatch\")"); + QVERIFY(hasProperty.toBool()); + hasProperty = eng.evaluate("RegExp.hasOwnProperty(\"$&\")"); + QVERIFY(hasProperty.toBool()); + + QJSValue result = eng.evaluate("" + "var re = /h(el)l(o)/\n" + "var text = \"blah hello world\"\n" + "text.match(re)\n"); + QVERIFY(!result.isError()); + QJSValue match = eng.evaluate("RegExp.$1"); + QCOMPARE(match.toString(), QString("el")); + match = eng.evaluate("RegExp.$2"); + QCOMPARE(match.toString(), QString("o")); + for (int i = 3; i <= 9; ++i) { + match = eng.evaluate("RegExp.$" + QString::number(i)); + QVERIFY(match.isString()); + QCOMPARE(match.toString(), QString()); + } + QCOMPARE(eng.evaluate("RegExp.input").toString(), QString("blah hello world")); + QCOMPARE(eng.evaluate("RegExp.lastParen").toString(), QString("o")); + QCOMPARE(eng.evaluate("RegExp.leftContext").toString(), QString("blah ")); + QCOMPARE(eng.evaluate("RegExp.rightContext").toString(), QString(" world")); + + QCOMPARE(eng.evaluate("RegExp.lastMatch").toString(), QString("hello")); + + result = eng.evaluate("" + "var re = /h(ello)/\n" + "var text = \"hello\"\n" + "text.match(re)\n"); + QVERIFY(!result.isError()); + match = eng.evaluate("RegExp.$1"); + QCOMPARE(match.toString(), QString("ello")); + for (int i = 2; i <= 9; ++i) { + match = eng.evaluate("RegExp.$" + QString::number(i)); + QVERIFY(match.isString()); + QCOMPARE(match.toString(), QString()); + } + +} + QTEST_MAIN(tst_QJSEngine) #include "tst_qjsengine.moc" |