diff --git a/src/modules/util.js b/src/modules/util.js index 5defef9..041e670 100644 --- a/src/modules/util.js +++ b/src/modules/util.js @@ -192,6 +192,7 @@ }, str_replace: function(from, to, string) { + } }; diff --git a/tests/tests.js b/tests/tests.js index db9bd8e..afb6fd7 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -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(){ expect(2); @@ -237,6 +276,41 @@ deepEqual($_.util.reverse_key_sort(test_o), test_sorted, "Object 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"); + + });