From cd9103f7f2514b6380aa460ac9d6454e132be307 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Fri, 27 Jan 2012 11:19:50 +1000 Subject: [PATCH] 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 Reviewed-by: Robin Burchell --- src/declarative/qml/qdeclarativecompiler.cpp | 3 +++ .../qdeclarativeecmascript/data/regExp.2.qml | 7 +++++++ .../tst_qdeclarativeecmascript.cpp | 24 ++++++++++++++++------ 3 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/regExp.2.qml diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 8bf1faa..8a2d6ab 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 0000000..68cca57 --- /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 7ac00b3..678d367 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(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(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(component.create()); + QVERIFY(!object); + QCOMPARE(component.errorString(), err); + } } static inline bool evaluate_error(QV8Engine *engine, v8::Handle o, const char *source) -- 2.7.4