aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2012-01-27 11:19:50 +1000
committerQt by Nokia <qt-info@nokia.com>2012-01-27 08:42:06 +0100
commitcd9103f7f2514b6380aa460ac9d6454e132be307 (patch)
tree0d5f6edb396bb65172be2d7b6341f242e1d3c884
parentfc973c6ca45bd55122b7e2af8d38c4c11ab044a1 (diff)
Improve QRegExp property literal assignment error message
Previously, the error message given when a string literal was assigned to a regular expression property was not very helpful. This commit adds a better error message. Task-number: QTBUG-23068 Change-Id: Ia57b6434b9cdf009429e7b55edab4ab5c2b91c2a Reviewed-by: Michael Brasser <michael.brasser@nokia.com> Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
-rw-r--r--src/declarative/qml/qdeclarativecompiler.cpp3
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/regExp.2.qml7
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp24
3 files changed, 28 insertions, 6 deletions
diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp
index 8bf1faa2f1..8a2d6abb7b 100644
--- a/src/declarative/qml/qdeclarativecompiler.cpp
+++ b/src/declarative/qml/qdeclarativecompiler.cpp
@@ -257,6 +257,9 @@ bool QDeclarativeCompiler::testLiteralAssignment(QDeclarativeScript::Property *p
case QVariant::Url:
if (!v->value.isString()) COMPILE_EXCEPTION(v, tr("Invalid property assignment: url expected"));
break;
+ case QVariant::RegExp:
+ COMPILE_EXCEPTION(v, tr("Invalid property assignment: regular expression expected; use /pattern/ syntax"));
+ break;
case QVariant::UInt:
{
bool ok = v->value.isNumber();
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/regExp.2.qml b/tests/auto/declarative/qdeclarativeecmascript/data/regExp.2.qml
new file mode 100644
index 0000000000..68cca5733b
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/regExp.2.qml
@@ -0,0 +1,7 @@
+import Qt.test 1.0
+
+MyQmlObject{
+ id: obj
+ objectName: "obj"
+ regExp: "[a-zA-z]"
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
index 7ac00b3abe..678d367ee6 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
@@ -1781,14 +1781,26 @@ void tst_qdeclarativeecmascript::dynamicCreationOwnership()
QCOMPARE(dtorCount, expectedDtorCount);
}
-//QTBUG-9367
void tst_qdeclarativeecmascript::regExpBug()
{
- QDeclarativeComponent component(&engine, testFileUrl("regExp.qml"));
- MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create());
- QVERIFY(object != 0);
- QCOMPARE(object->regExp().pattern(), QLatin1String("[a-zA-z]"));
- delete object;
+ //QTBUG-9367
+ {
+ QDeclarativeComponent component(&engine, testFileUrl("regExp.qml"));
+ MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create());
+ QVERIFY(object != 0);
+ QCOMPARE(object->regExp().pattern(), QLatin1String("[a-zA-z]"));
+ delete object;
+ }
+
+ //QTBUG-23068
+ {
+ QString err = QString(QLatin1String("%1:6 Invalid property assignment: regular expression expected; use /pattern/ syntax\n")).arg(testFileUrl("regExp.2.qml").toString());
+ QDeclarativeComponent component(&engine, testFileUrl("regExp.2.qml"));
+ QTest::ignoreMessage(QtWarningMsg, "QDeclarativeComponent: Component is not ready");
+ MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create());
+ QVERIFY(!object);
+ QCOMPARE(component.errorString(), err);
+ }
}
static inline bool evaluate_error(QV8Engine *engine, v8::Handle<v8::Object> o, const char *source)