'use strict';

var _chai;

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

var _replaceBufferNonRecursive;

function _load_replaceBufferNonRecursive() {
  return _replaceBufferNonRecursive = _interopRequireDefault(require('../../../src/utils/buffer/replace-buffer-non-recursive'));
}

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

describe('ReplaceBuffer', function () {
  it('should replace an old string with a new string', function () {
    var buffer = Buffer.from('hello world');
    (0, (_chai || _load_chai()).expect)((0, (_replaceBufferNonRecursive || _load_replaceBufferNonRecursive()).default)(buffer, 'world', 'david').toString()).to.equal('hello david');
  });
  it('should not change the buffer if nothing found', function () {
    var buffer = Buffer.from('hello world!');
    (0, (_chai || _load_chai()).expect)((0, (_replaceBufferNonRecursive || _load_replaceBufferNonRecursive()).default)(buffer, 'non', 'exist').toString()).to.equal('hello world!');
  });
  it('should replace multiple occurrences', function () {
    var buffer = Buffer.from('hello world');
    (0, (_chai || _load_chai()).expect)((0, (_replaceBufferNonRecursive || _load_replaceBufferNonRecursive()).default)(buffer, 'l', '!').toString()).to.equal('he!!o wor!d');
  });
  it('should return a Buffer instance', function () {
    var buffer = Buffer.from('hello world');
    (0, (_chai || _load_chai()).expect)((0, (_replaceBufferNonRecursive || _load_replaceBufferNonRecursive()).default)(buffer, 'l', '!')).to.be.instanceof(Buffer);
  });
  it('should throw an error if non-buffer argument was passed', function () {
    try {
      (0, (_replaceBufferNonRecursive || _load_replaceBufferNonRecursive()).default)('hello world', 'l', '!');
    } catch (err) {
      (0, (_chai || _load_chai()).expect)(err.message).to.equal('replaceBuffer expect to get Buffer, got string instead');
    }
  });
});