diff options
author | Chris Adams <christopher.adams@nokia.com> | 2011-11-21 10:02:35 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-11-29 04:34:11 +0100 |
commit | c648598a8ba8bf72b5d556211df877578d5f5b64 (patch) | |
tree | 47cfe3fe9ac48fdd609ac51e5351de925da7dec2 /tests | |
parent | 5587885a71b962eb9443c1f83e3e477490bd691d (diff) |
Add indexed deleter to sequence wrapper, implement length setter
Previously, elements could not be deleted from sequences directly
without reassignment. This commit adds an indexed deleter which
allows elements to be deleted by specifying an index. A deleted
element will be replaced with a default-constructed element in the
sequence (slight departure from ECMA262r3 which specifies that it
should be replaced with Undefined).
This commit also implements the length property setter according
to the requirements on Array [[Put]] by ECMA262r3 which allows
removal of elements from a sequence (required for proper behaviour
of Array.prototype methods such as splice() and pop()).
Task-number: QTBUG-22808
Change-Id: I62511b3edc2ec35f92d2a2bd719278e129c98547
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.array.qml | 41 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp | 12 |
2 files changed, 47 insertions, 6 deletions
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.array.qml b/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.array.qml index 5eaa225708..52abda1e55 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.array.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.array.qml @@ -79,26 +79,67 @@ Item { if (msco.intListProperty[199] != 200) success = false; if (msco.intListProperty.length != 200) success = false; + // test indexed deleter + msco.intListProperty = [ 1, 2, 3, 4, 5 ]; + delete msco.intListProperty[-1]; + expected = [ 1, 2, 3, 4, 5 ]; + if (msco.intListProperty.toString() != expected.toString()) success = false; + delete msco.intListProperty[0]; + expected = [ 0, 2, 3, 4, 5 ]; + if (msco.intListProperty.toString() != expected.toString()) success = false; + delete msco.intListProperty[2]; + expected = [ 0, 2, 0, 4, 5 ]; + if (msco.intListProperty.toString() != expected.toString()) success = false; + delete msco.intListProperty[7]; + expected = [ 0, 2, 0, 4, 5 ]; + if (msco.intListProperty.toString() != expected.toString()) success = false; + // other operations are defined on the array prototype; see if they work. + + // splice msco.intListProperty = [ 0, 1, 2, 3, 4, 5, 6, 7 ]; msco.intListProperty.splice(1,3, 33, 44, 55, 66); expected = [ 0, 33, 44, 55, 66, 4, 5, 6, 7 ]; if (msco.intListProperty.toString() != expected.toString()) success = false; + msco.intListProperty = [ 0, 1, 2, 3, 4, 5, 6, 7 ]; + msco.intListProperty.splice(1, 3); + expected = [ 0, 4, 5, 6, 7 ]; + if (msco.intListProperty.toString() != expected.toString()) success = false; msco.qrealListProperty = [ 0.1, 1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1 ]; msco.qrealListProperty.splice(1,3, 33.33, 44.44, 55.55, 66.66); expected = [ 0.1, 33.33, 44.44, 55.55, 66.66, 4.1, 5.1, 6.1, 7.1 ]; if (msco.qrealListProperty.toString() != expected.toString()) success = false; + msco.qrealListProperty = [ 0.1, 1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1 ]; + msco.qrealListProperty.splice(1,3); + expected = [ 0.1, 4.1, 5.1, 6.1, 7.1 ]; + if (msco.qrealListProperty.toString() != expected.toString()) success = false; msco.boolListProperty = [ false, true, true, false, false, true, false, true ]; msco.boolListProperty.splice(1,3, false, true, false, false); expected = [ false, false, true, false, false, false, true, false, true ]; if (msco.boolListProperty.toString() != expected.toString()) success = false; + msco.boolListProperty = [ false, true, true, false, false, true, false, true ]; + msco.boolListProperty.splice(1,3); + expected = [ false, false, true, false, true ]; + if (msco.boolListProperty.toString() != expected.toString()) success = false; msco.stringListProperty = [ "one", "two", "three", "four", "five", "six", "seven", "eight" ]; msco.stringListProperty.splice(1,3, "nine", "ten", "eleven", "twelve"); expected = [ "one", "nine", "ten", "eleven", "twelve", "five", "six", "seven", "eight" ]; if (msco.stringListProperty.toString() != expected.toString()) success = false; + msco.stringListProperty = [ "one", "two", "three", "four", "five", "six", "seven", "eight" ]; + msco.stringListProperty.splice(0,3); + expected = [ "four", "five", "six", "seven", "eight" ]; + if (msco.stringListProperty.toString() != expected.toString()) success = false; + + // pop + msco.intListProperty = [ 0, 1, 2, 3, 4, 5, 6, 7 ]; + var poppedVal = msco.intListProperty.pop(); + expected = [ 0, 1, 2, 3, 4, 5, 6 ]; + if (msco.intListProperty.toString() != expected.toString()) success = false; + expected = 7; + if (poppedVal != expected) success = false; } property variant variantList: [ 1, 2, 3, 4, 5 ]; diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 426f9663d2..a95d4380fa 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -4225,14 +4225,14 @@ void tst_qdeclarativeecmascript::sequenceConversionArray() QDeclarativeComponent component(&engine, qmlFile); QObject *object = component.create(); QVERIFY(object != 0); - //QMetaObject::invokeMethod(object, "indexedAccess"); - //QVERIFY(object->property("success").toBool()); - //QMetaObject::invokeMethod(object, "arrayOperations"); - //QVERIFY(object->property("success").toBool()); + QMetaObject::invokeMethod(object, "indexedAccess"); + QVERIFY(object->property("success").toBool()); + QMetaObject::invokeMethod(object, "arrayOperations"); + QVERIFY(object->property("success").toBool()); QMetaObject::invokeMethod(object, "testEqualitySemantics"); QVERIFY(object->property("success").toBool()); - //QMetaObject::invokeMethod(object, "testReferenceDeletion"); - //QCOMPARE(object->property("referenceDeletion").toBool(), true); + QMetaObject::invokeMethod(object, "testReferenceDeletion"); + QCOMPARE(object->property("referenceDeletion").toBool(), true); delete object; } |