Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Chris Adams authored and Qt by Nokia committed Jan 27, 2012
1 parent fc973c6 commit cd9103f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/declarative/qml/qdeclarativecompiler.cpp
Expand Up @@ -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();
Expand Down
@@ -0,0 +1,7 @@
import Qt.test 1.0

MyQmlObject{
id: obj
objectName: "obj"
regExp: "[a-zA-z]"
}
Expand Up @@ -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)
Expand Down

0 comments on commit cd9103f

Please sign in to comment.