OLD | NEW |
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 Loading... |
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, 2, 7); |
| 731 deepEqual(array.toJS(), [7, 2, 3], "Using splice with negative index paramet
er succeeded"); |
| 732 }); |
| 733 |
683 test("String type", function() | 734 test("String type", function() |
684 { | 735 { |
685 let {string} = require("typedObjects"); | 736 let {string} = require("typedObjects"); |
686 | 737 |
687 let s1 = string(); | 738 let s1 = string(); |
688 ok(s1, "String created without parameters"); | 739 ok(s1, "String created without parameters"); |
689 equal(s1.length, 0, "String length is zero"); | 740 equal(s1.length, 0, "String length is zero"); |
690 equal(s1.toString(), "", "JavaScript representation is empty string"); | 741 equal(s1.toString(), "", "JavaScript representation is empty string"); |
691 s1.release(); | 742 s1.release(); |
692 | 743 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 s11.release(); | 800 s11.release(); |
750 | 801 |
751 let s12 = string(s8, 4); | 802 let s12 = string(s8, 4); |
752 ok(s12, "String created as typed substring without length parameter"); | 803 ok(s12, "String created as typed substring without length parameter"); |
753 equal(s12.length, 10, "String length set correctly"); | 804 equal(s12.length, 10, "String length set correctly"); |
754 equal(s12.toString(), "longstring", "JavaScript representation is correct"); | 805 equal(s12.toString(), "longstring", "JavaScript representation is correct"); |
755 s12.release(); | 806 s12.release(); |
756 s8.release(); | 807 s8.release(); |
757 }); | 808 }); |
758 })(); | 809 })(); |
OLD | NEW |