<commit_before>'use strict';

/* globals describe, it, beforeEach, afterEach, sinon, Imager */

describe('Imager.js HTML data-* API', function(){
  // Simili-Array.map for IE8 compat purpose
  var applyEach = Imager.applyEach;

  describe('handling {width} in data-src', function(){
    var fixtures;

    afterEach(function(){
      cleanFixtures(fixtures);
    });

    it('should not use RegExp anymore', function(done){
      fixtures = loadFixtures('data-src-old');
      var imgr = new Imager({ availableWidths: [320, 640] });

      runAfterAnimationFrame(function(){
        applyEach(imgr.divs, function(el){
          expect(el).to.have.property('nodeName', 'IMG');
          expect(el.src).to.contain(el.getAttribute('data-src'));
        });

        done();
      });
    });

    it('should replace {width} by the computed width or a fallback', function(done){
      fixtures = loadFixtures('data-src-new');
      var imgr = new Imager({ availableWidths: [640, 320] });

      runAfterAnimationFrame(function(){
        var src = applyEach(imgr.divs, function(el){ return el.getAttribute('src'); });

        expect(src).to.eql([
          'base/test/fixtures/media/C-320.jpg',
          'base/test/fixtures/media/B-640.jpg',
          'base/test/fixtures/media-320/fillmurray.jpg'
        ]);

        done();
      });
    });

    it('should interpolate {width} with an alternate string value', function(done){
      fixtures = loadFixtures('data-src-interpolate');
      var imgr = new Imager({ availableWidths: {1024: '', 320: 'n_d', 640: 'z_d'} });

      runAfterAnimationFrame(function(){
        var src = applyEach(imgr.divs, function(el){ return el.getAttribute('src'); });

        expect(src).to.eql([
          'base/test/fixtures/interpolated/B-n_d.jpg',
          'base/test/fixtures/interpolated/B-z_d.jpg',
          'base/test/fixtures/1024/1024.jpg'
        ]);

        done();
      });
    });

    it('should interpolate {width} based on an interpolation function', function(done){
      fixtures = loadFixtures('data-src-interpolate');
      var imgr = new Imager({
        availableWidths: [320, 640, 1024],
        widthInterpolator: function(w) {
          if (w == 320) { return 'n_d'; }
          if (w == 640) { return 'z_d'; }
          return '';
        }
      });

      runAfterAnimationFrame(function(){
        var src = imgr.divs.map(function(el){ return el.getAttribute('src'); });

        expect(src).to.eql([
          'base/test/fixtures/interpolated/B-n_d.jpg',
          'base/test/fixtures/interpolated/B-z_d.jpg',
          'base/test/fixtures/1024/1024.jpg'
        ]);

        done();
      });
    });
  });

  describe('Imager.getPixelRatio', function(){
      var sandbox;

      beforeEach(function(){
          sandbox = sinon.sandbox.create();
      });

      afterEach(function(){
          sandbox.restore();
      });<commit_msg>Fixing an `Array.prototype.map` in tests breaking w/ IE8.<commit_after>'use strict';

/* globals describe, it, beforeEach, afterEach, sinon, Imager */

describe('Imager.js HTML data-* API', function(){
  // Simili-Array.map for IE8 compat purpose
  var applyEach = Imager.applyEach;

  describe('handling {width} in data-src', function(){
    var fixtures;

    afterEach(function(){
      cleanFixtures(fixtures);
    });

    it('should not use RegExp anymore', function(done){
      fixtures = loadFixtures('data-src-old');
      var imgr = new Imager({ availableWidths: [320, 640] });

      runAfterAnimationFrame(function(){
        applyEach(imgr.divs, function(el){
          expect(el).to.have.property('nodeName', 'IMG');
          expect(el.src).to.contain(el.getAttribute('data-src'));
        });

        done();
      });
    });

    it('should replace {width} by the computed width or a fallback', function(done){
      fixtures = loadFixtures('data-src-new');
      var imgr = new Imager({ availableWidths: [640, 320] });

      runAfterAnimationFrame(function(){
        var src = applyEach(imgr.divs, function(el){ return el.getAttribute('src'); });

        expect(src).to.eql([
          'base/test/fixtures/media/C-320.jpg',
          'base/test/fixtures/media/B-640.jpg',
          'base/test/fixtures/media-320/fillmurray.jpg'
        ]);

        done();
      });
    });

    it('should interpolate {width} with an alternate string value', function(done){
      fixtures = loadFixtures('data-src-interpolate');
      var imgr = new Imager({ availableWidths: {1024: '', 320: 'n_d', 640: 'z_d'} });

      runAfterAnimationFrame(function(){
        var src = applyEach(imgr.divs, function(el){ return el.getAttribute('src'); });

        expect(src).to.eql([
          'base/test/fixtures/interpolated/B-n_d.jpg',
          'base/test/fixtures/interpolated/B-z_d.jpg',
          'base/test/fixtures/1024/1024.jpg'
        ]);

        done();
      });
    });

    it('should interpolate {width} based on an interpolation function', function(done){
      fixtures = loadFixtures('data-src-interpolate');
      var imgr = new Imager({
        availableWidths: [320, 640, 1024],
        widthInterpolator: function(w) {
          if (w == 320) { return 'n_d'; }
          if (w == 640) { return 'z_d'; }
          return '';
        }
      });

      runAfterAnimationFrame(function(){
        var src = applyEach(imgr.divs, function(el){ return el.getAttribute('src'); });

        expect(src).to.eql([
          'base/test/fixtures/interpolated/B-n_d.jpg',
          'base/test/fixtures/interpolated/B-z_d.jpg',
          'base/test/fixtures/1024/1024.jpg'
        ]);

        done();
      });
    });
  });

  describe('Imager.getPixelRatio', function(){
      var sandbox;

      beforeEach(function(){
          sandbox = sinon.sandbox.create();
      });

      afterEach(function(){
          sandbox.restore();
      });
{'fraction_non_alphanumeric': 0.16208838082238525, 'fraction_numerical': 0.022009895922197577, 'mean_word_length': 2.4976133651551313, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '88679', 'n_tokens_mistral': 1968, 'n_tokens_neox': 1813, 'n_words': 348}