<commit_before>'use strict';

// core modules
var assert = require('assert');
var path = require('path');

// community modules
var range = require('range').range;

// local modules
var fileTooBig = require('../../lib/rules/fileTooBig.js');

var MockContext = function(fname, content) {
  var reports = [];

  return {
    getFilename: function() {
      return path.sep + 'tmp' + path.sep + fname;
    },
    getSourceCode: function() {
      return {
        getText: function() {
          return content;
        }
      };
    },
    options: [{limit: 1536}],
    report: function() {
      reports.push(Array.prototype.slice.apply(arguments));
    },
    getReports: function() {
      return reports;
    }
  };
};

describe('eslint-plugin-filesize', function() {
  it('doesn\'t report anything for an empty file', function() {
    var context = MockContext('empty.js', '');
    fileTooBig(context).Program('mock-node');
    assert.deepEqual(context.getReports(), []);
  });

  it('doesn\'t report anything for a small file', function() {
    var context = MockContext('small.js', 'awehaioidfboaidhfboiashdobhadb');
    fileTooBig(context).Program('mock-node');
    assert.deepEqual(context.getReports(), []);
  });

  it('reports when file is too big', function() {
    var context = MockContext(
      'big.js',
      range(500000).map(function(i) {
        return String.fromCharCode(97 + (i * i * i) % 26);
      }).join('')
    );

    fileTooBig(context).Program('mock-node');

    assert.deepEqual(
      context.getReports(),
      [['mock-node', 'big.min.js.gz is 2021 bytes (limit: 1536)']]
    );
  });
});<commit_msg>Add test for bad config<commit_after>'use strict';

// core modules
var assert = require('assert');
var path = require('path');

// community modules
var range = require('range').range;

// local modules
var fileTooBig = require('../../lib/rules/fileTooBig.js');

var MockContext = function(fname, content) {
  var reports = [];

  return {
    getFilename: function() {
      return path.sep + 'tmp' + path.sep + fname;
    },
    getSourceCode: function() {
      return {
        getText: function() {
          return content;
        }
      };
    },
    options: [{limit: 1536}],
    report: function() {
      reports.push(Array.prototype.slice.apply(arguments));
    },
    getReports: function() {
      return reports;
    }
  };
};

describe('eslint-plugin-filesize', function() {
  it('doesn\'t report anything for an empty file', function() {
    var context = MockContext('empty.js', '');
    fileTooBig(context).Program('mock-node');
    assert.deepEqual(context.getReports(), []);
  });

  it('doesn\'t report anything for a small file', function() {
    var context = MockContext('small.js', 'awehaioidfboaidhfboiashdobhadb');
    fileTooBig(context).Program('mock-node');
    assert.deepEqual(context.getReports(), []);
  });

  it('reports when file is too big', function() {
    var context = MockContext(
      'big.js',
      range(500000).map(function(i) {
        return String.fromCharCode(97 + (i * i * i) % 26);
      }).join('')
    );

    fileTooBig(context).Program('mock-node');

    assert.deepEqual(
      context.getReports(),
      [['mock-node', 'big.min.js.gz is 2021 bytes (limit: 1536)']]
    );
  });

  it('reports bad config', function() {
    var context = MockContext('empty.js', '');
    context.options = ['foobar'];
    fileTooBig(context).Program('mock-node');

    assert.deepEqual(
      context.getReports(),
      [['mock-node', 'invalid config (context.options[0]: "foobar")']]
    );
  });
});
{'fraction_non_alphanumeric': 0.17684797768479776, 'fraction_numerical': 0.012552301255230125, 'mean_word_length': 3.0292134831460675, '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': '7286891', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1120, 'n_words': 239}