9 describe("Array Methods", {
13 'should flatten a multidimensional array': function(){
14 var arr = [1,2,3,[4,5,[6,7,[8]]], [[[[[9]]]]]];
15 value_of(arr.flatten()).should_be([1,2,3,4,5,6,7,8,9]);
18 'should flatten arguments': function(){
19 var test = function(){
20 return Array.flatten(arguments);
22 value_of(test(1,2,3)).should_be([1,2,3]);
23 value_of(test([1,2,3])).should_be([1,2,3]);
24 value_of(test(1,2,[3])).should_be([1,2,3]);
29 'should filter an array': function(){
30 var array = [1,2,3,0,0,0];
31 var arr = array.concat([false, null, 4]).filter(Number.type);
32 value_of(arr).should_be(array.concat(4));
37 'should clean an array from undefined and null values': function(){
38 var array = [null, 1, 0, true, false, "foo", undefined];
39 var arr = array.clean();
40 value_of(arr).should_be([1, 0, true, false, "foo"]);
45 'should return a mapping of an array': function(){
46 var arr = [1,2,3,0,0,0].map(function(item){
50 value_of(arr).should_be([2,3,4,1,1,1]);
55 'should return true if every item matches the comparator, otherwise false': function(){
56 value_of([1,2,3,0,0,0].every(Number.type)).should_be_true();
58 value_of(['1',2,3,0].every(Number.type)).should_be_false();
63 'should return true if some of the items in the array match the comparator, otherwise false': function(){
64 value_of(['1',2,3,0].some(Number.type)).should_be_true();
66 value_of([1,2,3,0,0,0].map(String).some(Number.type)).should_be_false();
71 'should return the index of the item': function(){
72 value_of([1,2,3,0,0,0].indexOf(0)).should_be(3);
75 'should return -1 if the item is not found in the array': function(){
76 value_of([1,2,3,0,0,0].indexOf('not found')).should_be(-1);
81 'should remove all items in the array that match the specified item': function(){
82 var arr = [1,2,3,0,0,0].erase(0);
83 value_of(arr).should_be([1,2,3]);
88 'should return true if the array contains the specified item': function(){
89 value_of([1,2,3,0,0,0].contains(0)).should_be_true();
92 'should return false if the array does not contain the specified item': function(){
93 value_of([0,1,2].contains('not found')).should_be_false();
98 'should associate an array with a specified array': function(){
99 var obj = [1,2,3,0,0,0].associate(['a', 'b', 'c', 'd']);
100 value_of(obj).should_be({a:1, b:2, c:3, d:0});
105 'should link an array items to a new object according to the specified matchers': function(){
106 var el = document.createElement('div');
107 var assoc2 = [100, 'Hello', {foo: 'bar'}, el, false].link({
108 myNumber: Number.type,
109 myElement: Element.type,
110 myObject: Object.type,
111 myString: String.type,
115 value_of(assoc2).should_be({
118 myObject: {foo: 'bar'},
126 'should extend an array': function(){
130 value_of(a).should_be([1,2,4,2,3,4,5]);
131 value_of(b).should_be([2,3,4,5]);
136 'should combine an array': function(){
137 var arr = [1,2,3,4].combine([3,1,4,5,6,7]);
138 value_of(arr).should_be([1,2,3,4,5,6,7]);
143 'should include only new items': function(){
144 var arr = [1,2,3,4].include(1).include(5);
145 value_of(arr).should_be([1,2,3,4,5]);
150 'should return the last item in the array': function(){
151 value_of([1,2,3,0,0,0].getLast()).should_be(0);
154 'should return null if there are no items': function(){
155 value_of([].getLast()).should_be(null);
160 'should empty the array': function(){
161 var arr = [1,2,3,4].empty();
162 value_of(arr).should_be([]);
167 'should return the item': function(){
169 value_of(arr.item(0)).should_be(1);
170 value_of(array.item(-1)).should_be(4);
173 'should retun null if no item or no items in the array': function(){
175 value_of(arr.item(10)).should_be(null);
178 value_of(arr.item(-1)).should_be(null);
183 describe("Array Color Methods", {
187 'should return null if the length of the array is not 3': function(){
188 value_of([].hexToRgb()).should_be_null();
191 'should return a CSS rgb string': function(){
192 value_of(['0','0','0'].hexToRgb()).should_be('rgb(0,0,0)');
195 'should support shorthand hex': function(){
196 value_of(['c','c','c'].hexToRgb()).should_be('rgb(204,204,204)');
199 'should return an array with 16-based numbers when passed true': function(){
200 value_of(['ff','ff','ff'].hexToRgb(true)).should_be([255,255,255]);
205 'should return null if the array does not have at least 3 times': function(){
206 value_of([0,1].rgbToHex()).should_be_null();
209 'should return a css hexadecimal string': function(){
210 value_of(['255', '0', '0'].rgbToHex()).should_be('#ff0000');
211 value_of([0,0,255].rgbToHex()).should_be('#0000ff');
214 'should return an array with hexadecimal string items': function(){
215 value_of([0,255,0].rgbToHex(true)).should_be(['00', 'ff', '00']);
218 'should return `transparent` if the fourth item is 0 and first param is not true': function(){
219 value_of([0,0,0,0].rgbToHex()).should_be('transparent');