<commit_before>(function(){
  
  module('fabric.util');
  
  test('toFixed', function(){
    ok(typeof fabric.util.toFixed == 'function');
    
    function test(what) {
      equals(fabric.util.toFixed(what, 2), 166.67, 'should leave 2 fractional digits');
      equals(fabric.util.toFixed(what, 5), 166.66667, 'should leave 5 fractional digits');
      equals(fabric.util.toFixed(what, 0), 167, 'should leave 0 fractional digits');
      
      var fractionless = (typeof what == 'number') 
        ? parseInt(what) 
        : what.substring(0, what.indexOf('.'));
        
      equals(fabric.util.toFixed(fractionless, 2), 166, 'should leave fractionless number as is');
    }
    
    test.call(this, '166.66666666666666666666'); // string
    test.call(this, 166.66666666666666666666); // number
  });
  
  test('removeFromArray', function() {
    var testArray = [1,2,3,4,5];
    
    ok(typeof fabric.util.removeFromArray == 'function');
    
    fabric.util.removeFromArray(testArray, 2);
    same([1,3,4,5], testArray);
    equals(fabric.util.removeFromArray(testArray, 1), testArray, 'should return reference to original array');
    
    testArray = [1,2,3,1];
    fabric.util.removeFromArray(testArray, 1);
    same([2,3,1], testArray, 'only first occurance of value should be deleted');
    
    testArray = [1,2,3];
    fabric.util.removeFromArray(testArray, 12);
    same([1,2,3], testArray, 'deleting unexistent value should not affect array');
    
    testArray = [];
    fabric.util.removeFromArray(testArray, 1);
    same([], testArray, 'deleting any value from empty array should not affect it');
    
    testArray = ['0'];
    fabric.util.removeFromArray(testArray, 0);
    same(['0'], testArray, 'should use (strict) identity comparison, rather than equality one');
  });
  
  test('degreesToRadians', function(){
    ok(typeof fabric.util.degreesToRadians == 'function');
    equals(fabric.util.degreesToRadians(0), 0);
    equals(fabric.util.degreesToRadians(90), Math.PI / 2);
    equals(fabric.util.degreesToRadians(180), Math.PI);
    
    same(fabric.util.degreesToRadians(), NaN);
  });
  
  test('getRandomInt', function() {
    ok(typeof fabric.util.getRandomInt == 'function');
    
    var randomInts = [];
    for (var i = 100; i--; ) {
      var randomInt = fabric.util.getRandomInt(100, 200); 
      randomInts.push(randomInt);
      ok(randomInt >= 100 && randomInt <= 200);
    }
    
    var areAllTheSame = randomInts.every(function(value){ 
      return value === randomInts[0];
    });
    
    ok(!areAllTheSame);
  });
  
  test('falseFunction', function() {
    ok(typeof fabric.util.falseFunction == 'function');
    equals(fabric.util.falseFunction(), false);
  });
  
  test('String.prototype.trim', function() {
    ok(typeof String.prototype.trim == 'function');
    equals('\t\n   foo bar \n    \xA0  '.trim(), 'foo bar');
  });
  
  test('camelize', function() {
    var camelize = fabric.util.string.camelize;
    
    ok(typeof camelize == 'function');
    
    equals(camelize('foo'), 'foo');
    equals(camelize('foo-bar'), 'fooBar');
    equals(camelize('Foo-bar-Baz'), 'FooBarBaz');
    equals(camelize('FooBarBaz'), 'FooBarBaz');
    equals(camelize('-bar'), 'Bar');
    equals(camelize(''), '');
    equals(camelize('and_something_with_underscores'), 'and_something_with_underscores');
    equals(camelize('underscores_and-dashes'), 'underscores_andDashes');
    equals(camelize('--double'), 'Double');
  });
  
  test('capitalize', function() {
    var capitalize = fabric.util.string.capitalize;
    
    ok(typeof capitalize == 'function');
    
    equals(capitalize('foo'), 'Foo');
    equals(capitalize(''), '');
    equals(capitalize('Foo'), 'Foo');
    equals(capitalize('foo-bar-baz'), 'Foo-bar-baz');
    equals(capitalize('FOO'), 'Foo');
    equals(capitalize('FoobaR'), 'Foobar');
    equals(capitalize('2foo'), '2foo');
  });
  
  test('extend', function() {
    var extend = fabric.util.object.extend;
    
    ok(typeof extend == 'function');
    
    var destination = { x: 1 },
        source = { y: 2 };
        
    extend(destination, source);
    
    equals(destination.x, 1);
    equals(destination.y, 2);
    equals(source.x, undefined);
    equals(source.y, 2);
    
    destination = { x: 1 };
    source = { x: 2 };
    
    extend(destination, source);
    
    equals(destination.x, 2);
    equals(source.x, 2);
  });
  
  test('clone', function() {
    var clone = fabric.util.object.clone;
    
    ok(typeof clone == 'function');
    
    var obj = { x: 1, y: [1, 2, 3] },
        clone = clone(obj);
    
    equals(clone.x, 1);
    notEqual(obj, clone);
    equals(clone.y, obj.y);
  });
  
  test('bind', function() {
    ok(typeof Function.prototype.bind == 'function');
    
    var obj = { };
    function fn() {
      return [this, arguments[0], arguments[1]];
    }
    
    var bound = fn.bind(obj);
    same([obj, undefined, undefined], bound());
    same([obj, 1, undefined], bound(1))
    same([obj, 1, null], bound(1, null));
    
    bound = fn.bind(obj, 1);
    same([obj, 1, undefined], bound());
    same([obj, 1, 2], bound(2));
  });
  
  test('getById', function() {
    ok(typeof fabric.util.getById == 'function');
    
    var el = document.createElement('div');
    el.id = 'foobarbaz';
    document.body.appendChild(el);
    
    equals(el, fabric.util.getById(el));
    equals(el, fabric.util.getById('foobarbaz'));
    equals(null, fabric.util.getById('likely-non-existent-id'));
  });
  
  test('toArray', function() {
    ok(typeof fabric.util.toArray == 'function');
    
    same(['x', 'y'], fabric.util.toArray({ 0: 'x', 1: 'y', length: 2 }));
    same([1, 3], fabric.util.toArray(function(){ return arguments }(1, 3)));
    
    var nodelist = document.getElementsByTagName('div'),
        converted = fabric.util.toArray(nodelist);
        
    ok(converted instanceof Array);
    equals(nodelist.length, converted.length);
    equals(nodelist[0], converted[0]);
    equals(nodelist[1], converted[1]);
  });
})();<commit_msg>Add unit tests for `fabric.util.makeElement`, `fabric.util.addClass`, and `fabric.util.wrapElement`.<commit_after>(function(){
  
  module('fabric.util');
  
  test('toFixed', function(){
    ok(typeof fabric.util.toFixed == 'function');
    
    function test(what) {
      equals(fabric.util.toFixed(what, 2), 166.67, 'should leave 2 fractional digits');
      equals(fabric.util.toFixed(what, 5), 166.66667, 'should leave 5 fractional digits');
      equals(fabric.util.toFixed(what, 0), 167, 'should leave 0 fractional digits');
      
      var fractionless = (typeof what == 'number') 
        ? parseInt(what) 
        : what.substring(0, what.indexOf('.'));
        
      equals(fabric.util.toFixed(fractionless, 2), 166, 'should leave fractionless number as is');
    }
    
    test.call(this, '166.66666666666666666666'); // string
    test.call(this, 166.66666666666666666666); // number
  });
  
  test('removeFromArray', function() {
    var testArray = [1,2,3,4,5];
    
    ok(typeof fabric.util.removeFromArray == 'function');
    
    fabric.util.removeFromArray(testArray, 2);
    same([1,3,4,5], testArray);
    equals(fabric.util.removeFromArray(testArray, 1), testArray, 'should return reference to original array');
    
    testArray = [1,2,3,1];
    fabric.util.removeFromArray(testArray, 1);
    same([2,3,1], testArray, 'only first occurance of value should be deleted');
    
    testArray = [1,2,3];
    fabric.util.removeFromArray(testArray, 12);
    same([1,2,3], testArray, 'deleting unexistent value should not affect array');
    
    testArray = [];
    fabric.util.removeFromArray(testArray, 1);
    same([], testArray, 'deleting any value from empty array should not affect it');
    
    testArray = ['0'];
    fabric.util.removeFromArray(testArray, 0);
    same(['0'], testArray, 'should use (strict) identity comparison, rather than equality one');
  });
  
  test('degreesToRadians', function(){
    ok(typeof fabric.util.degreesToRadians == 'function');
    equals(fabric.util.degreesToRadians(0), 0);
    equals(fabric.util.degreesToRadians(90), Math.PI / 2);
    equals(fabric.util.degreesToRadians(180), Math.PI);
    
    same(fabric.util.degreesToRadians(), NaN);
  });
  
  test('getRandomInt', function() {
    ok(typeof fabric.util.getRandomInt == 'function');
    
    var randomInts = [];
    for (var i = 100; i--; ) {
      var randomInt = fabric.util.getRandomInt(100, 200); 
      randomInts.push(randomInt);
      ok(randomInt >= 100 && randomInt <= 200);
    }
    
    var areAllTheSame = randomInts.every(function(value){ 
      return value === randomInts[0];
    });
    
    ok(!areAllTheSame);
  });
  
  test('falseFunction', function() {
    ok(typeof fabric.util.falseFunction == 'function');
    equals(fabric.util.falseFunction(), false);
  });
  
  test('String.prototype.trim', function() {
    ok(typeof String.prototype.trim == 'function');
    equals('\t\n   foo bar \n    \xA0  '.trim(), 'foo bar');
  });
  
  test('camelize', function() {
    var camelize = fabric.util.string.camelize;
    
    ok(typeof camelize == 'function');
    
    equals(camelize('foo'), 'foo');
    equals(camelize('foo-bar'), 'fooBar');
    equals(camelize('Foo-bar-Baz'), 'FooBarBaz');
    equals(camelize('FooBarBaz'), 'FooBarBaz');
    equals(camelize('-bar'), 'Bar');
    equals(camelize(''), '');
    equals(camelize('and_something_with_underscores'), 'and_something_with_underscores');
    equals(camelize('underscores_and-dashes'), 'underscores_andDashes');
    equals(camelize('--double'), 'Double');
  });
  
  test('capitalize', function() {
    var capitalize = fabric.util.string.capitalize;
    
    ok(typeof capitalize == 'function');
    
    equals(capitalize('foo'), 'Foo');
    equals(capitalize(''), '');
    equals(capitalize('Foo'), 'Foo');
    equals(capitalize('foo-bar-baz'), 'Foo-bar-baz');
    equals(capitalize('FOO'), 'Foo');
    equals(capitalize('FoobaR'), 'Foobar');
    equals(capitalize('2foo'), '2foo');
  });
  
  test('extend', function() {
    var extend = fabric.util.object.extend;
    
    ok(typeof extend == 'function');
    
    var destination = { x: 1 },
        source = { y: 2 };
        
    extend(destination, source);
    
    equals(destination.x, 1);
    equals(destination.y, 2);
    equals(source.x, undefined);
    equals(source.y, 2);
    
    destination = { x: 1 };
    source = { x: 2 };
    
    extend(destination, source);
    
    equals(destination.x, 2);
    equals(source.x, 2);
  });
  
  test('clone', function() {
    var clone = fabric.util.object.clone;
    
    ok(typeof clone == 'function');
    
    var obj = { x: 1, y: [1, 2, 3] },
        clone = clone(obj);
    
    equals(clone.x, 1);
    notEqual(obj, clone);
    equals(clone.y, obj.y);
  });
  
  test('bind', function() {
    ok(typeof Function.prototype.bind == 'function');
    
    var obj = { };
    function fn() {
      return [this, arguments[0], arguments[1]];
    }
    
    var bound = fn.bind(obj);
    same([obj, undefined, undefined], bound());
    same([obj, 1, undefined], bound(1))
    same([obj, 1, null], bound(1, null));
    
    bound = fn.bind(obj, 1);
    same([obj, 1, undefined], bound());
    same([obj, 1, 2], bound(2));
  });
  
  test('getById', function() {
    ok(typeof fabric.util.getById == 'function');
    
    var el = document.createElement('div');
    el.id = 'foobarbaz';
    document.body.appendChild(el);
    
    equals(el, fabric.util.getById(el));
    equals(el, fabric.util.getById('foobarbaz'));
    equals(null, fabric.util.getById('likely-non-existent-id'));
  });
  
  test('toArray', function() {
    ok(typeof fabric.util.toArray == 'function');
    
    same(['x', 'y'], fabric.util.toArray({ 0: 'x', 1: 'y', length: 2 }));
    same([1, 3], fabric.util.toArray(function(){ return arguments }(1, 3)));
    
    var nodelist = document.getElementsByTagName('div'),
        converted = fabric.util.toArray(nodelist);
        
    ok(converted instanceof Array);
    equals(nodelist.length, converted.length);
    equals(nodelist[0], converted[0]);
    equals(nodelist[1], converted[1]);
  });
  
  test('makeElement', function() {
    var makeElement = fabric.util.makeElement;
    ok(typeof makeElement == 'function');
    
    var el = makeElement('div');
    
    equals(el.tagName.toLowerCase(), 'div');
    equals(el.nodeType, 1);
    
    el = makeElement('p', { 'class': 'blah', 'for': 'boo_hoo', 'some_random-attribute': 'woot' });
    
    equals(el.tagName.toLowerCase(), 'p');
    equals(el.nodeType, 1);
    equals(el.className, 'blah');
    equals(el.htmlFor, 'boo_hoo');
    equals(el.getAttribute('some_random-attribute'), 'woot');
  });
  
  test('addClass', function() {
    var addClass = fabric.util.addClass;
    ok(typeof addClass == 'function');
    
    var el = document.createElement('div');
    addClass(el, 'foo');
    equals(el.className, 'foo');
    
    addClass(el, 'bar');
    equals(el.className, 'foo bar');
    
    addClass(el, 'baz qux');
    equals(el.className, 'foo bar baz qux');
    
    addClass(el, 'foo');
    equals(el.className, 'foo bar baz qux');
  });
  
  test('wrapElement', function() {
    var wrapElement = fabric.util.wrapElement;
    ok(typeof wrapElement == 'function');
    
    var el = document.createElement('p');
    var wrapper = wrapElement(el, 'div');
    
    equals(wrapper.tagName.toLowerCase(), 'div');
    equals(wrapper.firstChild, el);
    
    el = document.createElement('p');
    wrapper = wrapElement(el, 'div', { 'class': 'foo' });
    
    equals(wrapper.tagName.toLowerCase(), 'div');
    equals(wrapper.firstChild, el);
    equals(wrapper.className, 'foo');
    
    var childEl = document.createElement('span');
    var parentEl = document.createElement('p');
    
    parentEl.appendChild(childEl);
    
    wrapper = wrapElement(childEl, 'strong');
    
    // wrapper is now in between parent and child
    equals(wrapper.parentNode, parentEl);
    equals(wrapper.firstChild, childEl);
  });
})();
{'fraction_non_alphanumeric': 0.17688427932087802, 'fraction_numerical': 0.023868722028841372, 'mean_word_length': 3.2111875560873466, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1730384', 'n_tokens_mistral': 4926, 'n_tokens_neox': 4583, 'n_words': 919}