<commit_before>/* vim: set et sw=2 ts=2: */

describe('WhiteHorse', function () {
  'use strict';

  var assert = require('assert');
  var path = require('path');
  var WhiteHorse = require('../index.js');

  it('should be initialized without errors', function () {
    var container = new WhiteHorse(require);
    assert(container instanceof WhiteHorse);
  });
  
  it('should throw if require was not passed as first argument', function () {
    try {
      new WhiteHorse();
      assert(false);
    } catch (err) {
      assert(err);
    }
  });
  
  it('should try to guess $root if require did not resolve', function (done) {
    var requireMock = function () {};
    requireMock.resolve = function () {
      throw "";
    };
    requireMock.cache = require.cache;
    new WhiteHorse(requireMock).inject(function ($root) {
      assert(typeof $root === 'string');
      assert($root.length > 0);
      done();
    }, function (err) {
      assert.equal(err, null);
    });
  });

  it('should be initialized if used without new as if with new', function () {
    var whiteHorse = WhiteHorse;
    var container = whiteHorse(require);
    assert(container instanceof WhiteHorse);
  });

  it('getModule() should return undefined if a module does not exist', function () {
    var container = new WhiteHorse(require);
    assert.equal(container.getModule('something'), undefined);
  });

  it('getModule() should return a registered module', function () {
    var container = new WhiteHorse(require);
    container.register('something', function () {});
    assert(container.getModule('something') instanceof WhiteHorse.Module);
  });

  it('inject() should inject $module as undefined', function (done) {
    var container = new WhiteHorse(require);
    container.inject(function ($module) {
      assert.equal($module, undefined);
      return 1337;
    }, function (err, result) {
      assert.equal(err, null);
      assert.equal(result, 1337);
      done();
    });
  });

  it('inject() should inject $root', function (done) {
    var mockRequire = function (){};
    mockRequire.resolve = function () {
      return 'some/path';
    };
    var container = new WhiteHorse(mockRequire);
    container.inject(function ($root) {
      assert.equal($root, 'some');
      return 1337;
    }, function (err, result) {
      assert.equal(err, null);
      assert.equal(result, 1337);
      done();
    });
  });

  it('inject() should inject $root + $done (async)', function (done) {
    var mockRequire = function (){};
    mockRequire.resolve = function () {
      return 'some/path';
    };
    var container = new WhiteHorse(mockRequire);
    container.inject(function ($root, $done) {
      assert.equal($root, 'some');
      $done(null, 1337);
    }, function (err, result) {
      assert.equal(err, null);
      assert.equal(result, 1337);
      done();
    });
  });

  it('should inject double-dollar dependencies', function (done) {
    var f = function (path) {
      assert(path);
      done();
    };
    var container = new WhiteHorse(require);
    container.injectWith(f, [ '$$path' ]);
  });
  
  it('getModule() should return undefined if invoked with anything else but a string', function () {
    assert.equal(new WhiteHorse(require).getModule(7), undefined);
  });

  it('use() should register an npm module', function (done) {
    var container = new WhiteHorse(require).use('nodash');
    container.inject(function (nodash) {
      assert(nodash);
    }, function (err, result) {
      assert.equal(err, null);
      done();
    });
  });
<commit_msg>return of the code coverage<commit_after>/* vim: set et sw=2 ts=2: */

describe('WhiteHorse', function () {
  'use strict';

  var assert = require('assert');
  var path = require('path');
  var WhiteHorse = require('../index.js');

  it('should be initialized without errors', function () {
    var container = new WhiteHorse(require);
    assert(container instanceof WhiteHorse);
  });
  
  it('should throw if require was not passed as first argument', function () {
    try {
      new WhiteHorse();
      assert(false);
    } catch (err) {
      assert(err);
    }
  });
  
  it('should try to guess $root if require did not resolve', function (done) {
    var requireMock = function () {};
    requireMock.resolve = function () {
      throw "";
    };
    requireMock.cache = require.cache;
    new WhiteHorse(requireMock).inject(function ($root) {
      assert(typeof $root === 'string');
      assert($root.length > 0);
      done();
    }, function (err) {
      assert.equal(err, null);
    });
  });

  it('should be initialized if used without new as if with new', function () {
    var whiteHorse = WhiteHorse;
    var container = whiteHorse(require);
    assert(container instanceof WhiteHorse);
  });

  it('getModule() should return undefined if a module does not exist', function () {
    var container = new WhiteHorse(require);
    assert.equal(container.getModule('something'), undefined);
  });

  it('getModule() should return a registered module', function () {
    var container = new WhiteHorse(require);
    container.register('something', function () {});
    assert(container.getModule('something') instanceof WhiteHorse.Module);
  });

  it('inject() should inject $module as undefined', function (done) {
    var container = new WhiteHorse(require);
    container.inject(function ($module) {
      assert.equal($module, undefined);
      return 1337;
    }, function (err, result) {
      assert.equal(err, null);
      assert.equal(result, 1337);
      done();
    });
  });

  it('inject() should inject $root', function (done) {
    var mockRequire = function (){};
    mockRequire.resolve = function () {
      return 'some/path';
    };
    var container = new WhiteHorse(mockRequire);
    container.inject(function ($root) {
      assert.equal($root, 'some');
      return 1337;
    }, function (err, result) {
      assert.equal(err, null);
      assert.equal(result, 1337);
      done();
    });
  });

  it('inject() should inject $root + $done (async)', function (done) {
    var mockRequire = function (){};
    mockRequire.resolve = function () {
      return 'some/path';
    };
    var container = new WhiteHorse(mockRequire);
    container.inject(function ($root, $done) {
      assert.equal($root, 'some');
      $done(null, 1337);
    }, function (err, result) {
      assert.equal(err, null);
      assert.equal(result, 1337);
      done();
    });
  });

  it('should inject double-dollar dependencies', function (done) {
    var f = function (path) {
      assert(path);
      done();
    };
    var container = new WhiteHorse(require);
    container.injectWith(f, [ '$$path' ]);
  });
  
  it('should emit unhandled_error when not given a fallback to inject()', function (done) {
    var container = new WhiteHorse(require);
    container.on('unhandled_error', function (err) {
      assert(err.dependenciesFailed);
      done();
    });
    container.inject(function (dependency) {});
  });
  
  it('should emit unhandled_error when not given a fallback to injectWith()', function (done) {
    var container = new WhiteHorse(require);
    container.on('unhandled_error', function (err) {
      assert(err.dependenciesFailed);
      done();
    });
    container.injectWith(function () {}, [ 'dependency' ]);
  });
  
  it('getModule() should return undefined if invoked with anything else but a string', function () {
    assert.equal(new WhiteHorse(require).getModule(7), undefined);
  });

  it('use() should register an npm module', function (done) {
    var container = new WhiteHorse(require).use('nodash');
    container.inject(function (nodash) {
      assert(nodash);
    }, function (err, result) {
      assert.equal(err, null);
      done();
    });
  });

{'fraction_non_alphanumeric': 0.15148794253463316, 'fraction_numerical': 0.007183170856849667, 'mean_word_length': 3.1517571884984026, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7204949', 'n_tokens_mistral': 2306, 'n_tokens_neox': 2237, 'n_words': 616}