Improve QRegExp property literal assignment error message
authorChris Adams <christopher.adams@nokia.com>
Fri, 27 Jan 2012 01:19:50 +0000 (11:19 +1000)
committerQt by Nokia <qt-info@nokia.com>
Fri, 27 Jan 2012 07:42:06 +0000 (08:42 +0100)
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>

src/declarative/qml/qdeclarativecompiler.cpp
tests/auto/declarative/qdeclarativeecmascript/data/regExp.2.qml [new file with mode: 0644]
tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp

index 8bf1faa..8a2d6ab 100644 (file)
@@ -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 (file)
index 0000000..68cca57
--- /dev/null
@@ -0,0 +1,7 @@
+import Qt.test 1.0
+
+MyQmlObject{
+    id: obj
+    objectName: "obj"
+    regExp: "[a-zA-z]"
+}
index 7ac00b3..678d367 100644 (file)
@@ -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)