'use strict';

var _chai;

function _load_chai() {
  return _chai = require('chai');
}

var _;

function _load_() {
  return _ = require('.');
}

describe('bitIds', function () {
  describe('getUniq', function () {
    it('should return a uniq array with no duplications', function () {
      var a = new (_ || _load_()).BitId({ name: 'a' });
      var b = new (_ || _load_()).BitId({ name: 'a' });
      var bitIds = new (_ || _load_()).BitIds(a, b);
      (0, (_chai || _load_chai()).expect)(bitIds.getUniq()).to.have.lengthOf(1);
    });
  });
  describe('search functions', function () {
    var bitIds = void 0;
    before(function () {
      var a = new (_ || _load_()).BitId({ name: 'a', scope: 'my-scope', version: '0.0.1' });
      var b = new (_ || _load_()).BitId({ name: 'b' });
      var c = new (_ || _load_()).BitId({ name: 'c' });
      bitIds = new (_ || _load_()).BitIds(a, b, c);
    });
    describe('search', function () {
      it('should find an exact match', function () {
        var result = bitIds.search(new (_ || _load_()).BitId({ name: 'a', scope: 'my-scope', version: '0.0.1' }));
        (0, (_chai || _load_chai()).expect)(result).to.be.an.instanceOf((_ || _load_()).BitId);
        (0, (_chai || _load_chai()).expect)(result.serialize()).to.deep.equal({ name: 'a', scope: 'my-scope', version: '0.0.1' });
      });
      it('should find a match when an ID has only name', function () {
        var result = bitIds.search(new (_ || _load_()).BitId({ name: 'b' }));
        (0, (_chai || _load_chai()).expect)(result).to.be.an.instanceOf((_ || _load_()).BitId);
        (0, (_chai || _load_chai()).expect)(result.serialize()).to.deep.equal({ name: 'b' });
      });
      it('should not return a result with a mismatch version', function () {
        var result = bitIds.search(new (_ || _load_()).BitId({ name: 'a', scope: 'my-scope', version: '0.0.2' }));
        (0, (_chai || _load_chai()).expect)(result).to.be.undefined;
      });
      it('should not return a result with a mismatch scope', function () {
        var result = bitIds.search(new (_ || _load_()).BitId({ name: 'a', scope: 'my-another-scope', version: '0.0.1' }));
        (0, (_chai || _load_chai()).expect)(result).to.be.undefined;
      });
    });
    describe('searchWithoutVersion', function () {
      it('should find an exact match', function () {
        var result = bitIds.searchWithoutVersion(new (_ || _load_()).BitId({ name: 'a', scope: 'my-scope', version: '0.0.1' }));
        (0, (_chai || _load_chai()).expect)(result).to.be.an.instanceOf((_ || _load_()).BitId);
        (0, (_chai || _load_chai()).expect)(result.serialize()).to.deep.equal({ name: 'a', scope: 'my-scope', version: '0.0.1' });
      });
      it('should return a result even with a mismatch version', function () {
        var result = bitIds.searchWithoutVersion(new (_ || _load_()).BitId({ name: 'a', scope: 'my-scope', version: '0.0.2' }));
        (0, (_chai || _load_chai()).expect)(result).to.be.an.instanceOf((_ || _load_()).BitId);
        (0, (_chai || _load_chai()).expect)(result.serialize()).to.deep.equal({ name: 'a', scope: 'my-scope', version: '0.0.1' });
      });
      it('should not return a result with a mismatch scope', function () {
        var result = bitIds.searchWithoutVersion(new (_ || _load_()).BitId({ name: 'a', scope: 'my-another-scope', version: '0.0.1' }));
        (0, (_chai || _load_chai()).expect)(result).to.be.undefined;
      });
    });
    describe('searchWithoutScopeAndVersion', function () {
      it('should find an exact match', function () {
        var result = bitIds.searchWithoutScopeAndVersion(new (_ || _load_()).BitId({ name: 'a', scope: 'my-scope', version: '0.0.1' }));
        (0, (_chai || _load_chai()).expect)(result).to.be.an.instanceOf((_ || _load_()).BitId);
        (0, (_chai || _load_chai()).expect)(result.serialize()).to.deep.equal({ name: 'a', scope: 'my-scope', version: '0.0.1' });
      });
      it('should return a result even with a mismatch version', function () {
        var result = bitIds.searchWithoutScopeAndVersion(new (_ || _load_()).BitId({ name: 'a', scope: 'my-scope', version: '0.0.2' }));
        (0, (_chai || _load_chai()).expect)(result).to.be.an.instanceOf((_ || _load_()).BitId);
        (0, (_chai || _load_chai()).expect)(result.serialize()).to.deep.equal({ name: 'a', scope: 'my-scope', version: '0.0.1' });
      });
      it('should return a result even with a mismatch scope', function () {
        var result = bitIds.searchWithoutScopeAndVersion(new (_ || _load_()).BitId({ name: 'a', scope: 'my-another-scope', version: '0.0.1' }));
        (0, (_chai || _load_chai()).expect)(result).to.be.an.instanceOf((_ || _load_()).BitId);
        (0, (_chai || _load_chai()).expect)(result.serialize()).to.deep.equal({ name: 'a', scope: 'my-scope', version: '0.0.1' });
      });
    });
  });
});