Bug Tracker

Ticket #2616: map-tests.diff

File map-tests.diff, 1.1 kB (added by flesler, 9 months ago)

The tests for the test suite

  • unit/core.js

     
    15111511}); 
    15121512 
    15131513test("map()", function() { 
    1514     expect(2); 
     1514    expect(6); 
    15151515 
    15161516    isSet( 
    15171517        $("#ap").map(function(){ 
     
    15281528        q("ap","ap","ap"), 
    15291529        "Single Map" 
    15301530    ); 
     1531     
     1532    //for #2616 
     1533    var keys = $.map( {a:1,b:2}, function( v, k ){ 
     1534        return k; 
     1535    }, [ ] ); 
     1536 
     1537    equals( keys.join(""), "ab", "Map the keys from a hash to an array" ); 
     1538     
     1539    var values = $.map( {a:1,b:2}, function( v, k ){ 
     1540        return v; 
     1541    }, [ ] ); 
     1542 
     1543    equals( values.join(""), "12", "Map the values from a hash to an array" ); 
     1544     
     1545    var scripts = document.getElementsByTagName("script"); 
     1546    var mapped = $.map( scripts, function( v, k ){ 
     1547        return v; 
     1548    }, {length:0} ); 
     1549 
     1550    equals( mapped.length, scripts.length, "Map an array(-like) to a hash" ); 
     1551     
     1552    var flat = $.map( Array(4), function( v, k ){ 
     1553        return k % 2 ? k : [k,k,k];//try mixing array and regular returns 
     1554    }); 
     1555     
     1556    equals( flat.join(""), "00012223", "try the new flatten technique(#2616)" ); 
    15311557}); 
    15321558 
    15331559test("contents()", function() {