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

Side by Side Diff: test/tests/typedObjects.js

Issue 6273062181797888: Issue 505 - [Typed objects] Implement array helper methods (Closed)
Patch Set: Created May 19, 2014, 3:21 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/typedObjects/arrayTypes.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 673
674 array5.release(); 674 array5.release();
675 array5 = uint32Array(9); 675 array5 = uint32Array(9);
676 equal(array5.arrayBufferIndex, 5, "Buffer indexes for large arrays aren't re used"); 676 equal(array5.arrayBufferIndex, 5, "Buffer indexes for large arrays aren't re used");
677 equal(array5.arrayByteOffset, 0, "Large array is allocated at zero offset"); 677 equal(array5.arrayByteOffset, 0, "Large array is allocated at zero offset");
678 678
679 for (let array of [array1, array2, array3, array4, array5]) 679 for (let array of [array1, array2, array3, array4, array5])
680 array.release(); 680 array.release();
681 }); 681 });
682 682
683 test("Array methods", function()
684 {
685 let {uint32} = require("typedObjects");
686 let uint32Array = uint32.Array({
687 toJS: function()
688 {
689 let result = [];
690 for (let i = 0; i < this.length; i++)
691 result.push(this.get(i));
692 return result;
693 }
694 });
695
696 let array = uint32Array();
697 deepEqual(array.toJS(), [], "Array is initially empty");
698
699 throws(() => array.pop(), "Popping from an empty array throws");
700 throws(() => array.shift(), "Shifting an empty array throws");
701
702 equal(array.push(5), 1, "Pushing returns new length");
703 equal(array.push(2, 8), 3, "Pushing returns new length");
704 deepEqual(array.toJS(), [5, 2, 8], "Pushing three elements succeeded");
705
706 equal(array.pop(), 8, "Popping returns element");
707 equal(array.pop(), 2, "Popping returns element");
708 deepEqual(array.toJS(), [5], "Popping two elements succeeded");
709
710 equal(array.unshift(4), 2, "Unshifting returns new length");
711 equal(array.unshift(0, 9), 4, "Unshifting returns new length");
712 deepEqual(array.toJS(), [0, 9, 4, 5], "Unshifting two elements succeeded");
713
714 equal(array.shift(), 0, "Shifting returns element");
715 equal(array.shift(), 9, "Shifting returns element");
716 deepEqual(array.toJS(), [4, 5], "Shifting by two elements succeeded");
717
718 array.splice(1, 0, 1, 7);
719 deepEqual(array.toJS(), [4, 1, 7, 5], "Using splice to insert elements succe eded");
720 array.splice(2, 1);
721 deepEqual(array.toJS(), [4, 1, 5], "Using splice to remove an element succee ded");
722 array.splice(0, 2, 9);
723 deepEqual(array.toJS(), [9, 5], "Using splice to remove two elements and ins ert one succeeded");
724 array.splice(1, 1, 4, 2, 7);
725 deepEqual(array.toJS(), [9, 4, 2, 7], "Using splice to remove one element an d insert two succeeded");
726 array.splice(3, 8);
727 deepEqual(array.toJS(), [9, 4, 2], "Using splice with excessive count parame ter succeeded");
728 array.splice(9, 1, 3);
729 deepEqual(array.toJS(), [9, 4, 2, 3], "Using splice with excessive index par ameter succeeded");
730 array.splice(-2, 1, 7);
731 deepEqual(array.toJS(), [9, 4, 7, 3], "Using splice with negative index para meter succeeded");
732 array.splice(-20, 2, 10);
733 deepEqual(array.toJS(), [10, 7, 3], "Using splice with excessive negative in dex parameter succeeded");
734 });
735
683 test("String type", function() 736 test("String type", function()
684 { 737 {
685 let {string} = require("typedObjects"); 738 let {string} = require("typedObjects");
686 739
687 let s1 = string(); 740 let s1 = string();
688 ok(s1, "String created without parameters"); 741 ok(s1, "String created without parameters");
689 equal(s1.length, 0, "String length is zero"); 742 equal(s1.length, 0, "String length is zero");
690 equal(s1.toString(), "", "JavaScript representation is empty string"); 743 equal(s1.toString(), "", "JavaScript representation is empty string");
691 s1.release(); 744 s1.release();
692 745
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 s11.release(); 802 s11.release();
750 803
751 let s12 = string(s8, 4); 804 let s12 = string(s8, 4);
752 ok(s12, "String created as typed substring without length parameter"); 805 ok(s12, "String created as typed substring without length parameter");
753 equal(s12.length, 10, "String length set correctly"); 806 equal(s12.length, 10, "String length set correctly");
754 equal(s12.toString(), "longstring", "JavaScript representation is correct"); 807 equal(s12.toString(), "longstring", "JavaScript representation is correct");
755 s12.release(); 808 s12.release();
756 s8.release(); 809 s8.release();
757 }); 810 });
758 })(); 811 })();
OLDNEW
« no previous file with comments | « lib/typedObjects/arrayTypes.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld