Added object_merge tests

This commit is contained in:
Timothy Warren 2011-10-24 12:38:33 -04:00
parent f1bd4d92ee
commit 21ffcb19c9
2 changed files with 75 additions and 0 deletions

View File

@ -192,6 +192,7 @@
}, },
str_replace: function(from, to, string) str_replace: function(from, to, string)
{ {
} }
}; };

View File

@ -214,6 +214,45 @@
}); });
test("Array combine", function(){
expect(3);
var keys_5 = ["a", "u", "i", "e", "o"];
var keys_obj = {
"x": 2,
"a": 4,
"q": 3,
"r": 1,
"p": "q"
};
var vals_5 = [1, 5, 3, 2, 4];
var vals_4 = [3, 6, 2, 7];
var obj_combined = {
2:1,
4:5,
3:3,
1:2,
"q":4
};
var combined = {
"a":1,
"u":5,
"i":3,
"e":2,
"o":4
};
equal($_.util.array_combine(keys_5, vals_4), false, "Can't combine arrays of different sizes");
deepEqual($_.util.array_combine(keys_obj, vals_5), obj_combined, "Combine with keys as object");
deepEqual($_.util.array_combine(keys_5, vals_5), combined, "Properly combines arrays");
});
test("Reverse Key Sort", function(){ test("Reverse Key Sort", function(){
expect(2); expect(2);
@ -238,6 +277,41 @@
deepEqual($_.util.object_values($_.util.reverse_key_sort(test_array)), test_array_sorted, "Array Sort"); deepEqual($_.util.object_values($_.util.reverse_key_sort(test_array)), test_array_sorted, "Array Sort");
}); });
test("Object Merge", function(){
expect(2);
var arr1 = {
"color": "red",
0: 2,
1: 4
},
arr2 = {
0: "a",
1: "b",
"color": "green",
"shape": "trapezoid",
2: 4
},
res1 = {
"color": "green",
0: 2,
1: 4,
2: "a",
3: "b",
"shape": "trapezoid",
4: 4
},
arr3 = [],
arr4 = {
1:'value',
},
res2 = {0:'value'};
deepEqual($_.util.object_merge(arr1, arr2), res1, "Merge objects with numeric and test keys");
deepEqual($_.util.object_merge(arr3, arr4), res2, "Merged object has reordered keys");
});
}()); }());