diff options
author | Chris Adams <christopher.adams@nokia.com> | 2011-05-23 15:22:37 +1000 |
---|---|---|
committer | Chris Adams <christopher.adams@nokia.com> | 2011-05-23 17:09:50 +1000 |
commit | 9605fc786482bdd208cc3bfe92f318f7c314329c (patch) | |
tree | 1396d8e9e504722ca8ba5289707592eaf657fe0a /tests | |
parent | cca7611e260c8ba86da3b01a83e70447c1c362bc (diff) |
Support change slots for properties starting with '_'
According to ECMA-262r3, property names may begin with a letter,
underscore ('_'), dollar sign ('$'), or unicode escape sequence.
We previously supported Change slots for properties only if the
property name began with a letter; this patch adds support for
properties which begin with one or more underscore.
Task-number: QTBUG-17950
Reviewed-by: Aaron Kennedy
Change-Id: I6f28bde18a38e32c2131e0990fe0f69bda36f90e
Diffstat (limited to 'tests')
6 files changed, 118 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.1.qml b/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.1.qml new file mode 100644 index 0000000000..3182d6b4ab --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.1.qml @@ -0,0 +1,12 @@ +import QtQuick 1.0 + +Item { + property int changeCount: 0 + + property bool _nameWithUnderscore: false + + // this should error, since the first alpha isn't capitalised. + on_nameWithUnderscoreChanged: { + changeCount = changeCount + 2; + } +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.2.qml b/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.2.qml new file mode 100644 index 0000000000..50ef0b34dd --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.2.qml @@ -0,0 +1,12 @@ +import QtQuick 1.0 + +Item { + property int changeCount: 0 + + property bool ____nameWithUnderscores: false + + // this should error, since the first alpha isn't capitalised + on____nameWithUnderscoresChanged: { + changeCount = changeCount + 3; + } +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.3.qml b/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.3.qml new file mode 100644 index 0000000000..343cf91720 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.3.qml @@ -0,0 +1,12 @@ +import QtQuick 1.0 + +Item { + property int changeCount: 0 + + // invalid property name - we don't allow $ + property bool $nameWithDollarsign: false + + on$NameWithDollarsignChanged: { + changeCount = changeCount + 4; + } +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.4.qml b/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.4.qml new file mode 100644 index 0000000000..b8459875df --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.4.qml @@ -0,0 +1,12 @@ +import QtQuick 1.0 + +Item { + property int changeCount: 0 + + property bool _6nameWithUnderscoreNumber: false + + // invalid property name - the first character after an underscore must be a letter + on_6NameWithUnderscoreNumberChanged: { + changeCount = changeCount + 3; + } +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlots.qml b/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlots.qml new file mode 100644 index 0000000000..d31c89382b --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlots.qml @@ -0,0 +1,27 @@ +import QtQuick 1.0 + +Item { + property int changeCount: 0 + + property bool normalName: false + property bool _nameWithUnderscore: false + property bool ____nameWithUnderscores: false + + onNormalNameChanged: { + changeCount = changeCount + 1; + } + + on_NameWithUnderscoreChanged: { + changeCount = changeCount + 2; + } + + on____NameWithUnderscoresChanged: { + changeCount = changeCount + 3; + } + + Component.onCompleted: { + normalName = true; + _nameWithUnderscore = true; + ____nameWithUnderscores = true; + } +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index a408000a37..b2859b5b5b 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -147,6 +147,7 @@ private slots: void moduleApi(); void importScripts(); void scarceResources(); + void propertyChangeSlots(); void bug1(); void bug2(); @@ -2777,6 +2778,48 @@ void tst_qdeclarativeecmascript::scarceResources() delete object; } +void tst_qdeclarativeecmascript::propertyChangeSlots() +{ + // ensure that allowable property names are allowed and onPropertyNameChanged slots are generated correctly. + QDeclarativeComponent component(&engine, TEST_FILE("changeslots/propertyChangeSlots.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + delete object; + + // ensure that invalid property names fail properly. + QTest::ignoreMessage(QtWarningMsg, "QDeclarativeComponent: Component is not ready"); + QDeclarativeComponent e1(&engine, TEST_FILE("changeslots/propertyChangeSlotErrors.1.qml")); + QString expectedErrorString = e1.url().toString() + QLatin1String(":9:5: Cannot assign to non-existent property \"on_nameWithUnderscoreChanged\""); + QCOMPARE(e1.errors().at(0).toString(), expectedErrorString); + object = e1.create(); + QVERIFY(object == 0); + delete object; + + QTest::ignoreMessage(QtWarningMsg, "QDeclarativeComponent: Component is not ready"); + QDeclarativeComponent e2(&engine, TEST_FILE("changeslots/propertyChangeSlotErrors.2.qml")); + expectedErrorString = e2.url().toString() + QLatin1String(":9:5: Cannot assign to non-existent property \"on____nameWithUnderscoresChanged\""); + QCOMPARE(e2.errors().at(0).toString(), expectedErrorString); + object = e2.create(); + QVERIFY(object == 0); + delete object; + + QTest::ignoreMessage(QtWarningMsg, "QDeclarativeComponent: Component is not ready"); + QDeclarativeComponent e3(&engine, TEST_FILE("changeslots/propertyChangeSlotErrors.3.qml")); + expectedErrorString = e3.url().toString() + QLatin1String(":9:5: Cannot assign to non-existent property \"on$NameWithDollarsignChanged\""); + QCOMPARE(e3.errors().at(0).toString(), expectedErrorString); + object = e3.create(); + QVERIFY(object == 0); + delete object; + + QTest::ignoreMessage(QtWarningMsg, "QDeclarativeComponent: Component is not ready"); + QDeclarativeComponent e4(&engine, TEST_FILE("changeslots/propertyChangeSlotErrors.4.qml")); + expectedErrorString = e4.url().toString() + QLatin1String(":9:5: Cannot assign to non-existent property \"on_6NameWithUnderscoreNumberChanged\""); + QCOMPARE(e4.errors().at(0).toString(), expectedErrorString); + object = e4.create(); + QVERIFY(object == 0); + delete object; +} + // Test that assigning a null object works // Regressed with: df1788b4dbbb2826ae63f26bdf166342595343f4 void tst_qdeclarativeecmascript::nullObjectBinding() |