Side navigation
Ticket #2616: map-tests.diff
File map-tests.diff, 1.1 KB (added by flesler, April 22, 2008 11:38PM UTC)
The tests for the test suite
Index: unit/core.js
===================================================================
--- unit/core.js (revision 5284)
+++ unit/core.js (working copy)
@@ -1511,7 +1511,7 @@
});
test("map()", function() {
- expect(2);
+ expect(6);
isSet(
$("#ap").map(function(){
@@ -1528,6 +1528,32 @@
q("ap","ap","ap"),
"Single Map"
);
+
+ //for #2616
+ var keys = $.map( {a:1,b:2}, function( v, k ){
+ return k;
+ }, [ ] );
+
+ equals( keys.join(""), "ab", "Map the keys from a hash to an array" );
+
+ var values = $.map( {a:1,b:2}, function( v, k ){
+ return v;
+ }, [ ] );
+
+ equals( values.join(""), "12", "Map the values from a hash to an array" );
+
+ var scripts = document.getElementsByTagName("script");
+ var mapped = $.map( scripts, function( v, k ){
+ return v;
+ }, {length:0} );
+
+ equals( mapped.length, scripts.length, "Map an array(-like) to a hash" );
+
+ var flat = $.map( Array(4), function( v, k ){
+ return k % 2 ? k : [k,k,k];//try mixing array and regular returns
+ });
+
+ equals( flat.join(""), "00012223", "try the new flatten technique(#2616)" );
});
test("contents()", function() {
Download in other formats:
Original Format
File map-tests.diff, 1.1 KB (added by flesler, April 22, 2008 11:38PM UTC)
The tests for the test suite
Index: unit/core.js
===================================================================
--- unit/core.js (revision 5284)
+++ unit/core.js (working copy)
@@ -1511,7 +1511,7 @@
});
test("map()", function() {
- expect(2);
+ expect(6);
isSet(
$("#ap").map(function(){
@@ -1528,6 +1528,32 @@
q("ap","ap","ap"),
"Single Map"
);
+
+ //for #2616
+ var keys = $.map( {a:1,b:2}, function( v, k ){
+ return k;
+ }, [ ] );
+
+ equals( keys.join(""), "ab", "Map the keys from a hash to an array" );
+
+ var values = $.map( {a:1,b:2}, function( v, k ){
+ return v;
+ }, [ ] );
+
+ equals( values.join(""), "12", "Map the values from a hash to an array" );
+
+ var scripts = document.getElementsByTagName("script");
+ var mapped = $.map( scripts, function( v, k ){
+ return v;
+ }, {length:0} );
+
+ equals( mapped.length, scripts.length, "Map an array(-like) to a hash" );
+
+ var flat = $.map( Array(4), function( v, k ){
+ return k % 2 ? k : [k,k,k];//try mixing array and regular returns
+ });
+
+ equals( flat.join(""), "00012223", "try the new flatten technique(#2616)" );
});
test("contents()", function() {