Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7883: json.diff

File json.diff, 5.0 kB (added by savetheclocktower, 1 year ago)

New patch that fixes Array#toJSON and Hash#toJSON (and updates the tests)

  • trunk/test/unit/base.html

    old new  
    8484      methodWithBindArgumentsAndArguments.bind({hi:'withBindArgsAndArgs'},'arg1','arg2')('arg3','arg4'); 
    8585      assertEqual('withBindArgsAndArgs,arg1,arg2,arg3,arg4', globalBindTest); 
    8686    }}, 
     87     
     88    testFunctionCurry: function() { with(this) { 
     89      var split = function(delimiter, string) { return string.split(delimiter); }; 
     90      var splitOnColons = split.curry(":"); 
     91      assertEnumEqual(split(":", "0:1:2:3:4:5"), splitOnColons("0:1:2:3:4:5")); 
     92    }}, 
     93     
     94    testFunctionCompose: function() { with(this) { 
     95      String.prototype.f = String.prototype.split.curry(':').compose(Array.prototype.sort); 
     96      String.prototype.composed_underscore = String.prototype.camelize.compose(String.prototype.underscore); 
     97      assertEnumEqual(['1', '2', '3', '4', '5'], '5:4:3:2:1'.f()); 
     98      assertEqual("foo_bar_baz", "foo_bar_baz".composed_underscore()); 
     99    }}, 
     100     
     101    testFunctionDefer: function() { with(this) { 
     102      window.deferred = undefined; 
     103      var deferredFunction = function() { window.deferred = true; }; 
     104      deferredFunction.defer(1000); 
     105      assertUndefined(window.deferred); 
     106      wait(1000, function() { 
     107        assert(window.deferred); 
     108      }); 
     109    }}, 
    87110 
    88111    testObjectInspect: function() { with(this) { 
    89112      assertEqual('undefined', Object.inspect()); 
     
    99122      assertEqual('\"\"', Object.toJSON('')); 
    100123      assertEqual('[]', Object.toJSON([])); 
    101124      assertEqual('[\"a\"]', Object.toJSON(['a'])); 
    102       assertEqual('[\"a\",1]', Object.toJSON(['a', 1])); 
    103       assertEqual('[\"a\",{\"b\":null}]', Object.toJSON(['a', {'b': null}])); 
    104       assertEqual('{\"a\":\"hello!\"}', Object.toJSON({a: 'hello!'})); 
     125      assertEqual('[\"a\", 1]', Object.toJSON(['a', 1])); 
     126      assertEqual('[\"a\", {\"b\": null}]', Object.toJSON(['a', {'b': null}])); 
     127      assertEqual('{\"a\": \"hello!\"}', Object.toJSON({a: 'hello!'})); 
    105128      assertEqual('{}', Object.toJSON({})); 
    106129      assertEqual('{}', Object.toJSON({a: undefined, b: undefined, c: Prototype.K})); 
    107       assertEqual('{\"b\":[false,true],\"c\":{\"a\":\"hello!\"}}', 
     130      assertEqual('{\"b\": [false, true], \"c\": {\"a\": \"hello!\"}}', 
    108131        Object.toJSON({'b': [undefined, false, true, undefined], c: {a: 'hello!'}})); 
    109       assertEqual('{\"b\":[false,true],\"c\":{\"a\":\"hello!\"}}', 
     132      assertEqual('{\"b\": [false, true], \"c\": {\"a\": \"hello!\"}}', 
    110133        Object.toJSON($H({'b': [undefined, false, true, undefined], c: {a: 'hello!'}}))); 
    111134      assertEqual('true', Object.toJSON(true)); 
    112135      assertEqual('false', Object.toJSON(false)); 
     
    148171        div.setAttribute('id','test-'+i); 
    149172        document.body.appendChild(div); 
    150173        var tobj = new TestObj(); 
    151         var eventTest = {test:true}; 
     174        var eventTest = { test: true }; 
    152175        var call = tobj.assertingEventHandler.bindAsEventListener(tobj, 
    153           this.assertEqual.bind(this,eventTest), 
    154           this.assertEqual.bind(this,arg1), 
    155           this.assertEqual.bind(this,arg2), 
    156           this.assertEqual.bind(this,arg3), arg1, arg2, arg3 ); 
     176          this.assertEqual.bind(this, eventTest), 
     177          this.assertEqual.bind(this, arg1), 
     178          this.assertEqual.bind(this, arg2), 
     179          this.assertEqual.bind(this, arg3), arg1, arg2, arg3 ); 
    157180        call(eventTest); 
    158181      } 
    159182    }, 
  • trunk/src/base.js

    old new  
    4242    for (var property in object) { 
    4343      var value = Object.toJSON(object[property]); 
    4444      if (value !== undefined) 
    45         results.push(property.toJSON() + ':' + value); 
     45        results.push(property.toJSON() + ': ' + value); 
    4646    } 
    47     return '{' + results.join(',') + '}'; 
     47    return '{' + results.join(', ') + '}'; 
    4848  }, 
    4949   
    5050  keys: function(object) { 
  • trunk/src/array.js

    old new  
    109109      var value = Object.toJSON(object); 
    110110      if (value !== undefined) results.push(value); 
    111111    }); 
    112     return '[' + results.join(',') + ']'; 
     112    return '[' + results.join(', ') + ']'; 
    113113  } 
    114114}); 
    115115 
  • trunk/src/hash.js

    old new  
    2828    var results = []; 
    2929    this.prototype._each.call(object, function(pair) { 
    3030      var value = Object.toJSON(pair.value); 
    31       if (value !== undefined) results.push(pair.key.toJSON() + ':' + value); 
     31      if (value !== undefined) results.push(pair.key.toJSON() + ': ' + value); 
    3232    }); 
    33     return '{' + results.join(',') + '}'; 
     33    return '{' + results.join(', ') + '}'; 
    3434  } 
    3535}); 
    3636