<commit_before>/* eslint-disable no-unused-vars */
import Injector from '../../src/Injector';
import DependencyResolver from '../../src/DependencyResolver';

describe('Injector', () => {
  beforeEach(function () {
    this.injector = Injector.create('injector1');
  });

  it('should exist', function () {
    expect(Injector).to.exist;
    expect(this.injector).to.exist;
  });

  it('inject', function () {
    this.injector.registerFolders(__dirname, ['../fixtures']);
    this.injector.inject((House) =>
      expect(House).to.equal('House with Pitched Roof and Barn Doors and Double GlazedWindows and Long Garden')
    );
  });

  it('multi injector', function () {
    this.injector1 = this.injector;
    this.injector2 = Injector.create('injector2');
    this.injector1.registerDependencies({
      a: 'a',
      b: 'b'
    });
    this.injector2.registerDependencies({
      a: 'a_updated',
      c: 'c'
    });

    this.injector1.merge(this.injector2).inject((a, b, c, $injector) => {
      expect([a, b, c]).to.deep.equal(['a_updated', 'b', 'c']);
      expect($injector.getRegex(/./)).to.deep.equal({
        a: 'a_updated',
        b: 'b',
        c: 'c'
      });
    });

    this.injector1.inject((a, b, c, $injector) => {
      expect([a, b, c]).to.deep.equal(['a_updated', 'b', 'c']);
      expect($injector.getRegex(/./)).to.deep.equal({
        a: 'a_updated',
        b: 'b',
        c: 'c'
      });
    });

    this.injector1.inject($injector => expect($injector.getRegex(/ssd/)).to.deep.equal({}));

    this.injector1.inject($injector => expect($injector.getAll()).to.deep.equal({
      a: 'a_updated',
      b: 'b',
      c: 'c'
    }));

    this.injector1.inject($injector => expect($injector.getMap(['a', 'b'])).to.deep.equal({
      a: 'a_updated',
      b: 'b'
    }));

    this.injector1.inject($injector => expect($injector.getMap(['a', 'b'])).to.deep.equal({
      a: 'a_updated',
      b: 'b'
    }));

    DependencyResolver.prototype.throwError = () => {};

    this.injector1.inject($injector => expect($injector.get('missing')).to.equal(null));
    const error = this.injector1.resolver.errors[0];
    console.log(error);

    expect(error.error).to.equal('Missing Dependency');
    expect(error.callChain.getPath()).to.equal('$$injector1 -> $injector -> missing');

    this.injector1.addResolvableDependency('a', (b) => {}); // eslint-disable-line no-unused-vars
    this.injector1.addResolvableDependency('b', (a) => {}); // eslint-disable-line no-unused-vars
    this.injector1.inject($injector => $injector.get('a'));

    const cyclicError = this.injector1.resolver.errors[0];
    expect(cyclicError.error).to.equal('Cyclic Dependency');
    expect(cyclicError.callChain.getPath()).to.equal('$$injector1 -> $injector -> a -> b -> a');
  });

  it('registeration methods', function () {
    this.injector.logger.warn = (warningMessage) => {
      this.warningMessage = warningMessage;
    };
    this.injector.registerLibraries({
      _: 'lodash',
      chai: 'chai'
    }).inject((_, chai) => {
      expect(_.groupBy).to.exist;
      expect(chai.Assertion).to.exist;
      expect(this.warningMessage).to.equal('registerLibraries is deprecated, use registerDependencies with explicit require instead.');
    });
  });

  it('dont allow async use of $injector', function (done) {
    this.injector.registerLibraries({
      _: 'lodash',
      chai: 'chai'
    });
    this.injector.addResolvableDependency('foo', $injector => setTimeout(() => {
      expect(() => $injector.get('chai')).to.throw('cannot use $injector.get("chai") asynchronously');
      expect(() => $injector.getRegex(/.+/)).to.throw('cannot use $injector.getRegex(/.+/) asynchronously');
      done();
    }, 0));
    this.injector.inject((_, chai, $injector, foo) => {}); // eslint-disable-line no-unused-vars
  });

  describe('expose and link', () => {
    beforeEach(function () {<commit_msg>Fixing the broken test<commit_after>/* eslint-disable no-unused-vars */
import Injector from '../../src/Injector';
import DependencyResolver from '../../src/DependencyResolver';

describe('Injector', () => {
  beforeEach(function () {
    this.injector = Injector.create('injector1');
  });

  it('should exist', function () {
    expect(Injector).to.exist;
    expect(this.injector).to.exist;
  });

  it('inject', function () {
    this.injector.registerFolders(__dirname, ['../fixtures']);
    this.injector.inject((House) =>
      expect(House).to.equal('House with Pitched Roof and Barn Doors and Double GlazedWindows and Long Garden')
    );
  });

  it('multi injector', function () {
    this.injector1 = this.injector;
    this.injector2 = Injector.create('injector2');
    this.injector1.registerDependencies({
      a: 'a',
      b: 'b'
    });
    this.injector2.registerDependencies({
      a: 'a_updated',
      c: 'c'
    });

    this.injector1.merge(this.injector2).inject((a, b, c, $injector) => {
      expect([a, b, c]).to.deep.equal(['a_updated', 'b', 'c']);
      expect($injector.getRegex(/./)).to.deep.equal({
        a: 'a_updated',
        b: 'b',
        c: 'c'
      });
    });

    this.injector1.inject((a, b, c, $injector) => {
      expect([a, b, c]).to.deep.equal(['a_updated', 'b', 'c']);
      expect($injector.getRegex(/./)).to.deep.equal({
        a: 'a_updated',
        b: 'b',
        c: 'c'
      });
    });

    this.injector1.inject($injector => expect($injector.getRegex(/ssd/)).to.deep.equal({}));

    this.injector1.inject($injector => expect($injector.getAll()).to.deep.equal({
      a: 'a_updated',
      b: 'b',
      c: 'c'
    }));

    this.injector1.inject($injector => expect($injector.getMap(['a', 'b'])).to.deep.equal({
      a: 'a_updated',
      b: 'b'
    }));

    this.injector1.inject($injector => expect($injector.getMap(['a', 'b'])).to.deep.equal({
      a: 'a_updated',
      b: 'b'
    }));

    DependencyResolver.prototype.throwError = () => {};

    this.injector1.inject($injector => expect($injector.get('missing')).to.equal(null));
    const error = this.injector1.resolver.errors[0];
    console.log(error);

    expect(error.error).to.equal('Missing Dependency');
    expect(error.callChain.getPath()).to.equal('$$injector1 -> $injector -> missing');

    this.injector1.addResolvableDependency('a', (b) => {}); // eslint-disable-line no-unused-vars
    this.injector1.addResolvableDependency('b', (a) => {}); // eslint-disable-line no-unused-vars
    this.injector1.inject($injector => $injector.get('a'));

    const cyclicError = this.injector1.resolver.errors[0];
    expect(cyclicError.error).to.equal('Cyclic Dependency');
    expect(cyclicError.callChain.getPath()).to.equal('$$injector1 -> $injector -> a -> b -> a');
  });

  it('registeration methods', function () {
    this.injector.logger.warn = (warningMessage) => {
      this.warningMessage = warningMessage;
    };
    this.injector.registerLibraries({
      _: 'lodash',
      chai: 'chai'
    }).inject((_, chai) => {
      expect(_.groupBy).to.exist;
      expect(chai.Assertion).to.exist;
      expect(this.warningMessage).to.equal('registerLibraries is deprecated, use registerDependencies with explicit require instead.');
    });
  });

  it('dont allow async use of $injector', function (done) {
    this.injector.registerLibraries({
      _: 'lodash',
      chai: 'chai'
    });
    this.injector.addResolvableDependency('foo', $injector => setTimeout(() => {
      expect(() => $injector.get('chai')).to.throw('cannot use $injector.get(\'chai\') asynchronously');
      expect(() => $injector.getRegex(/.+/)).to.throw('cannot use $injector.getRegex(/.+/) asynchronously');
      done();
    }, 0));
    this.injector.inject((_, chai, $injector, foo) => {}); // eslint-disable-line no-unused-vars
  });

  describe('expose and link', () => {
    beforeEach(function () {
{'fraction_non_alphanumeric': 0.20395660497766432, 'fraction_numerical': 0.00612635609444799, 'mean_word_length': 3.190374331550802, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 57, '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': '2612642', 'n_tokens_mistral': 2683, 'n_tokens_neox': 2626, 'n_words': 411}