Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/tests/typedObjects.js

Issue 29323484: Issue 507 - Implement lightweight array.slice() method (Closed)
Patch Set: Created Aug. 12, 2015, 4:41 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/typedObjects/objectTypes.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/tests/typedObjects.js
diff --git a/test/tests/typedObjects.js b/test/tests/typedObjects.js
index 83ee6c4dd0ed0a08d78a6a62d7e5975af2f3d523..fea95d5327c32fe9f598ac62d8b976644c7b89ac 100644
--- a/test/tests/typedObjects.js
+++ b/test/tests/typedObjects.js
@@ -17,6 +17,7 @@
(function()
{
+ "use strict";
module("Typed objects");
test("Math utilities", function()
@@ -711,6 +712,81 @@
equal(array.unshift(0, 9), 4, "Unshifting returns new length");
deepEqual(array.toJS(), [0, 9, 4, 5], "Unshifting two elements succeeded");
+ let sliced = array.slice(1, 3);
+ deepEqual(sliced.toJS(), [9, 4], "Slicing an array works");
+ sliced.release();
+ deepEqual(sliced.toJS(), [], "Releasing a sliced array works");
+ deepEqual(array.toJS(), [0, 9, 4, 5], "Releasing a sliced array does not release the parent");
+ array.release();
+ deepEqual(array.toJS(), [], "Releasing a previously sliced array works");
+
+ array = uint32Array();
+ array.push(0, 9, 4, 5);
+ sliced = array.slice();
+ array.release();
+ deepEqual(sliced.toJS(), [0, 9, 4, 5], "Releasing a parent does not release a sliced array");
+ sliced.release();
+ deepEqual(sliced.toJS(), [], "Releasing a parent and sliced array does release a sliced array");
+
+ array = uint32Array();
+ array.push(0, 9, 4, 5);
+ sliced = array.slice(3);
+ deepEqual(sliced.toJS(), [5], "Array slicing adjusts byteOffset correctly");
+ deepEqual(array.toJS(), [0, 9, 4, 5], "Slicing an array does not alter the original array");
+ sliced.release();
+
+ sliced = array.slice(0);
+ deepEqual(sliced.toJS(), [0, 9, 4, 5], "Slicing can be used as 'copy'");
+ sliced.release();
+
+ sliced = array.slice(-2);
+ deepEqual(sliced.toJS(), [4, 5], "Slicing supports negative start index");
+ sliced.release();
+
+ sliced = array.slice(-10);
+ deepEqual(sliced.toJS(), [0, 9, 4, 5], "Slicing supports excessive negative start index");
+ sliced.release();
+
+ sliced = array.slice(-3, -1);
+ deepEqual(sliced.toJS(), [9, 4], "Slicing supports negative start and end index");
+ sliced.release();
+
+ sliced = array.slice(-10, -100);
+ deepEqual(sliced.toJS(), [], "Slicing supports excessive negative start and end index");
+ sliced.release();
+
+ sliced = array.slice(1, -1);
+ deepEqual(sliced.toJS(), [9, 4], "Slicing supports negative end index");
+ sliced.release();
+
+ sliced = array.slice(1, 3);
+ deepEqual(sliced.toJS(), [9, 4], "Slicing supports positive end index");
+ array.set(1, 8);
+ deepEqual(sliced.toJS(), [8, 4], "Sliced arrays rely on shared data");
+ sliced.release();
+
+ sliced = array.slice(1, 300);
+ deepEqual(sliced.toJS(), [8, 4, 5], "Slicing supports excessive positive end index");
+ sliced.release();
+
+ sliced = array.slice(100, 300);
+ deepEqual(sliced.toJS(), [], "Slicing supports excessive positive start and end index");
+ sliced.release();
+
+ sliced = array.slice();
+ throws(() => array.length = 1, "Length of sliced array is read only");
+ throws(() => sliced.length = 1, "Length of sliced array result is read only");
+
+ equal(array._refCount, 2, "Slicing an array increases it's refcount");
+ equal(sliced._refCount, 1, "Sliced arrays have a seperate refcount");
+ sliced.release();
+ equal(array._refCount, 1, "Releasing a sliced array decreases parent's refcount");
+
+ array = uint32Array();
+ array.push(0, 9, 4, 5, 6, 7);
+ array.length = 4;
+ equal(array.length, 4, "Length of non-sliced array is writable");
+
equal(array.shift(), 0, "Shifting returns element");
equal(array.shift(), 9, "Shifting returns element");
deepEqual(array.toJS(), [4, 5], "Shifting by two elements succeeded");
« no previous file with comments | « lib/typedObjects/objectTypes.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld