<commit_before>var _ = require('underscore'),
  bag = require('bagofholding'),
  sandbox = require('sandboxed-module'),
  should = require('should'),
  checks, mocks,
  worker;

describe('worker', function () {

  function create(checks, mocks) {
    return sandbox.require('../lib/worker', {
      requires: {
        fs: bag.mock.fs(checks, mocks)
      },
      globals: {
        console: bag.mock.console(checks, mocks),
        process: bag.mock.process(checks, mocks)
      }
    });
  }

  beforeEach(function () {
    checks = {};
    mocks = {};

    mocks.fs_createWriteStream = bag.mock.stream(checks, mocks);
  });

  describe('_templateFunctions', function () {

    function _write(template) {
      worker = new (create(checks, mocks))(333);
      worker.write({
        header: template,
        segment: template,
        footer: template
      }, '12345', 100, 'somedatafile', function () {
        checks.worker_write__count++;
      });

      checks.strings = checks.stream_write_strings.concat(checks.stream_end_string);
      checks.strings.length.should.be.above(0);
    }

    it('should evaluate integer function when it has no argument', function () {
      _write('{integer()}');
      for (var i = 0, ln = checks.strings.length; i < ln; i += 1) {
        (_.isNaN(checks.strings[i])).should.equal(false);
        checks.strings[i].should.not.match(/.+\..+/);
      }
    });

    it('should evaluate ranged integer function when it has min max arguments', function () {
      _write('{integer(100, 200)}');
      for (var i = 0, ln = checks.strings.length; i < ln; i += 1) {
        (_.isNaN(checks.strings[i])).should.equal(false);
        checks.strings[i].should.not.match(/.+\..+/);
        parseInt(checks.strings[i], 10).should.be.within(100, 200);
      }
    });

    it('should evaluate identical integer function when it has identical min max arguments', function () {
      _write('{integer(100, 100)}');
      for (var i = 0, ln = checks.strings.length; i < ln; i += 1) {
        (_.isNaN(checks.strings[i])).should.equal(false);
        checks.strings[i].should.not.match(/.+\..+/);
        parseInt(checks.strings[i], 10).should.equal(100);
      }
    });

    it('should evaluate float function when it has no argument', function () {
      _write('{float()}');
      for (var i = 0, ln = checks.strings.length; i < ln; i += 1) {
        (_.isNaN(checks.strings[i])).should.equal(false);
        checks.strings[i].should.match(/.+\..+/);
      }
    });

    it('should evaluate ranged float function when it has min max arguments', function () {
      _write('{float(100.0, 200.0)}');
      for (var i = 0, ln = checks.strings.length; i < ln; i += 1) {
        (_.isNaN(checks.strings[i])).should.equal(false);
        checks.strings[i].should.match(/.+\..+/);
        parseFloat(checks.strings[i], 10).should.be.within(100.0, 200.0);
      }
    });

    it('should evaluate identical float function when it has identical min max arguments', function () {
      _write('{float(567.89, 567.89)}');
      for (var i = 0, ln = checks.strings.length; i < ln; i += 1) {
        checks.strings[i].should.match(/.+\..+/);
        (checks.strings[i].match(/.+\..+/) !== null).should.equal(true);
        parseFloat(checks.strings[i]).should.equal(567.89);
      }
    });

    it('should evaluate date function with ISO format when it has no argument', function () {
      _write('{date()}');
      for (var i = 0, ln = checks.strings.length; i < ln; i += 1) {
        checks.strings[i].should.match(/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}/);
      }
    });

    it('should evaluate date function with custom format when it has format argument', function () {
      _write('{date(\'yyyy/mm/dd\')}');
      for (var i = 0, ln = checks.strings.length; i < ln; i += 1) {
        checks.strings[i].should.match(/[0-9]{4}\/[0-9]{2}\/[0-9]{2}/);
      }
    });

    it('should evaluate date function with default format and ranged date when it has min max arguments and no format argument', function () {
      _write('{date(1998, 2000)}');
      for (var i = 0, ln = checks.strings.length; i < ln; i += 1) {
        checks.strings[i].should.match(/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}/);
        parseInt(checks.strings[i].match(/^[0-9]{4}/)).should.be.within(1998, 1999);
      }
    });

    it('should evaluate date function with custom format and ranged date when it has min max format arguments', function () {
      _write('{date(\'yyyy/mm/dd\', 1998, 2000)}');
      for (var i = 0, ln = checks.strings.length; i < ln; i += 1) {
        checks.strings[i].should.match(/[0-9]{4}\/[0-9]{2}\/[0-9]{2}/);
        parseInt(checks.strings[i].match(/^[0-9]{4}/)).should.be.within(1998, 1999);
      }
    });

    it('should evaluate select function when it has arguments', function () {
      _write('{select(\'aaa\',\'bbb\',\'ccc\')}');
      for (var i = 0, ln = checks.strings.length; i < ln; i += 1) {
        ['aaa','bbb','ccc'].indexOf(checks.strings[i]).should.be.within(0, 2);
      }
    });<commit_msg>Add missing radix to parseInt.<commit_after>var _ = require('underscore'),
  bag = require('bagofholding'),
  sandbox = require('sandboxed-module'),
  should = require('should'),
  checks, mocks,
  worker;

describe('worker', function () {

  function create(checks, mocks) {
    return sandbox.require('../lib/worker', {
      requires: {
        fs: bag.mock.fs(checks, mocks)
      },
      globals: {
        console: bag.mock.console(checks, mocks),
        process: bag.mock.process(checks, mocks)
      }
    });
  }

  beforeEach(function () {
    checks = {};
    mocks = {};

    mocks.fs_createWriteStream = bag.mock.stream(checks, mocks);
  });

  describe('_templateFunctions', function () {

    function _write(template) {
      worker = new (create(checks, mocks))(333);
      worker.write({
        header: template,
        segment: template,
        footer: template
      }, '12345', 100, 'somedatafile', function () {
        checks.worker_write__count++;
      });

      checks.strings = checks.stream_write_strings.concat(checks.stream_end_string);
      checks.strings.length.should.be.above(0);
    }

    it('should evaluate integer function when it has no argument', function () {
      _write('{integer()}');
      for (var i = 0, ln = checks.strings.length; i < ln; i += 1) {
        (_.isNaN(checks.strings[i])).should.equal(false);
        checks.strings[i].should.not.match(/.+\..+/);
      }
    });

    it('should evaluate ranged integer function when it has min max arguments', function () {
      _write('{integer(100, 200)}');
      for (var i = 0, ln = checks.strings.length; i < ln; i += 1) {
        (_.isNaN(checks.strings[i])).should.equal(false);
        checks.strings[i].should.not.match(/.+\..+/);
        parseInt(checks.strings[i], 10).should.be.within(100, 200);
      }
    });

    it('should evaluate identical integer function when it has identical min max arguments', function () {
      _write('{integer(100, 100)}');
      for (var i = 0, ln = checks.strings.length; i < ln; i += 1) {
        (_.isNaN(checks.strings[i])).should.equal(false);
        checks.strings[i].should.not.match(/.+\..+/);
        parseInt(checks.strings[i], 10).should.equal(100);
      }
    });

    it('should evaluate float function when it has no argument', function () {
      _write('{float()}');
      for (var i = 0, ln = checks.strings.length; i < ln; i += 1) {
        (_.isNaN(checks.strings[i])).should.equal(false);
        checks.strings[i].should.match(/.+\..+/);
      }
    });

    it('should evaluate ranged float function when it has min max arguments', function () {
      _write('{float(100.0, 200.0)}');
      for (var i = 0, ln = checks.strings.length; i < ln; i += 1) {
        (_.isNaN(checks.strings[i])).should.equal(false);
        checks.strings[i].should.match(/.+\..+/);
        parseFloat(checks.strings[i], 10).should.be.within(100.0, 200.0);
      }
    });

    it('should evaluate identical float function when it has identical min max arguments', function () {
      _write('{float(567.89, 567.89)}');
      for (var i = 0, ln = checks.strings.length; i < ln; i += 1) {
        checks.strings[i].should.match(/.+\..+/);
        (checks.strings[i].match(/.+\..+/) !== null).should.equal(true);
        parseFloat(checks.strings[i]).should.equal(567.89);
      }
    });

    it('should evaluate date function with ISO format when it has no argument', function () {
      _write('{date()}');
      for (var i = 0, ln = checks.strings.length; i < ln; i += 1) {
        checks.strings[i].should.match(/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}/);
      }
    });

    it('should evaluate date function with custom format when it has format argument', function () {
      _write('{date(\'yyyy/mm/dd\')}');
      for (var i = 0, ln = checks.strings.length; i < ln; i += 1) {
        checks.strings[i].should.match(/[0-9]{4}\/[0-9]{2}\/[0-9]{2}/);
      }
    });

    it('should evaluate date function with default format and ranged date when it has min max arguments and no format argument', function () {
      _write('{date(1998, 2000)}');
      for (var i = 0, ln = checks.strings.length; i < ln; i += 1) {
        checks.strings[i].should.match(/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}/);
        parseInt(checks.strings[i].match(/^[0-9]{4}/), 10).should.be.within(1998, 1999);
      }
    });

    it('should evaluate date function with custom format and ranged date when it has min max format arguments', function () {
      _write('{date(\'yyyy/mm/dd\', 1998, 2000)}');
      for (var i = 0, ln = checks.strings.length; i < ln; i += 1) {
        checks.strings[i].should.match(/[0-9]{4}\/[0-9]{2}\/[0-9]{2}/);
        parseInt(checks.strings[i].match(/^[0-9]{4}/), 10).should.be.within(1998, 1999);
      }
    });

    it('should evaluate select function when it has arguments', function () {
      _write('{select(\'aaa\',\'bbb\',\'ccc\')}');
      for (var i = 0, ln = checks.strings.length; i < ln; i += 1) {
        ['aaa','bbb','ccc'].indexOf(checks.strings[i]).should.be.within(0, 2);
      }
    });
{'fraction_non_alphanumeric': 0.20070664442045344, 'fraction_numerical': 0.036902541957012466, 'mean_word_length': 2.6628324946081956, 'pattern_counts': {'":': 0, '<': 25, '<?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': '3896740', 'n_tokens_mistral': 3722, 'n_tokens_neox': 3336, 'n_words': 730}