'use strict';

var _chai;

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

var _dataToPersist;

function _load_dataToPersist() {
  return _dataToPersist = _interopRequireDefault(require('./data-to-persist'));
}

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

describe('DataToPersist', function () {
  describe('addFile', function () {
    describe('dir/file collision', function () {
      it('should not throw when the existing file starts with the added file in the same dir', function () {
        var dataToPersist = new (_dataToPersist || _load_dataToPersist()).default();
        dataToPersist.addFile({ path: 'foo/bar.js' });
        var addFile = function addFile() {
          return dataToPersist.addFile({ path: 'foo/bar.json' });
        };
        (0, (_chai || _load_chai()).expect)(addFile).to.not.throw();
      });
      it('should not throw when the added file starts with the existing file in the same dir', function () {
        var dataToPersist = new (_dataToPersist || _load_dataToPersist()).default();
        dataToPersist.addFile({ path: 'foo/bar.json' });
        var addFile = function addFile() {
          return dataToPersist.addFile({ path: 'foo/bar.js' });
        };
        (0, (_chai || _load_chai()).expect)(addFile).to.not.throw();
      });
      it('should throw when the added file is a directory of the existing file', function () {
        var dataToPersist = new (_dataToPersist || _load_dataToPersist()).default();
        dataToPersist.addFile({ path: 'foo/bar.js' });
        var addFile = function addFile() {
          return dataToPersist.addFile({ path: 'foo' });
        };
        (0, (_chai || _load_chai()).expect)(addFile).to.throw();
      });
      it('should throw when the existing file is a directory of the added file', function () {
        var dataToPersist = new (_dataToPersist || _load_dataToPersist()).default();
        dataToPersist.addFile({ path: 'foo' });
        var addFile = function addFile() {
          return dataToPersist.addFile({ path: 'foo/bar.js' });
        };
        (0, (_chai || _load_chai()).expect)(addFile).to.throw();
      });
      it('should throw when one is a directory of other with a few levels', function () {
        var dataToPersist = new (_dataToPersist || _load_dataToPersist()).default();
        dataToPersist.addFile({ path: 'foo1/foo2' });
        var addFile1 = function addFile1() {
          return dataToPersist.addFile({ path: 'foo1/foo2/foo3/foo4' });
        };
        (0, (_chai || _load_chai()).expect)(addFile1).to.throw();

        dataToPersist = new (_dataToPersist || _load_dataToPersist()).default();
        dataToPersist.addFile({ path: 'foo1/foo2/foo3/foo4' });
        var addFile2 = function addFile2() {
          return dataToPersist.addFile({ path: 'foo1/foo2' });
        };
        (0, (_chai || _load_chai()).expect)(addFile2).to.throw();
      });
      it('should not throw when file are different', function () {
        var dataToPersist = new (_dataToPersist || _load_dataToPersist()).default();
        dataToPersist.addFile({ path: 'bar' });
        var addFile1 = function addFile1() {
          return dataToPersist.addFile({ path: 'foo' });
        };
        (0, (_chai || _load_chai()).expect)(addFile1).to.not.throw();

        dataToPersist = new (_dataToPersist || _load_dataToPersist()).default();
        dataToPersist.addFile({ path: 'foo' });
        var addFile2 = function addFile2() {
          return dataToPersist.addFile({ path: 'bar' });
        };
        (0, (_chai || _load_chai()).expect)(addFile2).to.not.throw();
      });
      it('should not throw when file are different with the same dir', function () {
        var dataToPersist = new (_dataToPersist || _load_dataToPersist()).default();
        dataToPersist.addFile({ path: 'bar/foo.js' });
        var addFile1 = function addFile1() {
          return dataToPersist.addFile({ path: 'bar/baz.js' });
        };
        (0, (_chai || _load_chai()).expect)(addFile1).to.not.throw();

        dataToPersist = new (_dataToPersist || _load_dataToPersist()).default();
        dataToPersist.addFile({ path: 'bar/baz.js' });
        var addFile2 = function addFile2() {
          return dataToPersist.addFile({ path: 'bar/foo.js' });
        };
        (0, (_chai || _load_chai()).expect)(addFile2).to.not.throw();
      });
    });
  });
});